Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[trace] fixing some memory leaks in smpi instrumentation code
[simgrid.git] / src / smpi / smpi_coll.c
index 4f33738..1c05340 100644 (file)
@@ -118,6 +118,9 @@ static void tree_bcast(void *buf, int count, MPI_Datatype datatype,
   }
   smpi_mpi_startall(tree->numChildren, requests);
   smpi_mpi_waitall(tree->numChildren, requests, MPI_STATUS_IGNORE);
+  for (i = 0; i < tree->numChildren; i++){
+    xbt_free (requests[i]);
+  }
   xbt_free(requests);
 }
 
@@ -156,6 +159,9 @@ static void tree_antibcast(void *buf, int count, MPI_Datatype datatype,
   }
   smpi_mpi_startall(tree->numChildren, requests);
   smpi_mpi_waitall(tree->numChildren, requests, MPI_STATUS_IGNORE);
+  for (i = 0; i < tree->numChildren; i++){
+    xbt_free (requests[i]);
+  }
   xbt_free(requests);
 }
 
@@ -196,6 +202,8 @@ void nary_tree_barrier(MPI_Comm comm, int arity)
  * Alltoall Bruck
  *
  * Openmpi calls this routine when the message size sent to each rank < 2000 bytes and size < 12
+ * FIXME: uh, check smpi_pmpi again, but this routine is called for > 12, not
+ * less...
  **/
 int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
                                    MPI_Datatype sendtype, void *recvbuf,
@@ -205,20 +213,21 @@ int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
   int system_tag = 777;
   int i, rank, size, err, count;
   MPI_Aint lb;
-  MPI_Aint sendextent = 0;
-  MPI_Aint recvextent = 0;
+  MPI_Aint sendext = 0;
+  MPI_Aint recvext = 0;
   MPI_Request *requests;
 
   // FIXME: check implementation
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
   XBT_DEBUG("<%d> algorithm alltoall_bruck() called.", rank);
-  err = smpi_datatype_extent(sendtype, &lb, &sendextent);
-  err = smpi_datatype_extent(recvtype, &lb, &recvextent);
+  err = smpi_datatype_extent(sendtype, &lb, &sendext);
+  err = smpi_datatype_extent(recvtype, &lb, &recvext);
   /* Local copy from self */
   err =
-      smpi_datatype_copy(&((char *) sendbuf)[rank * sendextent], sendcount,
-                         sendtype, &((char *) recvbuf)[rank * recvextent],
+      smpi_datatype_copy((char *)sendbuf + rank * sendcount * sendext, 
+                         sendcount, sendtype, 
+                         (char *)recvbuf + rank * recvcount * recvext,
                          recvcount, recvtype);
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
@@ -232,7 +241,7 @@ int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
         continue;
       }
       requests[count] =
-          smpi_irecv_init(&((char *) recvbuf)[i * recvextent], recvcount,
+          smpi_irecv_init((char *)recvbuf + i * recvcount * recvext, recvcount,
                           recvtype, i, system_tag, comm);
       count++;
     }
@@ -244,7 +253,7 @@ int smpi_coll_tuned_alltoall_bruck(void *sendbuf, int sendcount,
         continue;
       }
       requests[count] =
-          smpi_isend_init(&((char *) sendbuf)[i * sendextent], sendcount,
+          smpi_isend_init((char *)sendbuf + i * sendcount * sendext, sendcount,
                           sendtype, i, system_tag, comm);
       count++;
     }
