Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Have attributes actually work in fortran... the horror
authorAugustin Degomme <degomme@wasabi>
Tue, 25 Sep 2018 09:29:09 +0000 (11:29 +0200)
committerAugustin Degomme <degomme@wasabi>
Tue, 25 Sep 2018 10:06:49 +0000 (12:06 +0200)
Callbacks signatures and behavior differ slightly from C, so try to do that correctly, if not cleanly

12 files changed:
include/smpi/mpif.h.in
include/smpi/smpi.h
src/smpi/bindings/smpi_f77.cpp
src/smpi/bindings/smpi_f77_comm.cpp
src/smpi/bindings/smpi_f77_type.cpp
src/smpi/bindings/smpi_pmpi.cpp
src/smpi/bindings/smpi_pmpi_type.cpp
src/smpi/bindings/smpi_pmpi_win.cpp
src/smpi/include/smpi_keyvals.hpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_datatype.cpp
src/smpi/mpi/smpi_keyvals.cpp

index 2a43590..1f01d37 100644 (file)
       integer MPI_COMM_NULL_COPY_FN, MPI_COMM_NULL_DELETE_FN
       parameter(MPI_COMM_NULL_COPY_FN =0)
       parameter(MPI_COMM_NULL_DELETE_FN =0)
       integer MPI_COMM_NULL_COPY_FN, MPI_COMM_NULL_DELETE_FN
       parameter(MPI_COMM_NULL_COPY_FN =0)
       parameter(MPI_COMM_NULL_DELETE_FN =0)
-      integer MPI_COMM_NULL_DUP_FN, MPI_COMM_DUP_FN
-      parameter(MPI_COMM_NULL_DUP_FN =0)
-      parameter(MPI_COMM_DUP_FN =0)
+      integer MPI_COMM_DUP_FN
+      parameter(MPI_COMM_DUP_FN =1)
       integer MPI_WIN_NULL_COPY_FN, MPI_WIN_NULL_DELETE_FN
       parameter(MPI_WIN_NULL_COPY_FN =0)
       parameter(MPI_WIN_NULL_DELETE_FN =0)
       integer MPI_WIN_DUP_FN
       integer MPI_WIN_NULL_COPY_FN, MPI_WIN_NULL_DELETE_FN
       parameter(MPI_WIN_NULL_COPY_FN =0)
       parameter(MPI_WIN_NULL_DELETE_FN =0)
       integer MPI_WIN_DUP_FN
-      parameter(MPI_WIN_DUP_FN =0)
+      parameter(MPI_WIN_DUP_FN =1)
+      integer MPI_TYPE_NULL_COPY_FN, MPI_TYPE_NULL_DELETE_FN
+      parameter(MPI_TYPE_NULL_COPY_FN =0)
+      parameter(MPI_TYPE_NULL_DELETE_FN =0)
+      integer MPI_TYPE_DUP_FN
+      parameter(MPI_TYPE_DUP_FN =1)
 
       integer MPI_ROOT, MPI_COMM_TYPE_SHARED
       parameter(MPI_ROOT=0)
 
       integer MPI_ROOT, MPI_COMM_TYPE_SHARED
       parameter(MPI_ROOT=0)
