Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Throw std::invalid_argument.
[simgrid.git] / src / smpi / colls / reduce / reduce-rab.cpp
index 22f34a0..351979c 100644 (file)
@@ -9,9 +9,9 @@
  * but this header must not be removed.
  */
 
-#include "../colls_private.h"
-#include <stdio.h>
-#include <stdlib.h>
+#include "../colls_private.hpp"
+#include <cstdio>
+#include <cstdlib>
 
 #define REDUCE_NEW_ALWAYS 1
 
@@ -409,13 +409,31 @@ Benchmark results on CRAY T3E
 #endif
 #endif
 
-typedef enum {MPIM_SHORT, MPIM_INT, MPIM_LONG, MPIM_UNSIGNED_SHORT,
-              MPIM_UNSIGNED, MPIM_UNSIGNED_LONG, MPIM_UNSIGNED_LONG_LONG, MPIM_FLOAT,
-              MPIM_DOUBLE, MPIM_BYTE} MPIM_Datatype;
-
-typedef enum {MPIM_MAX, MPIM_MIN, MPIM_SUM, MPIM_PROD,
-              MPIM_LAND, MPIM_BAND, MPIM_LOR, MPIM_BOR,
-              MPIM_LXOR, MPIM_BXOR} MPIM_Op;
+enum MPIM_Datatype {
+  MPIM_SHORT,
+  MPIM_INT,
+  MPIM_LONG,
+  MPIM_UNSIGNED_SHORT,
+  MPIM_UNSIGNED,
+  MPIM_UNSIGNED_LONG,
+  MPIM_UNSIGNED_LONG_LONG,
+  MPIM_FLOAT,
+  MPIM_DOUBLE,
+  MPIM_BYTE
+};
+
+enum MPIM_Op {
+  MPIM_MAX,
+  MPIM_MIN,
+  MPIM_SUM,
+  MPIM_PROD,
+  MPIM_LAND,
+  MPIM_BAND,
+  MPIM_LOR,
+  MPIM_BOR,
+  MPIM_LXOR,
+  MPIM_BXOR
+};
 #define MPI_I_DO_OP_C_INTEGER(MPI_I_do_op_TYPE,TYPE)                   \
 static void MPI_I_do_op_TYPE(TYPE* b1,TYPE* b2,TYPE* rslt, int cnt,MPIM_Op op)\
 { int i;                                                               \
@@ -497,8 +515,9 @@ static void MPI_I_do_op(void* b1, void* b2, void* rslt, int cnt,
 }
 
 REDUCE_LIMITS
-
-static int MPI_I_anyReduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype mpi_datatype, MPI_Op mpi_op, int root, MPI_Comm comm, int is_all)
+namespace simgrid{
+namespace smpi{
+static int MPI_I_anyReduce(const void* Sendbuf, void* Recvbuf, int count, MPI_Datatype mpi_datatype, MPI_Op mpi_op, int root, MPI_Comm comm, int is_all)
 {
   char *scr1buf, *scr2buf, *scr3buf, *xxx, *sendbuf, *recvbuf;
   int myrank, size, x_base, x_size, computed, idx;
@@ -521,7 +540,7 @@ static int MPI_I_anyReduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype
   else if(mpi_datatype==MPI_DOUBLE        ) datatype=MPIM_DOUBLE;
   else if(mpi_datatype==MPI_BYTE          ) datatype=MPIM_BYTE;
   else
-   THROWF(arg_error,0, "reduce rab algorithm can't be used with this datatype ! ");
+    throw std::invalid_argument("reduce rab algorithm can't be used with this datatype!");
 
   if     (mpi_op==MPI_MAX     ) op=MPIM_MAX;
   else if(mpi_op==MPI_MIN     ) op=MPIM_MIN;
@@ -594,14 +613,14 @@ static int MPI_I_anyReduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype
     MPI_Type_extent(mpi_datatype, &typelng);
     scrlng  = typelng * count;
 #ifdef NO_CACHE_OPTIMIZATION
-    scr1buf = static_cast<char*>(xbt_malloc(scrlng));
-    scr2buf = static_cast<char*>(xbt_malloc(scrlng));
-    scr3buf = static_cast<char*>(xbt_malloc(scrlng));
+    scr1buf = new char[scrlng];
+    scr2buf = new char[scrlng];
+    scr3buf = new char[scrlng];
 #else
 #  ifdef SCR_LNG_OPTIM
     scrlng = SCR_LNG_OPTIM(scrlng);
 #  endif
-    scr2buf = static_cast<char*>(xbt_malloc(3*scrlng));   /* To test cache problems.     */
+    scr2buf = new char[3 * scrlng]; /* To test cache problems.     */
     scr1buf = scr2buf + 1*scrlng; /* scr1buf and scr3buf must not*/
     scr3buf = scr2buf + 2*scrlng; /* be used for malloc because  */
                                   /* they are interchanged below.*/
@@ -913,9 +932,11 @@ static int MPI_I_anyReduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype
     }
 
 #   ifdef NO_CACHE_TESTING
-     xbt_free(scr1buf); xbt_free(scr2buf); xbt_free(scr3buf);
+    delete[] scr1buf;
+    delete[] scr2buf;
+    delete[] scr3buf;
 #   else
-     xbt_free(scr2buf); /* scr1buf and scr3buf are part of scr2buf */
+    delete[] scr2buf;             /* scr1buf and scr3buf are part of scr2buf */
 #   endif
     return(MPI_SUCCESS);
   } /* new_prot */
@@ -928,12 +949,14 @@ static int MPI_I_anyReduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype
 #endif /*REDUCE_LIMITS*/
 
 
-int Coll_reduce_rab::reduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
+int Coll_reduce_rab::reduce(const void* Sendbuf, void* Recvbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm)
 {
   return( MPI_I_anyReduce(Sendbuf, Recvbuf, count, datatype, op, root, comm, 0) );
 }
 
-int Coll_allreduce_rab::allreduce(void* Sendbuf, void* Recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
+int Coll_allreduce_rab::allreduce(const void* Sendbuf, void* Recvbuf, int count, MPI_Datatype datatype, MPI_Op op, MPI_Comm comm)
 {
   return( MPI_I_anyReduce(Sendbuf, Recvbuf, count, datatype, op,   -1, comm, 1) );
 }
+}
+}