Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
correct some issues with MPI_Sendrecv_replace, to avoid segfaults. I should implement...
[simgrid.git] / src / smpi / smpi_pmpi.c
index a83b0bd..5f4e6a2 100644 (file)
@@ -1152,16 +1152,24 @@ int PMPI_Sendrecv_replace(void *buf, int count, MPI_Datatype datatype,
                          MPI_Comm comm, MPI_Status * status)
 {
   //TODO: suboptimal implementation
// void *recvbuf;
+  void *recvbuf;
   int retval;
+  if ((datatype == MPI_DATATYPE_NULL)||(datatype->has_subtype==1)) {
+      retval = MPI_ERR_TYPE;
+  } else if (count < 0) {
+      retval = MPI_ERR_COUNT;
+  } else {
+    int size = smpi_datatype_size(datatype) * count;
+    recvbuf = xbt_new(char, size);
+    retval =
+        MPI_Sendrecv(buf, count, datatype, dst, sendtag, recvbuf, count,
+                     datatype, src, recvtag, comm, status);
+    if(retval==MPI_SUCCESS){
+        memcpy(buf, recvbuf, size * sizeof(char));
+    }
+    xbt_free(recvbuf);
 
-//  size = smpi_datatype_size(datatype) * count;
-//  recvbuf = xbt_new(char, size);
-  retval =
-      MPI_Sendrecv(buf, count, datatype, dst, sendtag, buf, count,
-                   datatype, src, recvtag, comm, status);
-/*memcpy(buf, recvbuf, size * sizeof(char));
-  xbt_free(recvbuf);*/
+  }
   return retval;
 }
 
@@ -2055,6 +2063,11 @@ int PMPI_Type_struct(int count, int* blocklens, MPI_Aint* indices, MPI_Datatype*
   smpi_bench_begin();
   return retval;}
 
+int PMPI_Error_class(int errorcode, int* errorclass) {
+  // assume smpi uses only standard mpi error codes
+  *errorclass=errorcode;
+  return MPI_SUCCESS;
+}
 
 /* The following calls are not yet implemented and will fail at runtime. */
 /* Once implemented, please move them above this notice. */
@@ -2128,10 +2141,6 @@ int PMPI_Topo_test(MPI_Comm comm, int* top_type) {
    return not_yet_implemented();
 }
 
-int PMPI_Error_class(int errorcode, int* errorclass) {
-   return not_yet_implemented();
-}
-
 int PMPI_Errhandler_create(MPI_Handler_function* function, MPI_Errhandler* errhandler) {
    return not_yet_implemented();
 }