Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Keyval should always exist.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 27 May 2021 07:52:59 +0000 (09:52 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Thu, 27 May 2021 09:17:01 +0000 (11:17 +0200)
Also please sonar by reducing depth for nested blocks.

src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp

index 6c350f0..9d6ac04 100644 (file)
@@ -80,37 +80,37 @@ int Comm::dup(MPI_Comm* newcomm){
 
   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 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);
-      }
-      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 (flag) {
-        elem.refcount++;
-        (*newcomm)->attributes().emplace(it.first, value_out);
+    xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Comm: %d", it.first);
+
+    smpi_key_elem& elem = elem_it->second;
+    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);
+    }
+    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 (flag) {
+      elem.refcount++;
+      (*newcomm)->attributes().emplace(it.first, value_out);
     }
   }
   //duplicate info if present
index d1b5b93..8fb7e77 100644 (file)
@@ -164,42 +164,41 @@ Datatype::~Datatype()
 
 int Datatype::copy_attrs(Datatype* datatype){
   flags_ &= ~DT_FLAG_PREDEFINED;
-  int ret = MPI_SUCCESS;
 
+  set_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype);
   for (auto const& it : datatype->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.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);
-      }
-      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 (flag) {
-        elem.refcount++;
-        attributes().emplace(it.first, value_out);
+    xbt_assert(elem_it != keyvals_.end(), "Keyval not found for Datatype: %d", it.first);
+
+    smpi_key_elem& elem = elem_it->second;
+    int ret             = MPI_SUCCESS;
+    int flag            = 0;
+    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);
+    }
+    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)
+      return ret;
+    if (flag) {
+      elem.refcount++;
+      attributes().emplace(it.first, value_out);
     }
   }
-  set_contents(MPI_COMBINER_DUP, 0, nullptr, 0, nullptr, 1, &datatype);
-  return ret;
+  return MPI_SUCCESS;
 }
 
 int Datatype::clone(MPI_Datatype* type){