Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Some cleanups, some smells
authordegomme <augustin.degomme@unibas.ch>
Tue, 14 Mar 2017 23:11:44 +0000 (00:11 +0100)
committerdegomme <augustin.degomme@unibas.ch>
Tue, 14 Mar 2017 23:25:11 +0000 (00:25 +0100)
18 files changed:
include/smpi/forward.hpp
include/smpi/smpi.h
src/smpi/colls/allgather/allgather-GB.cpp
src/smpi/colls/allgather/allgather-mvapich-smp.cpp
src/smpi/colls/allreduce/allreduce-rab1.cpp
src/smpi/colls/allreduce/allreduce-rab2.cpp
src/smpi/colls/smpi_mvapich2_selector_stampede.h
src/smpi/private.h
src/smpi/smpi_coll.hpp
src/smpi/smpi_comm.cpp
src/smpi/smpi_comm.hpp
src/smpi/smpi_datatype.cpp
src/smpi/smpi_datatype.hpp
src/smpi/smpi_global.cpp
src/smpi/smpi_group.cpp
src/smpi/smpi_pmpi.cpp
src/smpi/smpi_request.cpp
src/smpi/smpi_topo.hpp

index c1a210c..eb15070 100644 (file)
@@ -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
 
index dd09427..9968368 100644 (file)
@@ -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)
index f50e07f..88bc100 100644 (file)
@@ -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,
index 9c5f5b1..1a0fdcb 100644 (file)
@@ -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)
index 120abeb..3e255ba 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "../colls_private.h"
 //#include <star-reduction.c>
-using namespace simgrid::smpi;
 
 // NP pow of 2 for now
 int Coll_allreduce_rab1::allreduce(void *sbuff, void *rbuff,
index ac1e98f..62f8d97 100644 (file)
@@ -6,7 +6,6 @@
 
 #include "../colls_private.h"
 //#include <star-reduction.c>
-using namespace simgrid::smpi;
 
 // this requires that count >= NP
 int Coll_allreduce_rab2::allreduce(void *sbuff, void *rbuff,
index a2296bf..1b95601 100644 (file)
@@ -10,7 +10,6 @@
 
 #define MV2_MAX_NB_THRESHOLDS  32
 
-using namespace simgrid::smpi;
 
 XBT_PUBLIC(void) smpi_coll_cleanup_mvapich2(void);
 
index ed54386..e2376b8 100644 (file)
@@ -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();
index 1326935..8d67a30 100644 (file)
@@ -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); \
 };
index bbf41ec..8ea2304 100644 (file)
 
 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<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, key, sizeof(int)));
+          static_cast<smpi_comm_key_elem>(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<smpi_comm_key_elem>(xbt_dict_get_or_null(smpi_comm_keyvals, key));
+      smpi_comm_key_elem elem = static_cast<smpi_comm_key_elem>(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<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast<const char*>(&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<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
+    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(keyvals_, reinterpret_cast<const char*>(&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<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(&keyval), sizeof(int)));
+    static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(keyvals_,  reinterpret_cast<const char*>(&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<MPI_Comm>(xbt_dict_get_or_null(Comm::f2c_lookup_,get_key_id(key, id)));
+      MPI_Comm tmp =  static_cast<MPI_Comm>(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<smpi_comm_key_elem>(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<const char*>(keyval), sizeof(int),static_cast<void*>(value), nullptr);
-  comm_keyval_id++;
+  *keyval = keyval_id_;
+  xbt_dict_set_ext(keyvals_, reinterpret_cast<const char*>(keyval), sizeof(int),static_cast<void*>(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<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int)));
+     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(keyvals_,  reinterpret_cast<const char*>(keyval), sizeof(int)));
   if(elem==nullptr)
     return MPI_ERR_ARG;
-  xbt_dict_remove_ext(smpi_comm_keyvals,  reinterpret_cast<const char*>(keyval), sizeof(int));
+  xbt_dict_remove_ext(keyvals_,  reinterpret_cast<const char*>(keyval), sizeof(int));
   xbt_free(elem);
   return MPI_SUCCESS;
 }
+
+void Comm::keyval_cleanup(){
+  if(Comm::keyvals_!=nullptr) 
+    xbt_dict_free(&Comm::keyvals_);
+}
+
+
+}
+}
+
+
index ee313dc..4c2ead0 100644 (file)
@@ -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();
+
 };
 
 }
index 877b40e..c33bd1d 100644 (file)
 
 XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_datatype, smpi, "Logging specific to SMPI (datatype)");
 
-std::unordered_map<int, smpi_type_key_elem> 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<int, smpi_type_key_elem> 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;
 }
index dc5ea85..1cec8fb 100644 (file)
@@ -10,6 +10,7 @@
 #include <xbt/base.h>
 
 #include "private.h"
+#include <unordered_map>
 
 #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 */
 
 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<int, smpi_type_key_elem> keyvals_;
+    static int keyval_id_;
+
   public:
     static MPI_Datatype null_id_;
 
index 27f0e87..aa83bc2 100644 (file)
@@ -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();
index c5bcb02..fd78c2c 100644 (file)
@@ -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<MPI_Group>(xbt_dict_get_or_null(f2c_lookup_, get_key(key, id)));
+    return static_cast<MPI_Group>(xbt_dict_get_or_null(F2C::f2c_lookup_, get_key(key, id)));
   } else {
     return static_cast<MPI_Group>(MPI_GROUP_NULL);
   }
index 853c980..6bd1b8a 100644 (file)
@@ -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) {
index 46012d7..85f55b6 100644 (file)
@@ -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>(MPI_REQUEST_NULL);
-  return static_cast<MPI_Request>(xbt_dict_get(Request::f2c_lookup_, get_key_id(key, id)));
+  return static_cast<MPI_Request>(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));
 }
 
 
index 472b927..007e01b 100644 (file)
@@ -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{