Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
More template based factorization
authordegomme <augustin.degomme@unibas.ch>
Wed, 15 Mar 2017 22:57:35 +0000 (23:57 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Wed, 15 Mar 2017 22:58:19 +0000 (23:58 +0100)
src/smpi/smpi_comm.cpp
src/smpi/smpi_comm.hpp
src/smpi/smpi_datatype.cpp
src/smpi/smpi_global.cpp
src/smpi/smpi_keyvals.hpp
src/smpi/smpi_win.cpp

index 98e0599..d5e043e 100644 (file)
@@ -279,21 +279,6 @@ void Comm::ref(){
   refcount_++;
 }
 
-void Comm::cleanup_attributes(){
-  if(!attributes_.empty()){
-    int flag;
-    for(auto it = attributes_.begin(); it != attributes_.end(); it++){
-      try{
-        smpi_key_elem elem = keyvals_.at((*it).first);
-        if (elem != nullptr && elem->delete_fn.comm_delete_fn != nullptr)
-          elem->delete_fn.comm_delete_fn(this, (*it).first, (*it).second, &flag);
-      }catch(const std::out_of_range& oor) {
-        //already deleted, not a problem;
-      }
-    }
-  }
-}
-
 void Comm::cleanup_smp(){
   if (intra_comm_ != MPI_COMM_NULL)
     Comm::unref(intra_comm_);
@@ -315,7 +300,7 @@ void Comm::unref(Comm* comm){
 
   if(comm->refcount_==0){
     comm->cleanup_smp();
-    comm->cleanup_attributes();
+    comm->cleanup_attr<Comm>();
     delete comm;
   }
 }
index aedf39e..b98092f 100644 (file)
@@ -56,7 +56,6 @@ class Comm : public F2C, public Keyval{
     int is_uniform();
     int is_blocked();
     MPI_Comm split(int color, int key);
-    void cleanup_attributes();
     void cleanup_smp();
     void ref();
     static void unref(MPI_Comm comm);
index 5d39365..d024277 100644 (file)
@@ -159,18 +159,7 @@ Datatype::~Datatype(){
       return;
   }
 
-  if(!attributes_.empty()){
-    int flag;
-    for(auto it = attributes_.begin(); it != attributes_.end(); it++){
-      try{
-        smpi_key_elem elem = keyvals_.at((*it).first);
-        if (elem != nullptr && elem->delete_fn.type_delete_fn != nullptr)
-          elem->delete_fn.type_delete_fn(this, (*it).first, (*it).second, &flag);
-      }catch(const std::out_of_range& oor) {
-        //already deleted, not a problem;
-      }
-    }
-  }
+  cleanup_attr<Datatype>();
 
   xbt_free(name_);
 }
index 25c4ded..c5b7734 100644 (file)
@@ -634,7 +634,7 @@ void smpi_global_destroy()
 
   if (MPI_COMM_WORLD != MPI_COMM_UNINITIALIZED){
     MPI_COMM_WORLD->cleanup_smp();
-    MPI_COMM_WORLD->cleanup_attributes();
+    MPI_COMM_WORLD->cleanup_attr<Comm>();
     if(Colls::smpi_coll_cleanup_callback!=nullptr)
       Colls::smpi_coll_cleanup_callback();
     delete MPI_COMM_WORLD;
index 0508f33..74c7722 100644 (file)
@@ -47,6 +47,7 @@ class Keyval{
     template <typename T> int attr_get(int keyval, void* attr_value, int* flag);
     template <typename T> int attr_put(int keyval, void* attr_value);
     template <typename T> static int call_deleter(T* obj, smpi_key_elem elem, int keyval, void * value, int* flag);
+    template <typename T> void cleanup_attr();
 };
 
 template <typename T> int Keyval::keyval_create(smpi_copy_fn copy_fn, smpi_delete_fn delete_fn, int* keyval, void* extra_state){
@@ -138,6 +139,22 @@ template <typename T> int Keyval::attr_put(int keyval, void* attr_value){
   return MPI_SUCCESS;
 }
 
+template <typename T> void Keyval::cleanup_attr(){
+  if(!attributes_.empty()){
+    int flag;
+    for(auto it = attributes_.begin(); it != attributes_.end(); it++){
+      try{
+        smpi_key_elem elem = T::keyvals_.at((*it).first);
+        if(elem != nullptr){
+          call_deleter<T>((T*)this, elem, (*it).first,(*it).second,&flag);
+        }
+      }catch(const std::out_of_range& oor) {
+        //already deleted, not a problem;
+      }
+    }
+  }
+}
+
 }
 }
 
index a2c2220..67612c3 100644 (file)
@@ -59,19 +59,7 @@ Win::~Win(){
     MSG_barrier_destroy(bar_);
   xbt_mutex_destroy(mut_);
 
-  if(!attributes_.empty()){
-    int flag;
-    for(auto it = attributes_.begin(); it != attributes_.end(); it++){
-      try{
-        smpi_key_elem elem = keyvals_.at((*it).first);
-        if (elem != nullptr && elem->delete_fn.win_delete_fn != nullptr)
-          elem->delete_fn.win_delete_fn(this, (*it).first, (*it).second, &flag);
-      }catch(const std::out_of_range& oor) {
-        //already deleted, not a problem;
-      }
-    }
-  }
-
+  cleanup_attr<Win>();
 }
 
 void Win::get_name(char* name, int* length){