Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
fix reduce_scatter in place
authordegomme <augustin.degomme@unibas.ch>
Sat, 11 Feb 2017 17:36:45 +0000 (18:36 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Sun, 12 Feb 2017 01:08:28 +0000 (02:08 +0100)
src/smpi/smpi_pmpi.cpp

index 6504976..287b0e8 100644 (file)
@@ -2208,17 +2208,25 @@ int PMPI_Reduce_scatter(void *sendbuf, void *recvbuf, int *recvcounts, MPI_Datat
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = 0;
   extra->recvcounts= xbt_new(int, size);
     dt_size_send = smpi_datatype_size(datatype);
   extra->send_size = 0;
   extra->recvcounts= xbt_new(int, size);
-  for(i=0; i< size; i++)//copy data to avoid bad free
+  int totalcount = 0;
+  for(i=0; i< size; i++){//copy data to avoid bad free
     extra->recvcounts[i] = recvcounts[i]*dt_size_send;
     extra->recvcounts[i] = recvcounts[i]*dt_size_send;
-  TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
-
+    totalcount+= recvcounts[i];
+  }
   void* sendtmpbuf=sendbuf;
   void* sendtmpbuf=sendbuf;
-    if(sendbuf==MPI_IN_PLACE)
-      sendtmpbuf=recvbuf;
+  if(sendbuf==MPI_IN_PLACE){
+    sendtmpbuf= static_cast<void*>(xbt_malloc(totalcount*smpi_datatype_size(datatype)));
+    memcpy(sendtmpbuf,recvbuf, totalcount*smpi_datatype_size(datatype));
+  }
 
 
-    mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype,  op, comm);
-    retval = MPI_SUCCESS;
+  TRACE_smpi_collective_in(rank, -1, __FUNCTION__,extra);
+
+  mpi_coll_reduce_scatter_fun(sendtmpbuf, recvbuf, recvcounts, datatype,  op, comm);
+  retval = MPI_SUCCESS;
   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
   TRACE_smpi_collective_out(rank, -1, __FUNCTION__);
+
+  if(sendbuf==MPI_IN_PLACE)
+    xbt_free(sendtmpbuf);
   }
 
   smpi_bench_begin();
   }
 
   smpi_bench_begin();