Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
try to fix some compilation erros
[simgrid.git] / src / smpi / colls / reduce-binomial.c
index f2555f8..607bb6f 100644 (file)
@@ -1,3 +1,9 @@
+/* Copyright (c) 2013-2014. The SimGrid Team.
+ * All rights reserved.                                                     */
+
+/* This program is free software; you can redistribute it and/or modify it
+ * under the terms of the license (GNU LGPL) which comes with this package. */
+
 #include "colls_private.h"
 
 //#include <star-reduction.c>
@@ -10,7 +16,7 @@ int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count,
   int comm_size, rank;
   int mask, relrank, source;
   int dst;
-  int tag = 4321;
+  int tag = COLL_TAG_REDUCE;
   MPI_Aint extent;
   void *tmp_buf;
   MPI_Aint true_lb, true_extent;
@@ -21,10 +27,8 @@ int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count,
 
   extent = smpi_datatype_get_extent(datatype);
 
-  tmp_buf = (void *) xbt_malloc(count * extent);
+  tmp_buf = (void *) smpi_get_tmp_sendbuffer(count * extent);
   int is_commutative = smpi_op_is_commute(op);
-  smpi_mpi_sendrecv(sendbuf, count, datatype, rank, tag,
-               recvbuf, count, datatype, rank, tag, comm, &status);
   mask = 1;
   
   int lroot;
@@ -42,7 +46,7 @@ int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count,
   /* 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 = (void *) malloc(count*(max(extent,true_extent)));
+      recvbuf = (void *) smpi_get_tmp_recvbuffer(count*(max(extent,true_extent)));
       recvbuf = (void *)((char*)recvbuf - true_lb);
   }
    if ((rank != root) || (sendbuf != MPI_IN_PLACE)) {
@@ -72,15 +76,18 @@ int smpi_coll_tuned_reduce_binomial(void *sendbuf, void *recvbuf, int count,
     mask <<= 1;
   }
 
-if (!is_commutative && (root != 0)){
-  if (rank == 0){
-    smpi_mpi_send(recvbuf, count, datatype, root,tag, comm);
-  }else if (rank == root){
-    smpi_mpi_recv(recvbuf, count, datatype, 0, tag, comm, &status);
+  if (!is_commutative && (root != 0)){
+    if (rank == 0){
+      smpi_mpi_send(recvbuf, count, datatype, root,tag, comm);
+    }else if (rank == root){
+      smpi_mpi_recv(recvbuf, count, datatype, 0, tag, comm, &status);
+    }
   }
-}
 
-  free(tmp_buf);
+  if (rank != root) {
+         smpi_free_tmp_buffer(recvbuf);
+  }
+  smpi_free_tmp_buffer(tmp_buf);
 
   return 0;
 }