Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of git+ssh://scm.gforge.inria.fr//gitroot/simgrid/simgrid
[simgrid.git] / src / smpi / colls / reduce-scatter-gather.c
index 57161ff..38db760 100644 (file)
@@ -21,7 +21,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf,
   int recv_idx, last_idx = 0, newdst;
   int dst, send_cnt, recv_cnt, newroot, newdst_tree_root;
   int newroot_tree_root, new_count;
-  int tag = COLL_TAG_REDUCE;
+  int tag = COLL_TAG_REDUCE,temporary_buffer=0;
   void *send_ptr, *recv_ptr, *tmp_buf;
 
   cnts = NULL;
@@ -40,6 +40,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf,
   /* If I'm not the root, then my recvbuf may not be valid, therefore
   I have to allocate a temporary one */
   if (rank != root && !recvbuf) {
+    temporary_buffer=1;
     recvbuf = (void *)smpi_get_tmp_recvbuffer(count * extent);
   }
   /* find nearest power-of-two less than or equal to comm_size */
@@ -53,7 +54,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf,
     send_ptr = (void *) smpi_get_tmp_sendbuffer(new_count * extent);
     recv_ptr = (void *) smpi_get_tmp_recvbuffer(new_count * extent);
     tmp_buf = (void *) smpi_get_tmp_sendbuffer(new_count * extent);
-    memcpy(send_ptr, sendbuf, extent * count);
+    memcpy(send_ptr, sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, extent * count);
 
     //if ((rank != root))
     smpi_mpi_sendrecv(send_ptr, new_count, datatype, rank, tag,
@@ -232,7 +233,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf,
     tmp_buf = (void *) smpi_get_tmp_sendbuffer(count * extent);
 
     //if ((rank != root))
-    smpi_mpi_sendrecv(sendbuf, count, datatype, rank, tag,
+    smpi_mpi_sendrecv(sendbuf != MPI_IN_PLACE ? sendbuf : recvbuf, count, datatype, rank, tag,
                  recvbuf, count, datatype, rank, tag, comm, &status);
 
     rem = comm_size - pof2;
@@ -401,6 +402,7 @@ int smpi_coll_tuned_reduce_scatter_gather(void *sendbuf, void *recvbuf,
   }
   if (tmp_buf)
     smpi_free_tmp_buffer(tmp_buf);
+  if(temporary_buffer==1) smpi_free_tmp_buffer(recvbuf);
   if (cnts)
     free(cnts);
   if (disps)