index 51f0939..9af55d8 100644 (file)
@@ -372,14 +372,25 @@ typedef enum SMPI_Topo_type {
 typedef int MPI_Copy_function(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Delete_function(MPI_Comm comm, int keyval, void* attribute_val, void* extra_state);
 typedef int MPI_Copy_function(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Delete_function(MPI_Comm comm, int keyval, void* attribute_val, void* extra_state);
+typedef void MPI_Copy_function_fort(MPI_Comm oldcomm, int keyval, void* extra_state, void* attribute_val_in,
+                              void* attribute_val_out, int* flag, int* ierr);
+typedef void MPI_Delete_function_fort(MPI_Comm comm, int keyval, void* attribute_val, void* extra_state, int* ierr);
 #define MPI_Comm_copy_attr_function MPI_Copy_function
 #define MPI_Comm_delete_attr_function MPI_Delete_function
 #define MPI_Comm_copy_attr_function MPI_Copy_function
 #define MPI_Comm_delete_attr_function MPI_Delete_function
+#define MPI_Comm_copy_attr_function_fort MPI_Copy_function_fort
+#define MPI_Comm_delete_attr_function_fort MPI_Delete_function_fort
 typedef int MPI_Type_copy_attr_function(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Type_delete_attr_function(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state);
 typedef int MPI_Win_copy_attr_function(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Win_delete_attr_function(MPI_Win win, int keyval, void* attribute_val, void* extra_state);
 typedef int MPI_Type_copy_attr_function(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Type_delete_attr_function(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state);
 typedef int MPI_Win_copy_attr_function(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in,
                               void* attribute_val_out, int* flag);
 typedef int MPI_Win_delete_attr_function(MPI_Win win, int keyval, void* attribute_val, void* extra_state);
+typedef void MPI_Type_copy_attr_function_fort(MPI_Datatype type, int keyval, void* extra_state, void* attribute_val_in,
+                              void* attribute_val_out, int* flag, int* ierr);
+typedef void MPI_Type_delete_attr_function_fort(MPI_Datatype type, int keyval, void* attribute_val, void* extra_state, int* ierr);
+typedef void MPI_Win_copy_attr_function_fort(MPI_Win win, int keyval, void* extra_state, void* attribute_val_in,
+                              void* attribute_val_out, int* flag, int* ierr);
+typedef void MPI_Win_delete_attr_function_fort(MPI_Win win, int keyval, void* attribute_val, void* extra_state, int* ierr);
 #define MPI_COMM_NULL_COPY_FN ((MPI_Comm_copy_attr_function*)0)
 #define MPI_COMM_NULL_DELETE_FN ((MPI_Comm_delete_attr_function*)0)
 #define MPI_TYPE_NULL_COPY_FN ((MPI_Type_copy_attr_function*)0)
 #define MPI_COMM_NULL_COPY_FN ((MPI_Comm_copy_attr_function*)0)
 #define MPI_COMM_NULL_DELETE_FN ((MPI_Comm_delete_attr_function*)0)
 #define MPI_TYPE_NULL_COPY_FN ((MPI_Type_copy_attr_function*)0)
index f28922c..42165e3 100644 (file)
@@ -244,8 +244,9 @@ void mpi_win_delete_attr_(int* win, int* comm_keyval, int* ierr){
 }
 
 void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
 }
 
 void mpi_win_create_keyval_(void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
-  *ierr = MPI_Win_create_keyval(reinterpret_cast<MPI_Win_copy_attr_function*>(copy_fn),
-                                reinterpret_cast<MPI_Win_delete_attr_function*>(delete_fn), keyval, extra_state);
+  smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_copy_attr_function_fort*>(copy_fn)};
+  smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Win_delete_attr_function_fort*>(delete_fn)};
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
 void mpi_win_free_keyval_(int* keyval, int* ierr){
 }
 
 void mpi_win_free_keyval_(int* keyval, int* ierr){
@@ -718,7 +719,9 @@ void mpi_attr_put_ (int* comm, int* keyval, int* attr_value, int* ierr) {
 }
 
 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
 }
 
 void mpi_keyval_create_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr) {
- *ierr = MPI_Keyval_create(reinterpret_cast<MPI_Copy_function*>(copy_fn),reinterpret_cast<MPI_Delete_function*>(delete_fn), keyval, extra_state);
+  smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Copy_function_fort*>(copy_fn),nullptr,nullptr};
+  smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Delete_function_fort*>(delete_fn),nullptr,nullptr};
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
 void mpi_keyval_free_ (int* keyval, int* ierr) {
 }
 
 void mpi_keyval_free_ (int* keyval, int* ierr) {
index 02893b9..3e051e5 100644 (file)
@@ -90,9 +90,9 @@ void mpi_comm_delete_attr_ (int* comm, int* comm_keyval, int* ierr){
 }
 
 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
 }
 
 void mpi_comm_create_keyval_ (void* copy_fn, void* delete_fn, int* keyval, void* extra_state, int* ierr){
-
- *ierr = MPI_Comm_create_keyval(reinterpret_cast<MPI_Comm_copy_attr_function*>(copy_fn),  reinterpret_cast<MPI_Comm_delete_attr_function*>(delete_fn),
-         keyval,  extra_state) ;
+  smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_copy_attr_function_fort*>(copy_fn),nullptr,nullptr};
+  smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Comm_delete_attr_function_fort*>(delete_fn),nullptr,nullptr};
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
 }
 
 void mpi_comm_free_keyval_ (int* keyval, int* ierr) {
index 94773b8..ffd647b 100644 (file)
@@ -75,9 +75,9 @@ void mpi_type_delete_attr_ (int* type, int* type_keyval, int* ierr){
 }
 
 void mpi_type_create_keyval_ (void* copy_fn, void*  delete_fn, int* keyval, void* extra_state, int* ierr){
 }
 
 void mpi_type_create_keyval_ (void* copy_fn, void*  delete_fn, int* keyval, void* extra_state, int* ierr){
-
- *ierr = MPI_Type_create_keyval(reinterpret_cast<MPI_Type_copy_attr_function*>(copy_fn), reinterpret_cast<MPI_Type_delete_attr_function*>(delete_fn),
-                                keyval,  extra_state) ;
+  smpi_copy_fn _copy_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)copy_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_copy_attr_function_fort*>(copy_fn),nullptr};
+  smpi_delete_fn _delete_fn={nullptr,nullptr,nullptr,nullptr,(*(int*)delete_fn) == 0 ? nullptr : reinterpret_cast<MPI_Type_delete_attr_function_fort*>(delete_fn),nullptr};
+  *ierr = simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
 void mpi_type_free_keyval_ (int* keyval, int* ierr) {
 }
 
 void mpi_type_free_keyval_ (int* keyval, int* ierr) {
index e8622ac..08daa66 100644 (file)
@@ -223,8 +223,8 @@ int PMPI_Error_string(int errorcode, char* string, int* resultlen){
 }
 
 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
 }
 
 int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) {
-  smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr};
-  smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr};
+  smpi_copy_fn _copy_fn={copy_fn,nullptr,nullptr,nullptr,nullptr,nullptr};
+  smpi_delete_fn _delete_fn={delete_fn,nullptr,nullptr,nullptr,nullptr,nullptr};
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Comm>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
index ada61b8..5fcc106 100644 (file)
@@ -325,8 +325,8 @@ int PMPI_Type_delete_attr (MPI_Datatype type, int type_keyval)
 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state)
 {
 int PMPI_Type_create_keyval(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state)
 {
-  smpi_copy_fn _copy_fn={nullptr,copy_fn,nullptr};
-  smpi_delete_fn _delete_fn={nullptr,delete_fn,nullptr};
+  smpi_copy_fn _copy_fn={nullptr,copy_fn,nullptr,nullptr,nullptr,nullptr};
+  smpi_delete_fn _delete_fn={nullptr,delete_fn,nullptr,nullptr,nullptr,nullptr};
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Datatype>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
index 5a8ca34..b3ca2d7 100644 (file)
@@ -829,8 +829,8 @@ int PMPI_Win_delete_attr (MPI_Win win, int type_keyval)
 int PMPI_Win_create_keyval(MPI_Win_copy_attr_function* copy_fn, MPI_Win_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state)
 {
 int PMPI_Win_create_keyval(MPI_Win_copy_attr_function* copy_fn, MPI_Win_delete_attr_function* delete_fn, int* keyval,
                             void* extra_state)
 {
-  smpi_copy_fn _copy_fn={nullptr, nullptr, copy_fn};
-  smpi_delete_fn _delete_fn={nullptr, nullptr, delete_fn};
+  smpi_copy_fn _copy_fn={nullptr, nullptr,copy_fn,nullptr, nullptr,nullptr};
+  smpi_delete_fn _delete_fn={nullptr, nullptr,delete_fn,nullptr, nullptr,nullptr};
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
   return simgrid::smpi::Keyval::keyval_create<simgrid::smpi::Win>(_copy_fn, _delete_fn, keyval, extra_state);
 }
 
index 1f8ce73..43daa90 100644 (file)
@@ -14,17 +14,24 @@ struct smpi_delete_fn {
   MPI_Comm_delete_attr_function          *comm_delete_fn;
   MPI_Type_delete_attr_function          *type_delete_fn;
   MPI_Win_delete_attr_function           *win_delete_fn;
   MPI_Comm_delete_attr_function          *comm_delete_fn;
   MPI_Type_delete_attr_function          *type_delete_fn;
   MPI_Win_delete_attr_function           *win_delete_fn;
+  MPI_Comm_delete_attr_function_fort     *comm_delete_fn_fort;
+  MPI_Type_delete_attr_function_fort     *type_delete_fn_fort;
+  MPI_Win_delete_attr_function_fort      *win_delete_fn_fort;
 };
 
 struct smpi_copy_fn {
   MPI_Comm_copy_attr_function          *comm_copy_fn;
   MPI_Type_copy_attr_function          *type_copy_fn;
   MPI_Win_copy_attr_function           *win_copy_fn;
 };
 
 struct smpi_copy_fn {
   MPI_Comm_copy_attr_function          *comm_copy_fn;
   MPI_Type_copy_attr_function          *type_copy_fn;
   MPI_Win_copy_attr_function           *win_copy_fn;
+  MPI_Comm_copy_attr_function_fort     *comm_copy_fn_fort;
+  MPI_Type_copy_attr_function_fort     *type_copy_fn_fort;
+  MPI_Win_copy_attr_function_fort      *win_copy_fn_fort;
 };
 
 struct s_smpi_key_elem_t {
   smpi_copy_fn copy_fn;
   smpi_delete_fn delete_fn;
 };
 
 struct s_smpi_key_elem_t {
   smpi_copy_fn copy_fn;
   smpi_delete_fn delete_fn;
+  void* extra_state;
   int refcount;
 };
 
   int refcount;
 };
 
@@ -57,6 +64,7 @@ template <typename T> int Keyval::keyval_create(smpi_copy_fn copy_fn, smpi_delet
 
   value->copy_fn=copy_fn;
   value->delete_fn=delete_fn;
 
   value->copy_fn=copy_fn;
   value->delete_fn=delete_fn;
+  value->extra_state=extra_state;
   value->refcount=1;
 
   *keyval = T::keyval_id_;
   value->refcount=1;
 
   *keyval = T::keyval_id_;
@@ -126,13 +134,14 @@ template <typename T> int Keyval::attr_put(int keyval, void* attr_value){
   elem->refcount++;
   void * value = nullptr;
   int flag=0;
   elem->refcount++;
   void * value = nullptr;
   int flag=0;
-  this->attr_get<T>(keyval, &value, &flag);
-  if(flag!=0){
-    int ret = call_deleter<T>((T*)this, elem, keyval,value,&flag);
+  auto p = attributes()->insert({keyval, attr_value});
+  if (!p.second) {
+    int ret = call_deleter<T>((T*)this, elem, keyval,p.first->second,&flag);
+    // overwrite previous value
+    p.first->second = attr_value;
     if(ret!=MPI_SUCCESS)
     if(ret!=MPI_SUCCESS)
-        return ret;
+      return ret;
   }
   }
-  attributes()->insert({keyval, attr_value});
   return MPI_SUCCESS;
 }
 
   return MPI_SUCCESS;
 }
 
index 57c61d2..47cf004 100644 (file)
@@ -61,18 +61,29 @@ int Comm::dup(MPI_Comm* newcomm){
   int ret      = MPI_SUCCESS;
 
   if (not attributes()->empty()) {
   int ret      = MPI_SUCCESS;
 
   if (not attributes()->empty()) {
-    int flag;
-    void* value_out;
+    int flag=0;
+    void* value_out=nullptr;
     for (auto const& it : *attributes()) {
       smpi_key_elem elem = keyvals_.at(it.first);
     for (auto const& it : *attributes()) {
       smpi_key_elem elem = keyvals_.at(it.first);
-      if (elem != nullptr && elem->copy_fn.comm_copy_fn != MPI_NULL_COPY_FN) {
-        ret = elem->copy_fn.comm_copy_fn(this, it.first, nullptr, it.second, &value_out, &flag);
+      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 (ret != MPI_SUCCESS) {
           Comm::destroy(*newcomm);
           *newcomm = MPI_COMM_NULL;
           return ret;
         }
-        if (flag){
+        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});
         }
           elem->refcount++;
           (*newcomm)->attributes()->insert({it.first, value_out});
         }
index 5136911..c9b75ab 100644 (file)
@@ -128,21 +128,31 @@ Datatype::Datatype(Datatype *datatype, int* ret) : name_(nullptr), lb_(datatype-
   *ret = MPI_SUCCESS;
   if(datatype->name_)
     name_ = xbt_strdup(datatype->name_);
   *ret = MPI_SUCCESS;
   if(datatype->name_)
     name_ = xbt_strdup(datatype->name_);
-
+    
   if (not datatype->attributes()->empty()) {
   if (not datatype->attributes()->empty()) {
-    int flag;
+    int flag=0;
     void* value_out;
     void* value_out;
-    for(auto it = datatype->attributes()->begin(); it != datatype->attributes()->end(); it++){
-      smpi_key_elem elem = keyvals_.at((*it).first);
-
-      if (elem != nullptr && elem->copy_fn.type_copy_fn != MPI_NULL_COPY_FN) {
-        *ret = elem->copy_fn.type_copy_fn(datatype, (*it).first, nullptr, (*it).second, &value_out, &flag);
+    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 (*ret != MPI_SUCCESS) {
           break;
         }
-        if (flag){
+        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++;
           elem->refcount++;
-          attributes()->insert({(*it).first, value_out});
+          attributes()->insert({it.first, value_out});
         }
       }
     }
         }
       }
     }
index 47728de..35b82ff 100644 (file)
@@ -16,30 +16,30 @@ std::unordered_map<int, void*>* Keyval::attributes(){
 
 
 template <> int Keyval::call_deleter<Comm>(Comm* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
 
 
 template <> int Keyval::call_deleter<Comm>(Comm* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
-  if(elem->delete_fn.comm_delete_fn!=MPI_NULL_DELETE_FN){
-    int ret = elem->delete_fn.comm_delete_fn(obj, keyval, value, flag);
-    if(ret!=MPI_SUCCESS)
-      return ret;
-  }
-  return MPI_SUCCESS;
+  int ret = MPI_SUCCESS;
+  if(elem->delete_fn.comm_delete_fn!=MPI_NULL_DELETE_FN)
+    ret = elem->delete_fn.comm_delete_fn(obj, keyval, value, elem->extra_state);
+  else if(elem->delete_fn.comm_delete_fn_fort!=MPI_NULL_DELETE_FN)
+    elem->delete_fn.comm_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret);
+  return ret;
 }
 
 template <> int Keyval::call_deleter<Win>(Win* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
 }
 
 template <> int Keyval::call_deleter<Win>(Win* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
-  if(elem->delete_fn.win_delete_fn!=MPI_NULL_DELETE_FN){
-    int ret = elem->delete_fn.win_delete_fn(obj, keyval, value, flag);
-    if(ret!=MPI_SUCCESS)
-      return ret;
-  }
-  return MPI_SUCCESS;
+  int ret = MPI_SUCCESS;
+  if(elem->delete_fn.win_delete_fn!=MPI_NULL_DELETE_FN)
+    ret = elem->delete_fn.win_delete_fn(obj, keyval, value, elem->extra_state);
+  else if(elem->delete_fn.win_delete_fn_fort!=MPI_NULL_DELETE_FN)
+    elem->delete_fn.win_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret);
+  return ret;
 }
 
 template <> int Keyval::call_deleter<Datatype>(Datatype* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
 }
 
 template <> int Keyval::call_deleter<Datatype>(Datatype* obj, smpi_key_elem elem, int keyval, void * value, int* flag){
-  if(elem->delete_fn.type_delete_fn!=MPI_NULL_DELETE_FN){
-    int ret = elem->delete_fn.type_delete_fn(obj, keyval, value, flag);
-    if(ret!=MPI_SUCCESS)
-      return ret;
-  }
-  return MPI_SUCCESS;
+  int ret = MPI_SUCCESS;
+  if(elem->delete_fn.type_delete_fn!=MPI_NULL_DELETE_FN)
+    ret = elem->delete_fn.type_delete_fn(obj, keyval, value, elem->extra_state);
+  else if(elem->delete_fn.type_delete_fn_fort!=MPI_NULL_DELETE_FN)
+    elem->delete_fn.type_delete_fn_fort(obj, keyval, value, elem->extra_state, &ret);
+  return ret;
 }
 
 }
 }
 
 }