Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Review allocation of MPI attributes with Fortran bindings.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 23 May 2021 20:26:58 +0000 (22:26 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 14:59:28 +0000 (16:59 +0200)
src/smpi/bindings/smpi_f77.cpp
src/smpi/bindings/smpi_f77_comm.cpp
src/smpi/bindings/smpi_f77_type.cpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp

index 4f7ce4a..bfdbbc5 100644 (file)
@@ -273,7 +273,7 @@ void mpi_win_get_attr_(int* win, int* win_keyval, MPI_Aint* attribute_val, int*
 
 void mpi_win_set_attr_(int* win, int* win_keyval, MPI_Aint* att, int* ierr)
 {
-  auto* val = static_cast<MPI_Aint*>(xbt_malloc(sizeof(MPI_Aint)));
+  auto* val = xbt_new(MPI_Aint, 1);
   *val      = *att;
   *ierr     = MPI_Win_set_attr(simgrid::smpi::Win::f2c(*win), *win_keyval, val);
 }
@@ -801,7 +801,7 @@ void mpi_attr_delete_ (int* comm, int* keyval, int* ierr) {
 }
 
 void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) {
-  auto* val = static_cast<int*>(xbt_malloc(sizeof(int)));
+  auto* val = xbt_new(int, 1);
   *val      = *attr_value;
   *ierr     = MPI_Attr_put(simgrid::smpi::Comm::f2c(*comm), *keyval, val);
 }
index a540c6d..0113de4 100644 (file)
@@ -79,7 +79,7 @@ void mpi_comm_get_attr_ (int* comm, int* comm_keyval, int *attribute_val, int *f
 }
 
 void mpi_comm_set_attr_ (int* comm, int* comm_keyval, int *attribute_val, int* ierr){
-  auto* val = static_cast<int*>(xbt_malloc(sizeof(int)));
+  auto* val = xbt_new(int, 1);
   *val      = *attribute_val;
   *ierr     = MPI_Comm_set_attr(simgrid::smpi::Comm::f2c(*comm), *comm_keyval, val);
 }
index cf0a54d..1bd48b0 100644 (file)
@@ -64,7 +64,7 @@ void mpi_type_get_attr_ (int* type, int* type_keyval, int *attribute_val, int* f
 }
 
 void mpi_type_set_attr_ (int* type, int* type_keyval, int *attribute_val, int* ierr){
-  auto* val = static_cast<int*>(xbt_malloc(sizeof(int)));
+  auto* val = xbt_new(int, 1);
   *val      = *attribute_val;
   *ierr     = MPI_Type_set_attr(simgrid::smpi::Datatype::f2c(*type), *type_keyval, val);
 }
index 54d494d..3962016 100644 (file)
@@ -77,30 +77,37 @@ int Comm::dup(MPI_Comm* newcomm){
   }
   auto* cp     = new Group(this->group());
   (*newcomm)   = new  Comm(cp, this->topo());
-  int ret      = MPI_SUCCESS;
 
   for (auto const& it : attributes()) {
     auto elem_it = keyvals_.find(it.first);
     if (elem_it != keyvals_.end()) {
       smpi_key_elem& elem = elem_it->second;
-      int flag        = 0;
-      void* value_out = nullptr;
-      if (elem.copy_fn.comm_copy_fn != MPI_NULL_COPY_FN && elem.copy_fn.comm_copy_fn != MPI_COMM_DUP_FN)
+      int ret             = MPI_SUCCESS;
+      int flag            = 0;
+      void* value_out     = nullptr;
+      if (elem.copy_fn.comm_copy_fn == MPI_COMM_DUP_FN) {
+        value_out = it.second;
+        flag      = 1;
+      } else if (elem.copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) {
         ret = elem.copy_fn.comm_copy_fn(this, it.first, elem.extra_state, it.second, &value_out, &flag);
-      else if (elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN && *(int*)*elem.copy_fn.comm_copy_fn_fort != 1) {
-        value_out = (int*)xbt_malloc(sizeof(int));
-        elem.copy_fn.comm_copy_fn_fort(this, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+      }
+      if (elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) {
+        value_out = xbt_new(int, 1);
+        if (*(int*)*elem.copy_fn.comm_copy_fn_fort == 1) { // MPI_COMM_DUP_FN
+          memcpy(value_out, it.second, sizeof(int));
+          flag = 1;
+        } else { // not null, nor dup
+          elem.copy_fn.comm_copy_fn_fort(this, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+          if (ret != MPI_SUCCESS)
+            xbt_free(value_out);
+        }
       }
       if (ret != MPI_SUCCESS) {
         Comm::destroy(*newcomm);
         *newcomm = MPI_COMM_NULL;
         return ret;
       }
-      if (elem.copy_fn.comm_copy_fn == MPI_COMM_DUP_FN ||
-          ((elem.copy_fn.comm_copy_fn_fort != MPI_NULL_COPY_FN) && *(int*)*elem.copy_fn.comm_copy_fn_fort == 1)) {
-        elem.refcount++;
-        (*newcomm)->attributes().emplace(it.first, it.second);
-      } else if (flag) {
+      if (flag) {
         elem.refcount++;
         (*newcomm)->attributes().emplace(it.first, value_out);
       }
@@ -114,7 +121,7 @@ int Comm::dup(MPI_Comm* newcomm){
     (*newcomm)->set_errhandler(errhandlers_[this->rank()]);
   else
     (*newcomm)->set_errhandler(errhandler_);
-  return ret;
+  return MPI_SUCCESS;
 }
 
 int Comm::dup_with_info(MPI_Info info, MPI_Comm* newcomm){
index 1a80257..561499f 100644 (file)
@@ -168,21 +168,28 @@ int Datatype::copy_attrs(Datatype* datatype){
     if (elem_it != keyvals_.end()) {
       smpi_key_elem& elem = elem_it->second;
       int flag            = 0;
-      void* value_out;
-      if (elem.copy_fn.type_copy_fn != MPI_NULL_COPY_FN && elem.copy_fn.type_copy_fn != MPI_TYPE_DUP_FN)
+      void* value_out     = nullptr;
+      if (elem.copy_fn.type_copy_fn == MPI_TYPE_DUP_FN) {
+        value_out = it.second;
+        flag      = 1;
+      } else if (elem.copy_fn.type_copy_fn != MPI_NULL_COPY_FN) {
         ret = elem.copy_fn.type_copy_fn(datatype, it.first, elem.extra_state, it.second, &value_out, &flag);
-      else if (elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN && (*(int*)*elem.copy_fn.type_copy_fn_fort) != 1) {
-        value_out = (int*)xbt_malloc(sizeof(int));
-        elem.copy_fn.type_copy_fn_fort(datatype, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+      }
+      if (elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) {
+        value_out = xbt_new(int, 1);
+        if (*(int*)*elem.copy_fn.type_copy_fn_fort == 1) { // MPI_TYPE_DUP_FN
+          memcpy(value_out, it.second, sizeof(int));
+          flag = 1;
+        } else { // not null, nor dup
+          elem.copy_fn.type_copy_fn_fort(datatype, it.first, elem.extra_state, it.second, value_out, &flag, &ret);
+          if (ret != MPI_SUCCESS)
+            xbt_free(value_out);
+        }
       }
       if (ret != MPI_SUCCESS) {
         break;
       }
-      if (elem.copy_fn.type_copy_fn == MPI_TYPE_DUP_FN ||
-          ((elem.copy_fn.type_copy_fn_fort != MPI_NULL_COPY_FN) && (*(int*)*elem.copy_fn.type_copy_fn_fort == 1))) {
-        elem.refcount++;
-        attributes().emplace(it.first, it.second);
-      } else if (flag) {
+      if (flag) {
         elem.refcount++;
         attributes().emplace(it.first, value_out);
       }