Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
change some behaviors with MPI_IN_PLACE
authorAugustin Degomme <degomme@idpann.imag.fr>
Fri, 12 Jul 2013 16:27:59 +0000 (18:27 +0200)
committerAugustin Degomme <degomme@idpann.imag.fr>
Fri, 12 Jul 2013 17:13:32 +0000 (19:13 +0200)
src/smpi/colls/smpi_mpich_selector.c
src/smpi/colls/smpi_openmpi_selector.c
src/smpi/smpi_base.c
src/smpi/smpi_pmpi.c

index 2c6ab2d..a2a44ae 100644 (file)
@@ -426,6 +426,8 @@ int smpi_coll_tuned_reduce_scatter_mpich( void *sbuf, void *rbuf,
     int comm_size, i;
     size_t total_message_size;
 
+    if(sbuf==rbuf)sbuf=MPI_IN_PLACE; //restore MPI_IN_PLACE as these algos handle it
+
     XBT_DEBUG("smpi_coll_tuned_reduce_scatter_mpich");
     
     comm_size = smpi_comm_size(comm);
@@ -689,6 +691,11 @@ int smpi_coll_tuned_scatter_mpich(void *sbuf, int scount,
                                             int root, MPI_Comm  comm
                                             )
 {
+  if(smpi_comm_rank(comm)!=root){
+      sbuf=xbt_malloc(rcount*smpi_datatype_get_extent(rdtype));
+      scount=rcount;
+      sdtype=rdtype;
+  }
         return smpi_coll_tuned_scatter_ompi_binomial (sbuf, scount, sdtype, 
                                                        rbuf, rcount, rdtype, 
                                                        root, comm);
index e092bdd..2319633 100644 (file)
@@ -596,6 +596,11 @@ int smpi_coll_tuned_scatter_ompi(void *sbuf, int scount,
 
     if ((communicator_size > small_comm_size) &&
         (block_size < small_block_size)) {
+        if(rank!=root){
+            sbuf=xbt_malloc(rcount*smpi_datatype_get_extent(rdtype));
+            scount=rcount;
+            sdtype=rdtype;
+        }
         return smpi_coll_tuned_scatter_ompi_binomial (sbuf, scount, sdtype, 
                                                        rbuf, rcount, rdtype, 
                                                        root, comm);
index 04f665f..88e9307 100644 (file)
@@ -421,7 +421,6 @@ void smpi_mpi_startall(int count, MPI_Request * requests)
 
 void smpi_mpi_request_free(MPI_Request * request)
 {
-
   if((*request) != MPI_REQUEST_NULL){
     (*request)->refcount--;
     if((*request)->refcount<0) xbt_die("wrong refcount");
@@ -1110,8 +1109,10 @@ void smpi_mpi_scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     // FIXME: check for errors
     smpi_datatype_extent(sendtype, &lb, &sendext);
     // Local copy from root
-    smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
-                       sendcount, sendtype, recvbuf, recvcount, recvtype);
+    if(recvbuf!=MPI_IN_PLACE){
+        smpi_datatype_copy((char *)sendbuf + root * sendcount * sendext,
+                           sendcount, sendtype, recvbuf, recvcount, recvtype);
+    }
     // Send buffers to receivers
     requests = xbt_new(MPI_Request, size - 1);
     index = 0;
@@ -1149,8 +1150,10 @@ void smpi_mpi_scatterv(void *sendbuf, int *sendcounts, int *displs,
     // FIXME: check for errors
     smpi_datatype_extent(sendtype, &lb, &sendext);
     // Local copy from root
-    smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
+    if(recvbuf!=MPI_IN_PLACE){
+      smpi_datatype_copy((char *)sendbuf + displs[root] * sendext, sendcounts[root],
                        sendtype, recvbuf, recvcount, recvtype);
+    }
     // Send buffers to receivers
     requests = xbt_new(MPI_Request, size - 1);
     index = 0;
@@ -1179,9 +1182,11 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
   MPI_Request *requests;
   void **tmpbufs;
 
+
   char* sendtmpbuf = (char*) sendbuf;
   if( sendbuf == MPI_IN_PLACE ) {
-      sendtmpbuf = (char *)recvbuf;
+    sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+    smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
   }
 
   rank = smpi_comm_rank(comm);
@@ -1234,6 +1239,10 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
     }
     xbt_free(tmpbufs);
     xbt_free(requests);
+
+    if( sendbuf == MPI_IN_PLACE ) {
+      xbt_free(sendtmpbuf);
+    }
   }
 }
 
index 8feabee..7859738 100644 (file)
@@ -1865,9 +1865,9 @@ int PMPI_Scatter(void *sendbuf, int sendcount, MPI_Datatype sendtype,
              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
     retval = MPI_ERR_TYPE;
   } else {
-
-    if(recvbuf==MPI_IN_PLACE){
-       recvcount=0;
+    if (recvbuf == MPI_IN_PLACE) {
+        recvtype=sendtype;
+        recvcount=sendcount;
     }
     mpi_coll_scatter_fun(sendbuf, sendcount, sendtype, recvbuf, recvcount,
                      recvtype, root, comm);
@@ -1902,11 +1902,10 @@ int PMPI_Scatterv(void *sendbuf, int *sendcounts, int *displs,
              || ((recvbuf !=MPI_IN_PLACE) && (recvtype == MPI_DATATYPE_NULL))) {
     retval = MPI_ERR_TYPE;
   } else {
-
-    if(recvbuf==MPI_IN_PLACE){
-       recvcount=0;
+    if (recvbuf == MPI_IN_PLACE) {
+        recvtype=sendtype;
+        recvcount=sendcounts[smpi_comm_rank(comm)];
     }
-
     smpi_mpi_scatterv(sendbuf, sendcounts, displs, sendtype, recvbuf,
                       recvcount, recvtype, root, comm);
     retval = MPI_SUCCESS;
@@ -1937,17 +1936,7 @@ int PMPI_Reduce(void *sendbuf, void *recvbuf, int count,
     retval = MPI_ERR_ARG;
   } else {
 
-    char* sendtmpbuf = (char*) sendbuf;
-    if( sendbuf == MPI_IN_PLACE ) {
-      sendtmpbuf = (char *)xbt_malloc(count*smpi_datatype_get_extent(datatype));
-      smpi_datatype_copy(recvbuf, count, datatype,sendtmpbuf, count, datatype);
-    }
-
-    mpi_coll_reduce_fun(sendtmpbuf, recvbuf, count, datatype, op, root, comm);
-
-    if( sendbuf == MPI_IN_PLACE ) {
-      xbt_free(sendtmpbuf);
-    }
+    mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, root, comm);
 
     retval = MPI_SUCCESS;
   }