Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
optimize MPI_Sendrecv if a process has to exchange with himself only
[simgrid.git] / src / smpi / smpi_base.c
index 067cd82..875ce4e 100644 (file)
@@ -12,7 +12,7 @@
 #include "simix/smx_private.h"
 #include "surf/surf.h"
 #include "simgrid/sg_config.h"
-
+#include "colls/colls.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_base, smpi, "Logging specific to SMPI (base)");
 
@@ -527,7 +527,12 @@ void smpi_mpi_sendrecv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
 {
   MPI_Request requests[2];
   MPI_Status stats[2];
-
+  int myid=smpi_process_index();
+  if ((dst == myid) && (src == myid)) {
+      smpi_datatype_copy(sendbuf, sendcount, sendtype,
+                                     recvbuf, recvcount, recvtype);
+      return;
+  }
   requests[0] =
     smpi_isend_init(sendbuf, sendcount, sendtype, dst, sendtag, comm);
   requests[1] =
@@ -948,6 +953,8 @@ void smpi_mpi_reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
     int i, size, count;
     int *displs;
     int rank = smpi_process_index();
+    void *tmpbuf;
+
     /* arbitrarily choose root as rank 0 */
     size = smpi_comm_size(comm);
     count = 0;
@@ -956,10 +963,12 @@ void smpi_mpi_reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts,
       displs[i] = count;
       count += recvcounts[i];
     }
-    mpi_coll_reduce_fun(sendbuf, recvbuf, count, datatype, op, 0, comm);
-    smpi_mpi_scatterv(recvbuf, recvcounts, displs, datatype, recvbuf,
+    tmpbuf=(void*)xbt_malloc(count*smpi_datatype_get_extent(datatype));
+    mpi_coll_reduce_fun(sendbuf, tmpbuf, count, datatype, op, 0, comm);
+    smpi_mpi_scatterv(tmpbuf, recvcounts, displs, datatype, recvbuf,
                       recvcounts[rank], datatype, 0, comm);
     xbt_free(displs);
+    xbt_free(tmpbuf);
 }
 
 void smpi_mpi_gatherv(void *sendbuf, int sendcount, MPI_Datatype sendtype,
@@ -1169,6 +1178,13 @@ void smpi_mpi_reduce(void *sendbuf, void *recvbuf, int count,
 
   rank = smpi_comm_rank(comm);
   size = smpi_comm_size(comm);
+  //non commutative case, use a working algo from openmpi
+  if(!smpi_op_is_commute(op)){
+    smpi_coll_tuned_reduce_ompi_basic_linear(sendbuf, recvbuf, count,
+                     datatype, op, root, comm);
+    return;
+  }
+  
   if(rank != root) {
     // Send buffer to root
     smpi_mpi_send(sendbuf, count, datatype, root, system_tag, comm);