@@ -268,24 +277,20 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
 {
   int system_tag = 888;
   int i, rank, size, err, count;
-  MPI_Aint lb;
-  MPI_Aint sendinc = 0;
-  MPI_Aint recvinc = 0;
+  MPI_Aint lb = 0, sendext = 0, recvext = 0;
   MPI_Request *requests;
 
   /* Initialize. */
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
   XBT_DEBUG("<%d> algorithm alltoall_basic_linear() called.", rank);
-  err = smpi_datatype_extent(sendtype, &lb, &sendinc);
-  err = smpi_datatype_extent(recvtype, &lb, &recvinc);
-  sendinc *= sendcount;
-  recvinc *= recvcount;
+  err = smpi_datatype_extent(sendtype, &lb, &sendext);
+  err = smpi_datatype_extent(recvtype, &lb, &recvext);
   /* simple optimization */
-  err =
-      smpi_datatype_copy(&((char *) sendbuf)[rank * sendinc], sendcount,
-                         sendtype, &((char *) recvbuf)[rank * recvinc],
-                         recvcount, recvtype);
+  err = smpi_datatype_copy((char *)sendbuf + rank * sendcount * sendext, 
+                           sendcount, sendtype, 
+                           (char *)recvbuf + rank * recvcount * recvext, 
+                           recvcount, recvtype);
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
     requests = xbt_new(MPI_Request, 2 * (size - 1));
@@ -293,7 +298,7 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
     count = 0;
     for (i = (rank + 1) % size; i != rank; i = (i + 1) % size) {
       requests[count] =
-          smpi_irecv_init(&((char *) recvbuf)[i * recvinc], recvcount,
+          smpi_irecv_init((char *)recvbuf + i * recvcount * recvext, recvcount, 
                           recvtype, i, system_tag, comm);
       count++;
     }
@@ -302,10 +307,9 @@ int smpi_coll_tuned_alltoall_basic_linear(void *sendbuf, int sendcount,
      *     when messages actually arrive in the order in which they were posted.
      * TODO: check the previous assertion
      */
-    for (i = (rank + size - 1) % size; i != rank;
-         i = (i + size - 1) % size) {
+    for (i = (rank + size - 1) % size; i != rank; i = (i + size - 1) % size) {
       requests[count] =
-          smpi_isend_init(&((char *) sendbuf)[i * sendinc], sendcount,
+          smpi_isend_init((char *)sendbuf + i * sendcount * sendext, sendcount,
                           sendtype, i, system_tag, comm);
       count++;
     }
@@ -364,22 +368,20 @@ int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
 {
   int system_tag = 889;
   int i, rank, size, err, count;
-  MPI_Aint lb;
-  MPI_Aint sendextent = 0;
-  MPI_Aint recvextent = 0;
+  MPI_Aint lb = 0, sendext = 0, recvext = 0;
   MPI_Request *requests;
 
   /* Initialize. */
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
   XBT_DEBUG("<%d> algorithm basic_alltoallv() called.", rank);
-  err = smpi_datatype_extent(sendtype, &lb, &sendextent);
-  err = smpi_datatype_extent(recvtype, &lb, &recvextent);
+  err = smpi_datatype_extent(sendtype, &lb, &sendext);
+  err = smpi_datatype_extent(recvtype, &lb, &recvext);
   /* Local copy from self */
   err =
-      smpi_datatype_copy(&((char *) sendbuf)[senddisps[rank] * sendextent],
+      smpi_datatype_copy((char *)sendbuf + senddisps[rank] * sendext, 
                          sendcounts[rank], sendtype,
-                         &((char *) recvbuf)[recvdisps[rank] * recvextent],
+                         (char *)recvbuf + recvdisps[rank] * recvext, 
                          recvcounts[rank], recvtype);
   if (err == MPI_SUCCESS && size > 1) {
     /* Initiate all send/recv to/from others. */
@@ -394,7 +396,7 @@ int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
         continue;
       }
       requests[count] =
-          smpi_irecv_init(&((char *) recvbuf)[recvdisps[i] * recvextent],
+          smpi_irecv_init((char *)recvbuf + recvdisps[i] * recvext, 
                           recvcounts[i], recvtype, i, system_tag, comm);
       count++;
     }
@@ -407,7 +409,7 @@ int smpi_coll_basic_alltoallv(void *sendbuf, int *sendcounts,
         continue;
       }
       requests[count] =
-          smpi_isend_init(&((char *) sendbuf)[senddisps[i] * sendextent],
+          smpi_isend_init((char *)sendbuf + senddisps[i] * sendext, 
                           sendcounts[i], sendtype, i, system_tag, comm);
       count++;
     }