From: degomme Date: Wed, 15 Mar 2017 22:57:35 +0000 (+0100) Subject: More template based factorization X-Git-Tag: v3_15~96^2 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/f50c785a8f726657dc3b4e32de522a7b3baca707?hp=73a7fe0ba8650c65f6a7712a4e2b6c9057eac6ac;ds=sidebyside More template based factorization --- diff --git a/src/smpi/smpi_comm.cpp b/src/smpi/smpi_comm.cpp index 98e0599011..d5e043e922 100644 --- a/src/smpi/smpi_comm.cpp +++ b/src/smpi/smpi_comm.cpp @@ -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(); delete comm; } } diff --git a/src/smpi/smpi_comm.hpp b/src/smpi/smpi_comm.hpp index aedf39e845..b98092fc99 100644 --- a/src/smpi/smpi_comm.hpp +++ b/src/smpi/smpi_comm.hpp @@ -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); diff --git a/src/smpi/smpi_datatype.cpp b/src/smpi/smpi_datatype.cpp index 5d39365f41..d024277f18 100644 --- a/src/smpi/smpi_datatype.cpp +++ b/src/smpi/smpi_datatype.cpp @@ -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(); xbt_free(name_); } diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 25c4deddd4..c5b7734db1 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -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(); if(Colls::smpi_coll_cleanup_callback!=nullptr) Colls::smpi_coll_cleanup_callback(); delete MPI_COMM_WORLD; diff --git a/src/smpi/smpi_keyvals.hpp b/src/smpi/smpi_keyvals.hpp index 0508f33392..74c7722e9a 100644 --- a/src/smpi/smpi_keyvals.hpp +++ b/src/smpi/smpi_keyvals.hpp @@ -47,6 +47,7 @@ class Keyval{ template int attr_get(int keyval, void* attr_value, int* flag); template int attr_put(int keyval, void* attr_value); template static int call_deleter(T* obj, smpi_key_elem elem, int keyval, void * value, int* flag); + template void cleanup_attr(); }; template int Keyval::keyval_create(smpi_copy_fn copy_fn, smpi_delete_fn delete_fn, int* keyval, void* extra_state){ @@ -138,6 +139,22 @@ template int Keyval::attr_put(int keyval, void* attr_value){ return MPI_SUCCESS; } +template 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*)this, elem, (*it).first,(*it).second,&flag); + } + }catch(const std::out_of_range& oor) { + //already deleted, not a problem; + } + } + } +} + } } diff --git a/src/smpi/smpi_win.cpp b/src/smpi/smpi_win.cpp index a2c2220a3e..67612c3be2 100644 --- a/src/smpi/smpi_win.cpp +++ b/src/smpi/smpi_win.cpp @@ -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(); } void Win::get_name(char* name, int* length){