Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
We should'nt allow the use of uncommited datatypes in communications.
[simgrid.git] / src / smpi / smpi_mpi_dt.c
index eb1d71c..7cb76b7 100644 (file)
@@ -14,6 +14,7 @@
 #include "private.h"
 #include "smpi_mpi_dt_private.h"
 #include "mc/mc.h"
+#include "xbt/replay.h"
 #include "simgrid/modelchecker.h"
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_mpi_dt, smpi,
@@ -122,14 +123,18 @@ CREATE_MPI_DATATYPE_NULL(MPI_PACKED);
 // Internal use only
 CREATE_MPI_DATATYPE(MPI_PTR, void*);
 
+/** Check if the datatype is usable for communications
+ */
+int is_datatype_valid(MPI_Datatype datatype) {
+    return datatype != MPI_DATATYPE_NULL
+        && (datatype->flags & DT_FLAG_COMMITED);
+}
 
 size_t smpi_datatype_size(MPI_Datatype datatype)
 {
   return datatype->size;
 }
 
-
-
 MPI_Aint smpi_datatype_lb(MPI_Datatype datatype)
 {
   return datatype->lb;
@@ -156,7 +161,9 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
                        void *recvbuf, int recvcount, MPI_Datatype recvtype)
 {
   int count;
-
+  if(smpi_privatize_global_variables){
+    switch_data_segment(smpi_process_index());
+  }
   /* First check if we really have something to do */
   if (recvcount > 0 && recvbuf != sendbuf) {
     /* FIXME: treat packed cases */
@@ -165,7 +172,7 @@ int smpi_datatype_copy(void *sendbuf, int sendcount, MPI_Datatype sendtype,
     count = sendcount < recvcount ? sendcount : recvcount;
 
     if(sendtype->has_subtype == 0 && recvtype->has_subtype == 0) {
-      memcpy(recvbuf, sendbuf, count);
+      if(!_xbt_replay_is_active()) memcpy(recvbuf, sendbuf, count);
     }
     else if (sendtype->has_subtype == 0)
     {
@@ -323,7 +330,7 @@ void smpi_datatype_free(MPI_Datatype* type){
     xbt_free((*type)->substruct);
   }
   xbt_free(*type);
-
+  *type = MPI_DATATYPE_NULL;
 }
 
 void smpi_datatype_use(MPI_Datatype type){
@@ -1488,5 +1495,11 @@ void smpi_op_destroy(MPI_Op op)
 void smpi_op_apply(MPI_Op op, void *invec, void *inoutvec, int *len,
                    MPI_Datatype * datatype)
 {
+  if(smpi_privatize_global_variables){ //we need to switch here, as the called function may silently touch global variables
+    XBT_VERB("Applying operation, switch to the right data frame ");
+    switch_data_segment(smpi_process_index());
+  }
+
+  if(!_xbt_replay_is_active())
   op->func(invec, inoutvec, len, datatype);
 }