Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use std::string for f2c keys.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Oct 2020 21:42:34 +0000 (22:42 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Tue, 27 Oct 2020 22:43:08 +0000 (23:43 +0100)
src/smpi/include/smpi_f2c.hpp
src/smpi/mpi/smpi_comm.cpp
src/smpi/mpi/smpi_errhandler.cpp
src/smpi/mpi/smpi_f2c.cpp
src/smpi/mpi/smpi_group.cpp
src/smpi/mpi/smpi_request.cpp

index 7181c6b..d3f6b92 100644 (file)
@@ -12,8 +12,6 @@
 #include <unordered_map>
 #include <string>
 
-#define KEY_SIZE (sizeof(int) * 2 + 1)
-
 namespace simgrid{
 namespace smpi{
 
@@ -32,8 +30,8 @@ class F2C {
     static void f2c_id_increment();
 
   public:
-    char* get_my_key(char* key);
-    static char* get_key(char* key, int id);
+    std::string get_my_key() { return get_key(my_f2c_id_); }
+    static std::string get_key(int id) { return std::to_string(id); }
     static void delete_lookup();
     static std::unordered_map<std::string, F2C*>* lookup();
     F2C();
index dcd7d83..21dbc86 100644 (file)
@@ -509,9 +509,8 @@ MPI_Comm Comm::f2c(int id) {
   } else if(id==0){
     return MPI_COMM_WORLD;
   } else if(F2C::f2c_lookup() != nullptr && id >= 0) {
-    char key[KEY_SIZE];
     const auto& lookup = F2C::f2c_lookup();
-    auto comm          = lookup->find(get_key(key, id));
+    auto comm          = lookup->find(get_key(id));
     return comm == lookup->end() ? MPI_COMM_NULL : static_cast<MPI_Comm>(comm->second);
   } else {
     return MPI_COMM_NULL;
@@ -519,8 +518,7 @@ MPI_Comm Comm::f2c(int id) {
 }
 
 void Comm::free_f(int id) {
-  char key[KEY_SIZE];
-  F2C::f2c_lookup()->erase(get_key(key, id));
+  F2C::f2c_lookup()->erase(get_key(id));
 }
 
 void Comm::add_rma_win(MPI_Win win){
index abedcfa..3c7f9ce 100644 (file)
@@ -18,8 +18,7 @@ namespace smpi{
 
 MPI_Errhandler Errhandler::f2c(int id) {
   if(F2C::f2c_lookup() != nullptr && id >= 0) {
-    char key[KEY_SIZE];
-    return static_cast<MPI_Errhandler>(F2C::f2c_lookup()->at(get_key(key, id)));
+    return static_cast<MPI_Errhandler>(F2C::f2c_lookup()->at(get_key(id)));
   } else {
     return MPI_ERRHANDLER_NULL;
   }
index dafd940..35246a7 100644 (file)
@@ -41,16 +41,6 @@ int F2C::f2c_id(){
   return f2c_id_;
 }
 
-char* F2C::get_my_key(char* key) {
-  std::snprintf(key, KEY_SIZE, "%d", my_f2c_id_);
-  return key;
-}
-
-char* F2C::get_key(char* key, int id) {
-  std::snprintf(key, KEY_SIZE, "%d", id);
-  return key;
-}
-
 void F2C::delete_lookup(){
   delete f2c_lookup_;
 }
@@ -62,8 +52,7 @@ std::unordered_map<std::string, F2C*>* F2C::lookup()
 
 void F2C::free_f(int id)
 {
-  char key[KEY_SIZE];
-  f2c_lookup_->erase(get_key(key,id));
+  f2c_lookup_->erase(get_key(id));
 }
 
 int F2C::add_f()
@@ -71,9 +60,8 @@ int F2C::add_f()
   if (f2c_lookup_ == nullptr)
     f2c_lookup_ = new std::unordered_map<std::string, F2C*>();
 
-  char key[KEY_SIZE];
   my_f2c_id_=f2c_id_;
-  (*f2c_lookup_)[get_my_key(key)] = this;
+  (*f2c_lookup_)[get_my_key()] = this;
   f2c_id_increment();
   return my_f2c_id_;
 }
@@ -97,8 +85,7 @@ F2C* F2C::f2c(int id)
     f2c_lookup_ = new std::unordered_map<std::string, F2C*>();
 
   if(id >= 0){
-    char key[KEY_SIZE];
-    auto comm = f2c_lookup_->find(get_key(key,id));
+    auto comm = f2c_lookup_->find(get_key(id));
     return comm == f2c_lookup_->end() ? nullptr : comm->second;
   }else
     return nullptr;
index dceefb9..c52e2a7 100644 (file)
@@ -319,8 +319,7 @@ MPI_Group Group::f2c(int id) {
   if(id == -2) {
     return MPI_GROUP_EMPTY;
   } else if(F2C::f2c_lookup() != nullptr && id >= 0) {
-    char key[KEY_SIZE];
-    return static_cast<MPI_Group>(F2C::f2c_lookup()->at(get_key(key, id)));
+    return static_cast<MPI_Group>(F2C::f2c_lookup()->at(get_key(id)));
   } else {
     return MPI_GROUP_NULL;
   }
index ca295f3..22510d8 100644 (file)
@@ -1117,17 +1117,15 @@ int Request::waitsome(int incount, MPI_Request requests[], int *indices, MPI_Sta
 
 MPI_Request Request::f2c(int id)
 {
-  char key[KEY_SIZE];
   if(id==MPI_FORTRAN_REQUEST_NULL)
     return MPI_REQUEST_NULL;
-  return static_cast<MPI_Request>(F2C::f2c_lookup()->at(get_key(key,id)));
+  return static_cast<MPI_Request>(F2C::f2c_lookup()->at(get_key(id)));
 }
 
 void Request::free_f(int id)
 {
   if (id != MPI_FORTRAN_REQUEST_NULL) {
-    char key[KEY_SIZE];
-    F2C::f2c_lookup()->erase(get_key(key, id));
+    F2C::f2c_lookup()->erase(get_key(id));
   }
 }