Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
No need to test for attributes()->empty().
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Sun, 23 May 2021 12:41:53 +0000 (14:41 +0200)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 25 May 2021 08:43:38 +0000 (10:43 +0200)
src/smpi/include/smpi_keyvals.hpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp

index e2f9662..2c93473 100644 (file)
@@ -117,10 +117,7 @@ template <typename T> int Keyval::attr_get(int keyval, void* attr_value, int* fl
   const s_smpi_key_elem_t* elem = T::keyvals_.at(keyval);
   if(elem==nullptr)
     return MPI_ERR_ARG;
-  if(attributes()->empty()){
-    *flag=0;
-    return MPI_SUCCESS;
-  }
+
   const auto& attribs = attributes();
   auto attr           = attribs->find(keyval);
   if (attr != attribs->end()) {
@@ -150,19 +147,17 @@ template <typename T> int Keyval::attr_put(int keyval, void* attr_value){
 }
 
 template <typename T> void Keyval::cleanup_attr(){
-  if (not attributes()->empty()) {
-    int flag=0;
-    for (auto const& it : attributes_) {
-      auto elm = T::keyvals_.find(it.first);
-      if (elm != T::keyvals_.end()) {
-        smpi_key_elem elem = elm->second;
-        if(elem != nullptr){
-          call_deleter<T>((T*)this, elem, it.first,it.second,&flag);
-        }
-      } else {
-        // already deleted, not a problem
-        flag=0;
+  int flag = 0;
+  for (auto const& it : attributes_) {
+    auto elm = T::keyvals_.find(it.first);
+    if (elm != T::keyvals_.end()) {
+      smpi_key_elem elem = elm->second;
+      if (elem != nullptr) {
+        call_deleter<T>((T*)this, elem, it.first, it.second, &flag);
       }
+    } else {
+      // already deleted, not a problem
+      flag = 0;
     }
   }
 }
index 84ffe79..1ef564d 100644 (file)
@@ -79,33 +79,29 @@ int Comm::dup(MPI_Comm* newcomm){
   (*newcomm)   = new  Comm(cp, this->topo());
   int ret      = MPI_SUCCESS;
 
-  if (not attributes()->empty()) {
-    int flag=0;
-    void* value_out=nullptr;
-    for (auto const& it : *attributes()) {
-      smpi_key_elem elem = keyvals_.at(it.first);
-      if (elem != nullptr){
-        if( elem->copy_fn.comm_copy_fn != MPI_NULL_COPY_FN && 
-            elem->copy_fn.comm_copy_fn != MPI_COMM_DUP_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 (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()->insert({it.first, it.second});
-        }else if (flag){
-          elem->refcount++;
-          (*newcomm)->attributes()->insert({it.first, value_out});
-        }
+  for (auto const& it : *attributes()) {
+    smpi_key_elem elem = keyvals_.at(it.first);
+    if (elem != nullptr) {
+      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)
+        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 (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()->insert({it.first, it.second});
+      } else if (flag) {
+        elem->refcount++;
+        (*newcomm)->attributes()->insert({it.first, value_out});
       }
     }
   }
index 1bef5a1..cb1bee7 100644 (file)
@@ -162,32 +162,28 @@ Datatype::~Datatype()
 int Datatype::copy_attrs(Datatype* datatype){
   flags_ &= ~DT_FLAG_PREDEFINED;
   int ret = MPI_SUCCESS;
-    
-  if (not datatype->attributes()->empty()) {
-    int flag=0;
-    void* value_out;
-    for (auto const& it : *(datatype->attributes())) {
-      smpi_key_elem elem = keyvals_.at(it.first);
-      if (elem != nullptr){
-        if( elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN && 
-            elem->copy_fn.type_copy_fn != MPI_TYPE_DUP_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 (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()->insert({it.first, it.second});
-        } else if (flag){
-          elem->refcount++;
-          attributes()->insert({it.first, value_out});
-        }
+
+  for (auto const& it : *(datatype->attributes())) {
+    smpi_key_elem elem = keyvals_.at(it.first);
+    if (elem != nullptr) {
+      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)
+        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 (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()->insert({it.first, it.second});
+      } else if (flag) {
+        elem->refcount++;
+        attributes()->insert({it.first, value_out});
       }
     }
   }