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_);
if(comm->refcount_==0){
comm->cleanup_smp();
- comm->cleanup_attributes();
+ comm->cleanup_attr<Comm>();
delete comm;
}
}
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);
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_);
}
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;
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){
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;
+ }
+ }
+ }
+}
+
}
}
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){
/* We create some dummy keyvals here in case the same keyval
* is reused */
- for (i = 0; i < 1; i++) {
+ for (i = 0; i < 32; i++) {
MPI_Type_create_keyval(MPI_NULL_COPY_FN, MPI_NULL_DELETE_FN, &key[i], (void *) 0);
}
}
}
/* Free those other keyvals */
- for (i = 0; i < 1; i++) {
+ for (i = 0; i < 32; i++) {
MPI_Type_free_keyval(&key[i]);
}
MTestFreeDatatype(&mrtype);