From 5eb856761d5f073b07eac25c05012cfa8075e1f1 Mon Sep 17 00:00:00 2001 From: degomme Date: Wed, 15 Mar 2017 00:11:44 +0100 Subject: [PATCH] Some cleanups, some smells --- include/smpi/forward.hpp | 22 +----- include/smpi/smpi.h | 14 ++-- src/smpi/colls/allgather/allgather-GB.cpp | 2 - .../colls/allgather/allgather-mvapich-smp.cpp | 2 - src/smpi/colls/allreduce/allreduce-rab1.cpp | 1 - src/smpi/colls/allreduce/allreduce-rab2.cpp | 1 - .../colls/smpi_mvapich2_selector_stampede.h | 1 - src/smpi/private.h | 14 ---- src/smpi/smpi_coll.hpp | 62 +--------------- src/smpi/smpi_comm.cpp | 70 ++++++++++--------- src/smpi/smpi_comm.hpp | 16 ++++- src/smpi/smpi_datatype.cpp | 27 ++++--- src/smpi/smpi_datatype.hpp | 11 +++ src/smpi/smpi_global.cpp | 4 +- src/smpi/smpi_group.cpp | 4 +- src/smpi/smpi_pmpi.cpp | 4 +- src/smpi/smpi_request.cpp | 14 ++-- src/smpi/smpi_topo.hpp | 2 + 18 files changed, 98 insertions(+), 173 deletions(-) diff --git a/include/smpi/forward.hpp b/include/smpi/forward.hpp index c1a210ccf8..eb150705dd 100644 --- a/include/smpi/forward.hpp +++ b/include/smpi/forward.hpp @@ -24,15 +24,10 @@ class Topo; class Topo_Cart; class Topo_Graph; class Topo_Dist_Graph; -class Type_Contiguous; -class Type_Hindexed; -class Type_Hvector; -class Type_Indexed; -class Type_Struct; -class Type_Vector; class Win; class Colls; +class Coll; } } @@ -48,12 +43,6 @@ typedef simgrid::smpi::Topo_Cart SMPI_Cart_topology; typedef simgrid::smpi::Topo_Dist_Graph SMPI_Dist_Graph_topology; typedef simgrid::smpi::Topo_Graph SMPI_Graph_topology; typedef simgrid::smpi::Win SMPI_Win; -typedef simgrid::smpi::Type_Contiguous SMPI_Type_Contiguous; -typedef simgrid::smpi::Type_Hindexed SMPI_Type_Hindexed; -typedef simgrid::smpi::Type_Hvector SMPI_Type_Hvector; -typedef simgrid::smpi::Type_Indexed SMPI_Type_Indexed; -typedef simgrid::smpi::Type_Struct SMPI_Type_Struct; -typedef simgrid::smpi::Type_Vector SMPI_Type_Vector; #else @@ -65,15 +54,6 @@ typedef struct SMPI_Op SMPI_Op; typedef struct SMPI_Request SMPI_Request; typedef struct SMPI_Topology SMPI_Topology; typedef struct SMPI_Win SMPI_Win; -typedef struct SMPI_Graph_topology SMPI_Graph_topology; -typedef struct SMPI_Cart_topology SMPI_Cart_topology; -typedef struct SMPI_Dist_Graph_topology SMPI_Dist_Graph_topology; -typedef struct SMPI_Type_Contiguous SMPI_Type_Contiguous; -typedef struct SMPI_Type_Hindexed SMPI_Type_Hindexed; -typedef struct SMPI_Type_Hvector SMPI_Type_Hvector; -typedef struct SMPI_Type_Indexed SMPI_Type_Indexed; -typedef struct SMPI_Type_Struct SMPI_Type_Struct; -typedef struct SMPI_Type_Vector SMPI_Type_Vector; #endif diff --git a/include/smpi/smpi.h b/include/smpi/smpi.h index dd0942760c..9968368320 100644 --- a/include/smpi/smpi.h +++ b/include/smpi/smpi.h @@ -313,13 +313,13 @@ XBT_PUBLIC_DATA( const MPI_Datatype ) MPI_INTEGER16; //defines for fortran compatibility #if defined(__alpha__) || defined(__sparc64__) || defined(__x86_64__) || defined(__ia64__) - #define MPI_INTEGER MPI_INT - #define MPI_2INTEGER MPI_2INT - #define MPI_LOGICAL MPI_INT +#define MPI_INTEGER MPI_INT +#define MPI_2INTEGER MPI_2INT +#define MPI_LOGICAL MPI_INT #else - #define MPI_INTEGER MPI_LONG - #define MPI_2INTEGER MPI_2LONG - #define MPI_LOGICAL MPI_LONG +#define MPI_INTEGER MPI_LONG +#define MPI_2INTEGER MPI_2LONG +#define MPI_LOGICAL MPI_LONG #endif #define MPI_Fint int @@ -354,8 +354,6 @@ XBT_PUBLIC_DATA( MPI_Op ) MPI_BXOR; //For accumulate XBT_PUBLIC_DATA( MPI_Op ) MPI_REPLACE; -typedef SMPI_Topology *MPI_Topology; - typedef SMPI_Group* MPI_Group; #define MPI_GROUP_NULL ((MPI_Group)NULL) diff --git a/src/smpi/colls/allgather/allgather-GB.cpp b/src/smpi/colls/allgather/allgather-GB.cpp index f50e07f9fa..88bc100e85 100644 --- a/src/smpi/colls/allgather/allgather-GB.cpp +++ b/src/smpi/colls/allgather/allgather-GB.cpp @@ -6,8 +6,6 @@ #include "../colls_private.h" -using namespace simgrid::smpi; - // Allgather - gather/bcast algorithm int Coll_allgather_GB::allgather(void *send_buff, int send_count, MPI_Datatype send_type, void *recv_buff, diff --git a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp index 9c5f5b1b80..1a0fdcb623 100644 --- a/src/smpi/colls/allgather/allgather-mvapich-smp.cpp +++ b/src/smpi/colls/allgather/allgather-mvapich-smp.cpp @@ -36,8 +36,6 @@ */ #include "../colls_private.h" -using namespace simgrid::smpi; - int Coll_allgather_mvapich2_smp::allgather(void *sendbuf,int sendcnt, MPI_Datatype sendtype, void *recvbuf, int recvcnt,MPI_Datatype recvtype, MPI_Comm comm) diff --git a/src/smpi/colls/allreduce/allreduce-rab1.cpp b/src/smpi/colls/allreduce/allreduce-rab1.cpp index 120abebf46..3e255ba57a 100644 --- a/src/smpi/colls/allreduce/allreduce-rab1.cpp +++ b/src/smpi/colls/allreduce/allreduce-rab1.cpp @@ -6,7 +6,6 @@ #include "../colls_private.h" //#include -using namespace simgrid::smpi; // NP pow of 2 for now int Coll_allreduce_rab1::allreduce(void *sbuff, void *rbuff, diff --git a/src/smpi/colls/allreduce/allreduce-rab2.cpp b/src/smpi/colls/allreduce/allreduce-rab2.cpp index ac1e98f505..62f8d9794e 100644 --- a/src/smpi/colls/allreduce/allreduce-rab2.cpp +++ b/src/smpi/colls/allreduce/allreduce-rab2.cpp @@ -6,7 +6,6 @@ #include "../colls_private.h" //#include -using namespace simgrid::smpi; // this requires that count >= NP int Coll_allreduce_rab2::allreduce(void *sbuff, void *rbuff, diff --git a/src/smpi/colls/smpi_mvapich2_selector_stampede.h b/src/smpi/colls/smpi_mvapich2_selector_stampede.h index a2296bfb7f..1b9560195c 100644 --- a/src/smpi/colls/smpi_mvapich2_selector_stampede.h +++ b/src/smpi/colls/smpi_mvapich2_selector_stampede.h @@ -10,7 +10,6 @@ #define MV2_MAX_NB_THRESHOLDS 32 -using namespace simgrid::smpi; XBT_PUBLIC(void) smpi_coll_cleanup_mvapich2(void); diff --git a/src/smpi/private.h b/src/smpi/private.h index ed5438679f..e2376b8a55 100644 --- a/src/smpi/private.h +++ b/src/smpi/private.h @@ -68,20 +68,6 @@ enum smpi_process_state{ extern XBT_PRIVATE MPI_Comm MPI_COMM_UNINITIALIZED; - - -typedef struct s_smpi_mpi_comm_key_elem { - MPI_Comm_copy_attr_function* copy_fn; - MPI_Comm_delete_attr_function* delete_fn; -} s_smpi_mpi_comm_key_elem_t; -typedef struct s_smpi_mpi_comm_key_elem *smpi_comm_key_elem; - -typedef struct s_smpi_mpi_type_key_elem { - MPI_Type_copy_attr_function* copy_fn; - MPI_Type_delete_attr_function* delete_fn; -} s_smpi_mpi_type_key_elem_t; -typedef struct s_smpi_mpi_type_key_elem *smpi_type_key_elem; - XBT_PRIVATE void smpi_process_destroy(); XBT_PRIVATE void smpi_process_finalize(); XBT_PRIVATE int smpi_process_finalized(); diff --git a/src/smpi/smpi_coll.hpp b/src/smpi/smpi_coll.hpp index 1326935d34..8d67a30b38 100644 --- a/src/smpi/smpi_coll.hpp +++ b/src/smpi/smpi_coll.hpp @@ -81,76 +81,18 @@ class Colls{ static void (*smpi_coll_cleanup_callback)(); }; -class Coll_algo{ - private: - char* description_; - public: - char* description(); -}; - -class Coll_gather : public Coll_algo { - private: +class Coll { public: static int gather (void *, int, MPI_Datatype, void*, int, MPI_Datatype, int root, MPI_Comm); -}; - -class Coll_allgather : public Coll_algo { - private: - public: static int allgather (void *, int, MPI_Datatype, void*, int, MPI_Datatype, MPI_Comm); -}; - -class Coll_allgatherv : public Coll_algo { - private: - public: static int allgatherv (void *, int, MPI_Datatype, void*, int*, int*, MPI_Datatype, MPI_Comm); -}; - -class Coll_allreduce : public Coll_algo { - private: - public: static int allreduce (void *sbuf, void *rbuf, int rcount, MPI_Datatype dtype, MPI_Op op, MPI_Comm comm); -}; - -class Coll_alltoall : public Coll_algo { - private: - public: static int alltoall (void *, int, MPI_Datatype, void*, int, MPI_Datatype, MPI_Comm); -}; - -class Coll_alltoallv : public Coll_algo { - private: - public: static int alltoallv (void *, int*, int*, MPI_Datatype, void*, int*, int*, MPI_Datatype, MPI_Comm); -}; - -class Coll_bcast : public Coll_algo { - private: - public: static int bcast (void *buf, int count, MPI_Datatype datatype, int root, MPI_Comm com); -}; - -class Coll_reduce : public Coll_algo { - private: - public: static int reduce (void *buf, void *rbuf, int count, MPI_Datatype datatype, MPI_Op op, int root, MPI_Comm comm); -}; - -class Coll_reduce_scatter : public Coll_algo { - private: - public: static int reduce_scatter (void *sbuf, void *rbuf, int *rcounts,MPI_Datatype dtype,MPI_Op op,MPI_Comm comm); -}; - -class Coll_scatter : public Coll_algo { - private: - public: static int scatter (void *sendbuf, int sendcount, MPI_Datatype sendtype,void *recvbuf, int recvcount, MPI_Datatype recvtype,int root, MPI_Comm comm); -}; - -class Coll_barrier : public Coll_algo { - private: - public: static int barrier (MPI_Comm); }; @@ -162,7 +104,7 @@ class Coll_barrier : public Coll_algo { (void*) Coll_ ## cat ## _ ## name::cat } #define COLL_PROTO(cat, ret, args, name) \ -class Coll_ ## cat ## _ ## name : public Coll_ ## cat { \ +class Coll_ ## cat ## _ ## name : public Coll { \ public: \ static ret cat (COLL_UNPAREN args); \ }; diff --git a/src/smpi/smpi_comm.cpp b/src/smpi/smpi_comm.cpp index bbf41ec502..8ea2304215 100644 --- a/src/smpi/smpi_comm.cpp +++ b/src/smpi/smpi_comm.cpp @@ -18,10 +18,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, "Logging specific to SMPI (comm)"); -xbt_dict_t smpi_comm_keyvals = nullptr; -int comm_keyval_id = 0;//avoid collisions - - Comm mpi_MPI_COMM_UNINITIALIZED; MPI_Comm MPI_COMM_UNINITIALIZED=&mpi_MPI_COMM_UNINITIALIZED; @@ -51,7 +47,8 @@ static int smpi_compare_rankmap(const void *a, const void *b) namespace simgrid{ namespace smpi{ -Comm::Comm(){} +xbt_dict_t Comm::keyvals_ = nullptr; +int Comm::keyval_id_ = 0;//avoid collisions Comm::Comm(MPI_Group group, MPI_Topology topo) : group_(group), topo_(topo) { @@ -93,7 +90,7 @@ int Comm::dup(MPI_Comm* newcomm){ void* value_out; xbt_dict_foreach (attributes_, cursor, key, value_in) { smpi_comm_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_comm_keyvals, key, sizeof(int))); + static_cast(xbt_dict_get_or_null_ext(keyvals_, key, sizeof(int))); if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) { ret = elem->copy_fn(this, atoi(key), nullptr, value_in, &value_out, &flag); if (ret != MPI_SUCCESS) { @@ -294,7 +291,7 @@ void Comm::cleanup_attributes(){ void* value; int flag; xbt_dict_foreach (attributes_, cursor, key, value) { - smpi_comm_key_elem elem = static_cast(xbt_dict_get_or_null(smpi_comm_keyvals, key)); + smpi_comm_key_elem elem = static_cast(xbt_dict_get_or_null(keyvals_, key)); if (elem != nullptr && elem->delete_fn != nullptr) elem->delete_fn(this, atoi(key), value, &flag); } @@ -501,7 +498,7 @@ void Comm::init_smp(){ int Comm::attr_delete(int keyval){ smpi_comm_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(&keyval), sizeof(int))); + static_cast(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast(&keyval), sizeof(int))); if(elem==nullptr) return MPI_ERR_ARG; if(elem->delete_fn!=MPI_NULL_DELETE_FN){ @@ -522,7 +519,7 @@ int Comm::attr_delete(int keyval){ int Comm::attr_get(int keyval, void* attr_value, int* flag){ smpi_comm_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(&keyval), sizeof(int))); + static_cast(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast(&keyval), sizeof(int))); if(elem==nullptr) return MPI_ERR_ARG; if(attributes_==nullptr){ @@ -541,10 +538,10 @@ int Comm::attr_get(int keyval, void* attr_value, int* flag){ } int Comm::attr_put(int keyval, void* attr_value){ - if(smpi_comm_keyvals==nullptr) - smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr); + if(keyvals_==nullptr) + keyvals_ = xbt_dict_new_homogeneous(nullptr); smpi_comm_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(&keyval), sizeof(int))); + static_cast(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast(&keyval), sizeof(int))); if(elem==nullptr) return MPI_ERR_ARG; int flag; @@ -567,9 +564,9 @@ MPI_Comm Comm::f2c(int id) { return MPI_COMM_SELF; } else if(id==0){ return MPI_COMM_WORLD; - } else if(Comm::f2c_lookup_ != nullptr && id >= 0) { + } else if(F2C::f2c_lookup_ != nullptr && id >= 0) { char key[KEY_SIZE]; - MPI_Comm tmp = static_cast(xbt_dict_get_or_null(Comm::f2c_lookup_,get_key_id(key, id))); + MPI_Comm tmp = static_cast(xbt_dict_get_or_null(F2C::f2c_lookup_,get_key_id(key, id))); return tmp != nullptr ? tmp : MPI_COMM_NULL ; } else { return MPI_COMM_NULL; @@ -578,45 +575,52 @@ MPI_Comm Comm::f2c(int id) { void Comm::free_f(int id) { char key[KEY_SIZE]; - xbt_dict_remove(Comm::f2c_lookup_, id==0? get_key(key, id) : get_key_id(key, id)); + xbt_dict_remove(F2C::f2c_lookup_, id==0? get_key(key, id) : get_key_id(key, id)); } int Comm::add_f() { - if(Comm::f2c_lookup_==nullptr){ - Comm::f2c_lookup_=xbt_dict_new_homogeneous(nullptr); + if(F2C::f2c_lookup_==nullptr){ + F2C::f2c_lookup_=xbt_dict_new_homogeneous(nullptr); } char key[KEY_SIZE]; - xbt_dict_set(Comm::f2c_lookup_, this==MPI_COMM_WORLD? get_key(key, Comm::f2c_id_) : get_key_id(key,Comm::f2c_id_), this, nullptr); - Comm::f2c_id_++; - return Comm::f2c_id_-1; + xbt_dict_set(F2C::f2c_lookup_, this==MPI_COMM_WORLD? get_key(key, F2C::f2c_id_) : get_key_id(key,F2C::f2c_id_), this, nullptr); + F2C::f2c_id_++; + return F2C::f2c_id_-1; } - -} -} - -int smpi_comm_keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, +int Comm::keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state){ - if(smpi_comm_keyvals==nullptr) - smpi_comm_keyvals = xbt_dict_new_homogeneous(nullptr); + if(keyvals_==nullptr) + keyvals_ = xbt_dict_new_homogeneous(nullptr); smpi_comm_key_elem value = static_cast(xbt_new0(s_smpi_mpi_comm_key_elem_t,1)); value->copy_fn=copy_fn; value->delete_fn=delete_fn; - *keyval = comm_keyval_id; - xbt_dict_set_ext(smpi_comm_keyvals, reinterpret_cast(keyval), sizeof(int),static_cast(value), nullptr); - comm_keyval_id++; + *keyval = keyval_id_; + xbt_dict_set_ext(keyvals_, reinterpret_cast(keyval), sizeof(int),static_cast(value), nullptr); + keyval_id_++; return MPI_SUCCESS; } -int smpi_comm_keyval_free(int* keyval){ +int Comm::keyval_free(int* keyval){ smpi_comm_key_elem elem = - static_cast(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast(keyval), sizeof(int))); + static_cast(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast(keyval), sizeof(int))); if(elem==nullptr) return MPI_ERR_ARG; - xbt_dict_remove_ext(smpi_comm_keyvals, reinterpret_cast(keyval), sizeof(int)); + xbt_dict_remove_ext(keyvals_, reinterpret_cast(keyval), sizeof(int)); xbt_free(elem); return MPI_SUCCESS; } + +void Comm::keyval_cleanup(){ + if(Comm::keyvals_!=nullptr) + xbt_dict_free(&Comm::keyvals_); +} + + +} +} + + diff --git a/src/smpi/smpi_comm.hpp b/src/smpi/smpi_comm.hpp index ee313dcdde..4c2ead02c7 100644 --- a/src/smpi/smpi_comm.hpp +++ b/src/smpi/smpi_comm.hpp @@ -9,6 +9,13 @@ #include "private.h" + +typedef struct s_smpi_mpi_comm_key_elem { + MPI_Comm_copy_attr_function* copy_fn; + MPI_Comm_delete_attr_function* delete_fn; +} s_smpi_mpi_comm_key_elem_t; +typedef struct s_smpi_mpi_comm_key_elem *smpi_comm_key_elem; + namespace simgrid{ namespace smpi{ @@ -28,8 +35,11 @@ class Comm : public F2C{ int is_blocked_;// are ranks allocated on the same smp node contiguous ? xbt_dict_t attributes_; + static xbt_dict_t keyvals_; + static int keyval_id_; + public: - Comm(); + Comm() = default; Comm(MPI_Group group, MPI_Topology topo); @@ -62,6 +72,10 @@ class Comm : public F2C{ static void free_f(int id); static Comm* f2c(int); + static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval, void* extra_state); + static int keyval_free(int* keyval); + static void keyval_cleanup(); + }; } diff --git a/src/smpi/smpi_datatype.cpp b/src/smpi/smpi_datatype.cpp index 877b40eaf9..c33bd1d170 100644 --- a/src/smpi/smpi_datatype.cpp +++ b/src/smpi/smpi_datatype.cpp @@ -18,10 +18,6 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_datatype, smpi, "Logging specific to SMPI (datatype)"); -std::unordered_map smpi_type_keyvals; -int type_keyval_id=0;//avoid collisions - - #define CREATE_MPI_DATATYPE(name, type) \ static Datatype mpi_##name ( \ (char*) # name, \ @@ -107,7 +103,8 @@ CREATE_MPI_DATATYPE(MPI_PTR, void*); namespace simgrid{ namespace smpi{ -MPI_Datatype Datatype::null_id_=MPI_DATATYPE_NULL; +std::unordered_map Datatype::keyvals_; +int Datatype::keyval_id_=0; Datatype::Datatype(int size,MPI_Aint lb, MPI_Aint ub, int flags) : name_(nullptr), size_(size), lb_(lb), ub_(ub), flags_(flags), attributes_(nullptr), refcount_(1){ #if HAVE_MC @@ -138,7 +135,7 @@ Datatype::Datatype(Datatype *datatype, int* ret) : name_(nullptr), lb_(datatype- void* value_in; void* value_out; xbt_dict_foreach (datatype->attributes_, cursor, key, value_in) { - smpi_type_key_elem elem = smpi_type_keyvals.at(atoi(key)); + smpi_type_key_elem elem = keyvals_.at(atoi(key)); if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) { *ret = elem->copy_fn(datatype, atoi(key), nullptr, value_in, &value_out, &flag); if (*ret != MPI_SUCCESS) { @@ -170,7 +167,7 @@ Datatype::~Datatype(){ void * value; int flag; xbt_dict_foreach(attributes_, cursor, key, value){ - smpi_type_key_elem elem = smpi_type_keyvals.at(atoi(key)); + smpi_type_key_elem elem = keyvals_.at(atoi(key)); if(elem!=nullptr && elem->delete_fn!=nullptr) elem->delete_fn(this,*key, value, &flag); } @@ -262,7 +259,7 @@ void Datatype::set_name(char* name){ } int Datatype::attr_delete(int keyval){ - smpi_type_key_elem elem = smpi_type_keyvals.at(keyval); + smpi_type_key_elem elem = keyvals_.at(keyval); if(elem==nullptr) return MPI_ERR_ARG; if(elem->delete_fn!=MPI_NULL_DELETE_FN){ @@ -283,7 +280,7 @@ int Datatype::attr_delete(int keyval){ int Datatype::attr_get(int keyval, void* attr_value, int* flag){ - smpi_type_key_elem elem = smpi_type_keyvals.at(keyval); + smpi_type_key_elem elem = keyvals_.at(keyval); if(elem==nullptr) return MPI_ERR_ARG; if(attributes_==nullptr){ @@ -301,7 +298,7 @@ int Datatype::attr_get(int keyval, void* attr_value, int* flag){ } int Datatype::attr_put(int keyval, void* attr_value){ - smpi_type_key_elem elem = smpi_type_keyvals.at(keyval); + smpi_type_key_elem elem = keyvals_.at(keyval); if(elem==nullptr) return MPI_ERR_ARG; int flag; @@ -326,18 +323,18 @@ int Datatype::keyval_create(MPI_Type_copy_attr_function* copy_fn, MPI_Type_delet value->copy_fn=copy_fn; value->delete_fn=delete_fn; - *keyval = type_keyval_id; - smpi_type_keyvals.insert({*keyval, value}); - type_keyval_id++; + *keyval = keyval_id_; + keyvals_.insert({*keyval, value}); + keyval_id_++; return MPI_SUCCESS; } int Datatype::keyval_free(int* keyval){ - smpi_type_key_elem elem = smpi_type_keyvals.at(*keyval); + smpi_type_key_elem elem = keyvals_.at(*keyval); if(elem==0){ return MPI_ERR_ARG; } - smpi_type_keyvals.erase(*keyval); + keyvals_.erase(*keyval); xbt_free(elem); return MPI_SUCCESS; } diff --git a/src/smpi/smpi_datatype.hpp b/src/smpi/smpi_datatype.hpp index dc5ea855bd..1cec8fb33d 100644 --- a/src/smpi/smpi_datatype.hpp +++ b/src/smpi/smpi_datatype.hpp @@ -10,6 +10,7 @@ #include #include "private.h" +#include #define DT_FLAG_DESTROYED 0x0001 /**< user destroyed but some other layers still have a reference */ #define DT_FLAG_COMMITED 0x0002 /**< ready to be used for a send/recv operation */ @@ -31,6 +32,12 @@ extern const MPI_Datatype MPI_PTR; +typedef struct s_smpi_mpi_type_key_elem { + MPI_Type_copy_attr_function* copy_fn; + MPI_Type_delete_attr_function* delete_fn; +} s_smpi_mpi_type_key_elem_t; +typedef struct s_smpi_mpi_type_key_elem *smpi_type_key_elem; + //The following are datatypes for the MPI functions MPI_MAXLOC and MPI_MINLOC. typedef struct { float value; @@ -86,6 +93,10 @@ class Datatype : public F2C{ int flags_; xbt_dict_t attributes_; int refcount_; + + static std::unordered_map keyvals_; + static int keyval_id_; + public: static MPI_Datatype null_id_; diff --git a/src/smpi/smpi_global.cpp b/src/smpi/smpi_global.cpp index 27f0e87766..aa83bc2137 100644 --- a/src/smpi/smpi_global.cpp +++ b/src/smpi/smpi_global.cpp @@ -73,7 +73,6 @@ int process_count = 0; int smpi_universe_size = 0; int* index_to_process_data = nullptr; extern double smpi_total_benched_time; -extern xbt_dict_t smpi_comm_keyvals; xbt_os_timer_t global_timer; MPI_Comm MPI_COMM_WORLD = MPI_COMM_UNINITIALIZED; MPI_Errhandler *MPI_ERRORS_RETURN = nullptr; @@ -648,8 +647,7 @@ void smpi_global_destroy() } xbt_free(index_to_process_data); - if(smpi_comm_keyvals!=nullptr) - xbt_dict_free(&smpi_comm_keyvals); + Comm::keyval_cleanup(); if(smpi_privatize_global_variables) smpi_destroy_global_memory_segments(); smpi_free_static(); diff --git a/src/smpi/smpi_group.cpp b/src/smpi/smpi_group.cpp index c5bcb02620..fd78c2c86d 100644 --- a/src/smpi/smpi_group.cpp +++ b/src/smpi/smpi_group.cpp @@ -382,9 +382,9 @@ int Group::range_excl(int n, int ranges[][3], MPI_Group * newgroup){ MPI_Group Group::f2c(int id) { if(id == -2) { return MPI_GROUP_EMPTY; - } else if(f2c_lookup_ != nullptr && id >= 0) { + } else if(F2C::f2c_lookup_ != nullptr && id >= 0) { char key[KEY_SIZE]; - return static_cast(xbt_dict_get_or_null(f2c_lookup_, get_key(key, id))); + return static_cast(xbt_dict_get_or_null(F2C::f2c_lookup_, get_key(key, id))); } else { return static_cast(MPI_GROUP_NULL); } diff --git a/src/smpi/smpi_pmpi.cpp b/src/smpi/smpi_pmpi.cpp index 853c980c3b..6bd1b8af3f 100644 --- a/src/smpi/smpi_pmpi.cpp +++ b/src/smpi/smpi_pmpi.cpp @@ -2772,11 +2772,11 @@ MPI_Fint PMPI_Info_c2f(MPI_Info info){ } int PMPI_Keyval_create(MPI_Copy_function* copy_fn, MPI_Delete_function* delete_fn, int* keyval, void* extra_state) { - return smpi_comm_keyval_create(copy_fn, delete_fn, keyval, extra_state); + return Comm::keyval_create(copy_fn, delete_fn, keyval, extra_state); } int PMPI_Keyval_free(int* keyval) { - return smpi_comm_keyval_free(keyval); + return Comm::keyval_free(keyval); } int PMPI_Attr_delete(MPI_Comm comm, int keyval) { diff --git a/src/smpi/smpi_request.cpp b/src/smpi/smpi_request.cpp index 46012d70f6..85f55b60aa 100644 --- a/src/smpi/smpi_request.cpp +++ b/src/smpi/smpi_request.cpp @@ -1004,23 +1004,23 @@ MPI_Request Request::f2c(int id) { char key[KEY_SIZE]; if(id==MPI_FORTRAN_REQUEST_NULL) return static_cast(MPI_REQUEST_NULL); - return static_cast(xbt_dict_get(Request::f2c_lookup_, get_key_id(key, id))); + return static_cast(xbt_dict_get(F2C::f2c_lookup_, get_key_id(key, id))); } int Request::add_f() { - if(Request::f2c_lookup_==nullptr){ - Request::f2c_lookup_=xbt_dict_new_homogeneous(nullptr); + if(F2C::f2c_lookup_==nullptr){ + F2C::f2c_lookup_=xbt_dict_new_homogeneous(nullptr); } char key[KEY_SIZE]; - xbt_dict_set(Request::f2c_lookup_, get_key_id(key, Request::f2c_id_), this, nullptr); - Request::f2c_id_++; - return Request::f2c_id_-1; + xbt_dict_set(F2C::f2c_lookup_, get_key_id(key, F2C::f2c_id_), this, nullptr); + F2C::f2c_id_++; + return F2C::f2c_id_-1; } void Request::free_f(int id) { char key[KEY_SIZE]; if(id!=MPI_FORTRAN_REQUEST_NULL) - xbt_dict_remove(Request::f2c_lookup_, get_key_id(key, id)); + xbt_dict_remove(F2C::f2c_lookup_, get_key_id(key, id)); } diff --git a/src/smpi/smpi_topo.hpp b/src/smpi/smpi_topo.hpp index 472b927e1c..007e01bc18 100644 --- a/src/smpi/smpi_topo.hpp +++ b/src/smpi/smpi_topo.hpp @@ -16,6 +16,8 @@ typedef enum MPIR_Topo_type { MPI_INVALID_TOPO=-1 } MPIR_Topo_type; +typedef SMPI_Topology *MPI_Topology; + namespace simgrid{ namespace smpi{ -- 2.20.1