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.
static void destroy(MPI_Comm comm);
void init_smp();
static void destroy(MPI_Comm comm);
void init_smp();
static void free_f(int id);
static Comm* f2c(int);
static void free_f(int id);
static Comm* f2c(int);
static void set_f2c_lookup(std::unordered_map<std::string, F2C*>* map);
static int f2c_id();
static void f2c_id_increment();
static void set_f2c_lookup(std::unordered_map<std::string, F2C*>* map);
static int f2c_id();
static void f2c_id_increment();
+ char* get_my_key(char* key);
static char* get_key(char* key, int id);
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<std::string, F2C*>* lookup();
static void delete_lookup();
static std::unordered_map<std::string, F2C*>* 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();
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);
// 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);
static int grequest_complete( MPI_Request request);
static int get_status(MPI_Request req, int* flag, MPI_Status * status);
static int grequest_complete( MPI_Request request);
static int get_status(MPI_Request req, int* flag, MPI_Status * status);
static void free_f(int id);
static Request* f2c(int);
};
static void free_f(int id);
static Request* f2c(int);
};
std::unordered_map<int, smpi_key_elem> Comm::keyvals_;
int Comm::keyval_id_=0;
std::unordered_map<int, smpi_key_elem> 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;
{
refcount_ = 1;
topoType_ = MPI_INVALID_TOPO;
info_ = MPI_INFO_NULL;
static int global_id_=0;
//First creation of comm is done before SIMIX_run, so only do comms for others
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_;
int id;
if(this->rank()==0){
id=global_id_;
} else if(F2C::f2c_lookup() != nullptr && id >= 0) {
char key[KEY_SIZE];
const auto& lookup = F2C::f2c_lookup();
} 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<MPI_Comm>(comm->second);
} else {
return MPI_COMM_NULL;
return comm == lookup->end() ? MPI_COMM_NULL : static_cast<MPI_Comm>(comm->second);
} else {
return MPI_COMM_NULL;
void Comm::free_f(int id) {
char key[KEY_SIZE];
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<std::string, F2C*>);
- }
- 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){
}
void Comm::add_rma_win(MPI_Win win){
-char* F2C::get_key(char* key, int id) {
- std::snprintf(key, KEY_SIZE, "%u", static_cast<unsigned>(id));
+char* F2C::get_my_key(char* key) {
+ std::snprintf(key, KEY_SIZE, "%d", my_f2c_id_);
-char* F2C::get_key_id(char* key, int id) {
- std::snprintf(key, KEY_SIZE, "%u_%ld", static_cast<unsigned>(id), simgrid::s4u::this_actor::get_pid());
+char* F2C::get_key(char* key, int id) {
+ std::snprintf(key, KEY_SIZE, "%d", id);
void F2C::free_f(int id)
{
char key[KEY_SIZE];
void F2C::free_f(int id)
{
char key[KEY_SIZE];
- f2c_lookup_->erase(get_key(key, id));
+ f2c_lookup_->erase(get_key(key,id));
f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
char key[KEY_SIZE];
f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
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_lookup_ = new std::unordered_map<std::string, F2C*>;
}
f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
}
- 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_;
if(id >= 0){
char key[KEY_SIZE];
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;
return comm == f2c_lookup_->end() ? nullptr : comm->second;
}else
return nullptr;
char key[KEY_SIZE];
if(id==MPI_FORTRAN_REQUEST_NULL)
return static_cast<MPI_Request>(MPI_REQUEST_NULL);
char key[KEY_SIZE];
if(id==MPI_FORTRAN_REQUEST_NULL)
return static_cast<MPI_Request>(MPI_REQUEST_NULL);
- return static_cast<MPI_Request>(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<std::string, F2C*>);
- }
- 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<MPI_Request>(F2C::f2c_lookup()->at(get_key(key,id)));
}
void Request::free_f(int id)
{
if (id != MPI_FORTRAN_REQUEST_NULL) {
char key[KEY_SIZE];
}
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;
int Request::get_status(MPI_Request req, int* flag, MPI_Status * status){
*flag=0;