Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
activate commute flag for MPI_Op, adds smpi_op_is_commute to test it (-1 FIXME !)
[simgrid.git] / src / smpi / smpi_mpi_dt.c
index 19f0228..6041b85 100644 (file)
@@ -153,12 +153,10 @@ MPI_Aint smpi_datatype_get_extent(MPI_Datatype datatype){
 int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
                        void *recvbuf, int recvcount, MPI_Datatype recvtype)
 {
-  int retval, count;
+  int count;
 
   /* First check if we really have something to do */
-  if (recvcount == 0) {
-    retval = sendcount == 0 ? MPI_SUCCESS : MPI_ERR_TRUNCATE;
-  } else {
+  if (recvcount > 0 && recvbuf != sendbuf) {
     /* FIXME: treat packed cases */
     sendcount *= smpi_datatype_size(sendtype);
     recvcount *= smpi_datatype_size(recvtype);
@@ -179,20 +177,18 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     }else{
       s_smpi_subtype_t *subtype =  sendtype->substruct;
 
-      s_smpi_mpi_vector_t* type_c = (s_smpi_mpi_vector_t*)sendtype;
 
-      void * buf_tmp = xbt_malloc(count * type_c->size_oldtype);
+      void * buf_tmp = xbt_malloc(count);
 
       subtype->serialize( sendbuf, buf_tmp,1, subtype);
       subtype =  recvtype->substruct;
-      subtype->unserialize(recvbuf, buf_tmp,1, subtype);
+      subtype->unserialize( buf_tmp, recvbuf,1, subtype);
 
       free(buf_tmp);
     }
-    retval = sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
   }
 
-  return retval;
+  return sendcount > recvcount ? MPI_ERR_TRUNCATE : MPI_SUCCESS;
 }
 
 /*
@@ -311,6 +307,7 @@ void smpi_datatype_free(MPI_Datatype* type){
 
   if ((*type)->has_subtype == 1){
     ((s_smpi_subtype_t *)(*type)->substruct)->subtype_free(type);  
+    xbt_free((*type)->substruct);
   }
   xbt_free(*type);
 
@@ -1008,6 +1005,7 @@ void smpi_datatype_commit(MPI_Datatype *datatype)
 
 typedef struct s_smpi_mpi_op {
   MPI_User_function *func;
+  int is_commute;
 } s_smpi_mpi_op_t;
 
 #define MAX_OP(a, b)  (b) = (a) < (b) ? (b) : (a)
@@ -1329,7 +1327,7 @@ static void maxloc_func(void *a, void *b, int *length,
 
 
 #define CREATE_MPI_OP(name, func)                             \
-  static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */ }; \
+  static s_smpi_mpi_op_t mpi_##name = { &(func) /* func */, TRUE }; \
 MPI_Op name = &mpi_##name;
 
 CREATE_MPI_OP(MPI_MAX, max_func);
@@ -1348,13 +1346,17 @@ CREATE_MPI_OP(MPI_MINLOC, minloc_func);
 MPI_Op smpi_op_new(MPI_User_function * function, int commute)
 {
   MPI_Op op;
-
-  //FIXME: add commute param
   op = xbt_new(s_smpi_mpi_op_t, 1);
   op->func = function;
+  op-> is_commute = commute;
   return op;
 }
 
+int smpi_op_is_commute(MPI_Op op)
+{
+  return op-> is_commute;
+}
+
 void smpi_op_destroy(MPI_Op op)
 {
   xbt_free(op);