XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_comm, smpi, "Logging specific to SMPI (comm)");
- simgrid::smpi::Comm mpi_MPI_COMM_UNINITIALIZED;
+simgrid::smpi::Comm mpi_MPI_COMM_UNINITIALIZED;
MPI_Comm MPI_COMM_UNINITIALIZED=&mpi_MPI_COMM_UNINITIALIZED;
/* Support for cartesian topology was added, but there are 2 other types of topology, graph et dist graph. In order to
int Comm::dup(MPI_Comm* newcomm){
if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables
- smpi_switch_data_segment(smpi_process()->index());
- }
+ smpi_switch_data_segment(smpi_process()->index());
+ }
MPI_Group cp = new Group(this->group());
(*newcomm) = new Comm(cp, this->topo());
int ret = MPI_SUCCESS;
(*newcomm)->attributes()->insert({it.first, value_out});
}
}
- }
}
+ }
return ret;
}
// tell SimGrid we are not in replay for a while, because we need the buffers to be copied for the following calls
bool replaying = false; //cache data to set it back again after
if(smpi_process()->replaying()){
- replaying=true;
- smpi_process()->set_replaying(false);
+ replaying = true;
+ smpi_process()->set_replaying(false);
}
if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables
- smpi_switch_data_segment(smpi_process()->index());
- }
+ smpi_switch_data_segment(smpi_process()->index());
+ }
//identify neighbours in comm
//get the indexes of all processes sharing the same simix host
- xbt_swag_t process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
- int intra_comm_size = 0;
- int min_index = INT_MAX; // the minimum index will be the leader
- smx_actor_t actor = nullptr;
- xbt_swag_foreach(actor, process_list)
- {
- int index = actor->pid - 1;
-
- if (this->group()->rank(index) != MPI_UNDEFINED) {
- intra_comm_size++;
- // the process is in the comm
- if (index < min_index)
- min_index = index;
- }
+ xbt_swag_t process_list = sg_host_self()->extension<simgrid::simix::Host>()->process_list;
+ int intra_comm_size = 0;
+ int min_index = INT_MAX; // the minimum index will be the leader
+ smx_actor_t actor = nullptr;
+ xbt_swag_foreach(actor, process_list)
+ {
+ int index = actor->pid - 1;
+
+ if (this->group()->rank(index) != MPI_UNDEFINED) {
+ intra_comm_size++;
+ // the process is in the comm
+ if (index < min_index)
+ min_index = index;
+ }
}
XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
MPI_Group group_intra = new Group(intra_comm_size);
int * leaders_map= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
int * leader_list= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
for(i=0; i<comm_size; i++){
- leader_list[i]=-1;
+ leader_list[i] = -1;
}
Coll_allgather_mpich::allgather(&leader, 1, MPI_INT , leaders_map, 1, MPI_INT, this);
if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables
- smpi_switch_data_segment(smpi_process()->index());
- }
+ smpi_switch_data_segment(smpi_process()->index());
+ }
if(leaders_map_==nullptr){
leaders_map_= leaders_map;
int j=0;
int leader_group_size = 0;
for(i=0; i<comm_size; i++){
- int already_done=0;
- for(j=0;j<leader_group_size; j++){
- if(leaders_map_[i]==leader_list[j]){
- already_done=1;
- }
- }
- if(already_done==0){
- leader_list[leader_group_size]=leaders_map_[i];
- leader_group_size++;
+ int already_done = 0;
+ for (j = 0; j < leader_group_size; j++) {
+ if (leaders_map_[i] == leader_list[j]) {
+ already_done = 1;
}
+ }
+ if (already_done == 0) {
+ leader_list[leader_group_size] = leaders_map_[i];
+ leader_group_size++;
+ }
}
std::sort(leader_list, leader_list + leader_group_size);
this->set_leaders_comm(leader_comm);
this->set_intra_comm(comm_intra);
- //create intracommunicator
+ // create intracommunicator
}else{
for (i=0; i< leader_group_size;i++)
leaders_group->set_mapping(leader_list[i], i);
}
}
if(is_uniform==0 && this->is_uniform()!=0){
- non_uniform_map_= non_uniform_map;
+ non_uniform_map_ = non_uniform_map;
}else{
- xbt_free(non_uniform_map);
+ xbt_free(non_uniform_map);
}
is_uniform_=is_uniform;
}
Coll_bcast_mpich::bcast(&(is_uniform_),1, MPI_INT, 0, comm_intra );
if(smpi_privatize_global_variables == SMPI_PRIVATIZE_MMAP){ //we need to switch as the called function may silently touch global variables
- smpi_switch_data_segment(smpi_process()->index());
- }
+ smpi_switch_data_segment(smpi_process()->index());
+ }
// Are the ranks blocked ? = allocated contiguously on the SMP nodes
int is_blocked=1;
int prev=this->group()->rank(comm_intra->group()->index(0));
- for (i=1; i<my_local_size; i++){
- int that=this->group()->rank(comm_intra->group()->index(i));
- if(that!=prev+1){
- is_blocked=0;
- break;
- }
- prev = that;
+ for (i = 1; i < my_local_size; i++) {
+ int that = this->group()->rank(comm_intra->group()->index(i));
+ if (that != prev + 1) {
+ is_blocked = 0;
+ break;
+ }
+ prev = that;
}
int global_blocked;
if(MPI_COMM_WORLD==MPI_COMM_UNINITIALIZED || this==MPI_COMM_WORLD){
if(this->rank()==0){
- is_blocked_=global_blocked;
+ is_blocked_ = global_blocked;
}
}else{
is_blocked_=global_blocked;
} else if(id==0){
return MPI_COMM_WORLD;
} else if(F2C::f2c_lookup() != nullptr && id >= 0) {
- char key[KEY_SIZE];
- 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 ;
+ char key[KEY_SIZE];
+ try {
+ return static_cast<MPI_Comm>(F2C::f2c_lookup()->at(get_key_id(key, id)));
+ } catch (std::out_of_range& unfound) {
+ return MPI_COMM_NULL;
+ }
} else {
return MPI_COMM_NULL;
}
void Comm::free_f(int id) {
char key[KEY_SIZE];
- xbt_dict_remove(F2C::f2c_lookup(), id==0? get_key(key, id) : get_key_id(key, id));
+ 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(xbt_dict_new_homogeneous(nullptr));
+ F2C::set_f2c_lookup(new std::unordered_map<std::string, F2C*>);
}
char key[KEY_SIZE];
- 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_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;
}
-
void Comm::add_rma_win(MPI_Win win){
rma_wins_.push_back(win);
}
}
}
-
}
}
namespace simgrid{
namespace smpi{
-xbt_dict_t F2C::f2c_lookup_=nullptr;
-int F2C::f2c_id_=0;
+std::unordered_map<std::string, F2C*>* F2C::f2c_lookup_ = nullptr;
+int F2C::f2c_id_ = 0;
-xbt_dict_t F2C::f2c_lookup(){
+std::unordered_map<std::string, F2C*>* F2C::f2c_lookup()
+{
return f2c_lookup_;
}
-void F2C::set_f2c_lookup(xbt_dict_t dict){
- f2c_lookup_=dict;
+void F2C::set_f2c_lookup(std::unordered_map<std::string, F2C*>* map)
+{
+ f2c_lookup_ = map;
}
void F2C::f2c_id_increment(){
};
char* F2C::get_key(char* key, int id) {
- std::snprintf(key, KEY_SIZE, "%x", (unsigned)id);
+ std::snprintf(key, KEY_SIZE, "%x", static_cast<unsigned>(id));
return key;
}
char* F2C::get_key_id(char* key, int id) {
- std::snprintf(key, KEY_SIZE, "%x_%d", (unsigned)id, smpi_process()->index());
+ std::snprintf(key, KEY_SIZE, "%x_%d", static_cast<unsigned>(id), smpi_process()->index());
return key;
}
void F2C::delete_lookup(){
- xbt_dict_free(&f2c_lookup_);
+ delete f2c_lookup_;
}
-xbt_dict_t F2C::lookup(){
+std::unordered_map<std::string, F2C*>* F2C::lookup()
+{
return f2c_lookup_;
}
-void F2C::free_f(int id){
+void F2C::free_f(int id)
+{
char key[KEY_SIZE];
- xbt_dict_remove(f2c_lookup_, get_key(key, id));
+ f2c_lookup_->erase(get_key(key, id));
}
-int F2C::add_f(){
- if(f2c_lookup_==nullptr){
- f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
- }
+int F2C::add_f()
+{
+ if (f2c_lookup_ == nullptr)
+ f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
+
char key[KEY_SIZE];
- xbt_dict_set(f2c_lookup_, get_key(key, f2c_id_), this, nullptr);
+ (*f2c_lookup_)[get_key(key, f2c_id_)] = this;
f2c_id_increment();
return f2c_id_-1;
}
-int F2C::c2f(){
- if(f2c_lookup_==nullptr){
- f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
+int F2C::c2f()
+{
+ if (f2c_lookup_ == nullptr) {
+ f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
}
- char* existing_key = xbt_dict_get_key(f2c_lookup_, this);
- if(existing_key!=nullptr){
- return atoi(existing_key);}
- else{
- return this->add_f();}
+ for (auto elm : *f2c_lookup_)
+ if (elm.second == this)
+ return std::stoi(elm.first);
+
+ /* this function wasn't found, add it */
+ return this->add_f();
}
-F2C* F2C::f2c(int id){
- if(f2c_lookup_==nullptr){
- f2c_lookup_=xbt_dict_new_homogeneous(nullptr);
- }
+F2C* F2C::f2c(int id)
+{
+ if (f2c_lookup_ == nullptr)
+ f2c_lookup_ = new std::unordered_map<std::string, F2C*>;
+
if(id >= 0){
char key[KEY_SIZE];
- return static_cast<F2C*>(xbt_dict_get_or_null(f2c_lookup_, get_key(key, id)));
+ try {
+ return f2c_lookup_->at(get_key(key, id));
+ } catch (std::out_of_range& unfound) {
+ return nullptr;
+ }
}else
- return NULL;
+ return nullptr;
}
}