From: Augustin Degomme Date: Fri, 26 Jul 2019 08:09:57 +0000 (+0200) Subject: Change a bit F2C handling X-Git-Tag: v3.24~255 X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/commitdiff_plain/cbc68013e8f1008e88a8cefb1e60b7813cf8a409 Change a bit F2C handling Store the f2c id in the objects, instead of stupidly browsing the entire map to get it each time In some cases we had issues with old pointers not being removed from the map, and being reused for other objects, which could cause mismatches. --- diff --git a/src/smpi/include/smpi_comm.hpp b/src/smpi/include/smpi_comm.hpp index ae30f6583a..27d71bd63e 100644 --- a/src/smpi/include/smpi_comm.hpp +++ b/src/smpi/include/smpi_comm.hpp @@ -67,7 +67,6 @@ public: static void destroy(MPI_Comm comm); void init_smp(); - int add_f() override; static void free_f(int id); static Comm* f2c(int); diff --git a/src/smpi/include/smpi_f2c.hpp b/src/smpi/include/smpi_f2c.hpp index f28c8fbafe..1d965e9aba 100644 --- a/src/smpi/include/smpi_f2c.hpp +++ b/src/smpi/include/smpi_f2c.hpp @@ -27,19 +27,20 @@ class F2C { static void set_f2c_lookup(std::unordered_map* map); static int f2c_id(); static void f2c_id_increment(); + int my_f2c_id_; public: + char* get_my_key(char* key); static char* get_key(char* key, int id); - static char* get_key_id(char* key, int id); static void delete_lookup(); static std::unordered_map* lookup(); - + F2C() : my_f2c_id_(-1){} virtual ~F2C() = default; //Override these to handle specific values. virtual int add_f(); static void free_f(int id); virtual int c2f(); - + static void print_f2c_lookup(); // This method should be overridden in all subclasses to avoid casting the result when calling it. // For the default one, the MPI_*_NULL returned is assumed to be NULL. static F2C* f2c(int id); diff --git a/src/smpi/include/smpi_request.hpp b/src/smpi/include/smpi_request.hpp index f8fe78217c..d16e050492 100644 --- a/src/smpi/include/smpi_request.hpp +++ b/src/smpi/include/smpi_request.hpp @@ -115,7 +115,6 @@ public: static int grequest_complete( MPI_Request request); static int get_status(MPI_Request req, int* flag, MPI_Status * status); - int add_f() override; static void free_f(int id); static Request* f2c(int); }; diff --git a/src/smpi/mpi/smpi_comm.cpp b/src/smpi/mpi/smpi_comm.cpp index 380c314145..b03c34043b 100644 --- a/src/smpi/mpi/smpi_comm.cpp +++ b/src/smpi/mpi/smpi_comm.cpp @@ -28,7 +28,7 @@ namespace smpi{ std::unordered_map Comm::keyvals_; int Comm::keyval_id_=0; -Comm::Comm(MPI_Group group, MPI_Topology topo, int smp, int id) : group_(group), topo_(topo),is_smp_comm_(smp), id_(id) +Comm::Comm(MPI_Group group, MPI_Topology topo, int smp, int in_id) : group_(group), topo_(topo),is_smp_comm_(smp), id_(in_id) { refcount_ = 1; topoType_ = MPI_INVALID_TOPO; @@ -41,7 +41,7 @@ Comm::Comm(MPI_Group group, MPI_Topology topo, int smp, int id) : group_(group), info_ = MPI_INFO_NULL; static int global_id_=0; //First creation of comm is done before SIMIX_run, so only do comms for others - if(id==MPI_UNDEFINED && smp==0 && this->rank()!=MPI_UNDEFINED ){ + if(in_id==MPI_UNDEFINED && smp==0 && this->rank()!=MPI_UNDEFINED ){ int id; if(this->rank()==0){ id=global_id_; @@ -505,7 +505,7 @@ MPI_Comm Comm::f2c(int id) { } else if(F2C::f2c_lookup() != nullptr && id >= 0) { char key[KEY_SIZE]; const auto& lookup = F2C::f2c_lookup(); - auto comm = lookup->find(get_key_id(key, id)); + auto comm = lookup->find(get_key(key, id)); return comm == lookup->end() ? MPI_COMM_NULL : static_cast(comm->second); } else { return MPI_COMM_NULL; @@ -514,17 +514,7 @@ MPI_Comm Comm::f2c(int id) { void Comm::free_f(int id) { char key[KEY_SIZE]; - F2C::f2c_lookup()->erase(id == 0 ? get_key(key, id) : get_key_id(key, id)); -} - -int Comm::add_f() { - if(F2C::f2c_lookup()==nullptr){ - F2C::set_f2c_lookup(new std::unordered_map); - } - char key[KEY_SIZE]; - (*(F2C::f2c_lookup()))[this == MPI_COMM_WORLD ? get_key(key, F2C::f2c_id()) : get_key_id(key, F2C::f2c_id())] = this; - f2c_id_increment(); - return F2C::f2c_id()-1; + F2C::f2c_lookup()->erase(get_key(key, id)); } void Comm::add_rma_win(MPI_Win win){ diff --git a/src/smpi/mpi/smpi_f2c.cpp b/src/smpi/mpi/smpi_f2c.cpp index 868644c414..5fd26579c0 100644 --- a/src/smpi/mpi/smpi_f2c.cpp +++ b/src/smpi/mpi/smpi_f2c.cpp @@ -38,13 +38,13 @@ int F2C::f2c_id(){ return f2c_id_; }; -char* F2C::get_key(char* key, int id) { - std::snprintf(key, KEY_SIZE, "%u", static_cast(id)); +char* F2C::get_my_key(char* key) { + std::snprintf(key, KEY_SIZE, "%d", my_f2c_id_); return key; } -char* F2C::get_key_id(char* key, int id) { - std::snprintf(key, KEY_SIZE, "%u_%ld", static_cast(id), simgrid::s4u::this_actor::get_pid()); +char* F2C::get_key(char* key, int id) { + std::snprintf(key, KEY_SIZE, "%d", id); return key; } @@ -60,7 +60,7 @@ std::unordered_map* F2C::lookup() void F2C::free_f(int id) { char key[KEY_SIZE]; - f2c_lookup_->erase(get_key(key, id)); + f2c_lookup_->erase(get_key(key,id)); } int F2C::add_f() @@ -69,9 +69,10 @@ int F2C::add_f() f2c_lookup_ = new std::unordered_map; char key[KEY_SIZE]; - (*f2c_lookup_)[get_key(key, f2c_id_)] = this; + my_f2c_id_=f2c_id_; + (*f2c_lookup_)[get_my_key(key)] = this; f2c_id_increment(); - return f2c_id_-1; + return my_f2c_id_; } int F2C::c2f() @@ -80,12 +81,11 @@ int F2C::c2f() f2c_lookup_ = new std::unordered_map; } - for (auto const& elm : *f2c_lookup_) - if (elm.second == this) - return std::stoi(elm.first); - - /* this function wasn't found, add it */ - return this->add_f(); + if(my_f2c_id_==-1) + /* this function wasn't found, add it */ + return this->add_f(); + else + return my_f2c_id_; } F2C* F2C::f2c(int id) @@ -95,7 +95,7 @@ F2C* F2C::f2c(int id) if(id >= 0){ char key[KEY_SIZE]; - auto comm = f2c_lookup_->find(get_key(key, id)); + auto comm = f2c_lookup_->find(get_key(key,id)); return comm == f2c_lookup_->end() ? nullptr : comm->second; }else return nullptr; diff --git a/src/smpi/mpi/smpi_request.cpp b/src/smpi/mpi/smpi_request.cpp index 08003cec58..f8fa611d37 100644 --- a/src/smpi/mpi/smpi_request.cpp +++ b/src/smpi/mpi/smpi_request.cpp @@ -1089,29 +1089,17 @@ 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(F2C::f2c_lookup()->at(get_key_id(key, id))); -} - -int Request::add_f() -{ - if (F2C::f2c_lookup() == nullptr) { - F2C::set_f2c_lookup(new std::unordered_map); - } - char key[KEY_SIZE]; - (*(F2C::f2c_lookup()))[get_key_id(key, F2C::f2c_id())] = this; - F2C::f2c_id_increment(); - return F2C::f2c_id()-1; + return static_cast(F2C::f2c_lookup()->at(get_key(key,id))); } void Request::free_f(int id) { if (id != MPI_FORTRAN_REQUEST_NULL) { char key[KEY_SIZE]; - F2C::f2c_lookup()->erase(get_key_id(key, id)); + F2C::f2c_lookup()->erase(get_key(key, id)); } } - int Request::get_status(MPI_Request req, int* flag, MPI_Status * status){ *flag=0;