Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
oops
[simgrid.git] / src / smpi / colls / reduce_scatter-ompi.c
index f8c716f..e303d20 100644 (file)
@@ -23,6 +23,7 @@
 
 #include "colls_private.h"
 #include "coll_tuned_topo.h"
+#include "xbt/replay.h"
 
 /*
  * Recursive-halving function is (*mostly*) copied from the BASIC coll module.
@@ -61,6 +62,8 @@ smpi_coll_tuned_reduce_scatter_ompi_basic_recursivehalving(void *sbuf,
     size = smpi_comm_size(comm);
    
     XBT_DEBUG("coll:tuned:reduce_scatter_ompi_basic_recursivehalving, rank %d", rank);
+    if(!smpi_op_is_commute(op))
+      THROWF(arg_error,0, " reduce_scatter ompi_basic_recursivehalving can only be used for commutative operations! ");
 
     /* Find displacements and the like */
     disps = (int*) xbt_malloc(sizeof(int) * size);
@@ -89,7 +92,8 @@ smpi_coll_tuned_reduce_scatter_ompi_basic_recursivehalving(void *sbuf,
     }
 
     /* Allocate temporary receive buffer. */
-    recv_buf_free = (char*) xbt_malloc(buf_size);
+    recv_buf_free = (char*) smpi_get_tmp_recvbuffer(buf_size);
+
     recv_buf = recv_buf_free - lb;
     if (NULL == recv_buf_free) {
         err = MPI_ERR_OTHER;
@@ -97,7 +101,8 @@ smpi_coll_tuned_reduce_scatter_ompi_basic_recursivehalving(void *sbuf,
     }
    
     /* allocate temporary buffer for results */
-    result_buf_free = (char*) xbt_malloc(buf_size);
+    result_buf_free = (char*) smpi_get_tmp_sendbuffer(buf_size);
+
     result_buf = result_buf_free - lb;
    
     /* copy local buffer into the temporary results */
@@ -287,8 +292,8 @@ smpi_coll_tuned_reduce_scatter_ompi_basic_recursivehalving(void *sbuf,
 
  cleanup:
     if (NULL != disps) xbt_free(disps);
-    if (NULL != recv_buf_free) xbt_free(recv_buf_free);
-    if (NULL != result_buf_free) xbt_free(result_buf_free);
+    if (NULL != recv_buf_free) smpi_free_tmp_buffer(recv_buf_free);
+    if (NULL != result_buf_free) smpi_free_tmp_buffer(result_buf_free);
 
     return err;
 }
@@ -409,15 +414,15 @@ smpi_coll_tuned_reduce_scatter_ompi_ring(void *sbuf, void *rbuf, int *rcounts,
 
     max_real_segsize = true_extent + (ptrdiff_t)(max_block_count - 1) * extent;
 
-    accumbuf_free = (char*)xbt_malloc(true_extent + (ptrdiff_t)(total_count - 1) * extent);
+    accumbuf_free = (char*)smpi_get_tmp_recvbuffer(true_extent + (ptrdiff_t)(total_count - 1) * extent);
     if (NULL == accumbuf_free) { ret = -1; line = __LINE__; goto error_hndl; }
     accumbuf = accumbuf_free - lb;
 
-    inbuf_free[0] = (char*)xbt_malloc(max_real_segsize);
+    inbuf_free[0] = (char*)smpi_get_tmp_sendbuffer(max_real_segsize);
     if (NULL == inbuf_free[0]) { ret = -1; line = __LINE__; goto error_hndl; }
     inbuf[0] = inbuf_free[0] - lb;
     if (size > 2) {
-        inbuf_free[1] = (char*)xbt_malloc(max_real_segsize);
+        inbuf_free[1] = (char*)smpi_get_tmp_sendbuffer(max_real_segsize);
         if (NULL == inbuf_free[1]) { ret = -1; line = __LINE__; goto error_hndl; }
         inbuf[1] = inbuf_free[1] - lb;
     }
@@ -498,9 +503,9 @@ smpi_coll_tuned_reduce_scatter_ompi_ring(void *sbuf, void *rbuf, int *rcounts,
     if (ret < 0) { line = __LINE__; goto error_hndl; }
 
     if (NULL != displs) xbt_free(displs);
-    if (NULL != accumbuf_free) xbt_free(accumbuf_free);
-    if (NULL != inbuf_free[0]) xbt_free(inbuf_free[0]);
-    if (NULL != inbuf_free[1]) xbt_free(inbuf_free[1]);
+    if (NULL != accumbuf_free) smpi_free_tmp_buffer(accumbuf_free);
+    if (NULL != inbuf_free[0]) smpi_free_tmp_buffer(inbuf_free[0]);
+    if (NULL != inbuf_free[1]) smpi_free_tmp_buffer(inbuf_free[1]);
 
     return MPI_SUCCESS;
 
@@ -508,9 +513,9 @@ smpi_coll_tuned_reduce_scatter_ompi_ring(void *sbuf, void *rbuf, int *rcounts,
     XBT_DEBUG( "%s:%4d\tRank %d Error occurred %d\n",
                  __FILE__, line, rank, ret);
     if (NULL != displs) xbt_free(displs);
-    if (NULL != accumbuf_free) xbt_free(accumbuf_free);
-    if (NULL != inbuf_free[0]) xbt_free(inbuf_free[0]);
-    if (NULL != inbuf_free[1]) xbt_free(inbuf_free[1]);
+    if (NULL != accumbuf_free) smpi_free_tmp_buffer(accumbuf_free);
+    if (NULL != inbuf_free[0]) smpi_free_tmp_buffer(inbuf_free[0]);
+    if (NULL != inbuf_free[1]) smpi_free_tmp_buffer(inbuf_free[1]);
     return ret;
 }