Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
welcome simgrid::smpi::Request
[simgrid.git] / src / smpi / smpi_comm.cpp
index 58748d9..5c094cd 100644 (file)
@@ -23,6 +23,10 @@ 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
 
+
+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
  * support them, we have to add a field MPIR_Topo_type, and replace the MPI_Topology field by an union. */
 
@@ -47,28 +51,30 @@ static int smpi_compare_rankmap(const void *a, const void *b)
 }
 
 namespace simgrid{
-namespace SMPI{
+namespace smpi{
 
-Comm::Comm(MPI_Group group, MPI_Topology topo)
+Comm::Comm(){}
+
+Comm::Comm(MPI_Group group, MPI_Topology topo) : group_(group), topo_(topo)
 {
-  m_group = group;
-  m_refcount=1;
-  m_topoType = MPI_INVALID_TOPO;
-  m_topo = topo;
-  m_intra_comm = MPI_COMM_NULL;
-  m_leaders_comm = MPI_COMM_NULL;
-  m_is_uniform=1;
-  m_non_uniform_map = nullptr;
-  m_leaders_map = nullptr;
-  m_is_blocked=0;
-  m_attributes=nullptr;
+  refcount_=1;
+  topoType_ = MPI_INVALID_TOPO;
+  intra_comm_ = MPI_COMM_NULL;
+  leaders_comm_ = MPI_COMM_NULL;
+  is_uniform_=1;
+  non_uniform_map_ = nullptr;
+  leaders_map_ = nullptr;
+  is_blocked_=0;
+  attributes_=nullptr;
 }
 
 void Comm::destroy()
 {
-  if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->destroy();
-  smpi_topo_destroy(m_topo); // there's no use count on topos
+  if (this == MPI_COMM_UNINITIALIZED){
+    smpi_process_comm_world()->destroy();
+    return;
+  }
+  delete topo_; // there's no use count on topos
   this->unuse();
 }
 
@@ -76,18 +82,18 @@ int Comm::dup(MPI_Comm* newcomm){
   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
      smpi_switch_data_segment(smpi_process_index());
    }
-  MPI_Group cp = new simgrid::SMPI::Group(this->group());
-  (*newcomm) = new simgrid::SMPI::Comm(cp, this->topo());
+  MPI_Group cp = new simgrid::smpi::Group(this->group());
+  (*newcomm) = new simgrid::smpi::Comm(cp, this->topo());
   int ret = MPI_SUCCESS;
 
-  if(m_attributes !=nullptr){
-    (*newcomm)->m_attributes   = xbt_dict_new_homogeneous(nullptr);
+  if(attributes_ !=nullptr){
+    (*newcomm)->attributes_   = xbt_dict_new_homogeneous(nullptr);
     xbt_dict_cursor_t cursor = nullptr;
     char* key;
     int flag;
     void* value_in;
     void* value_out;
-    xbt_dict_foreach (m_attributes, cursor, key, value_in) {
+    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)));
       if (elem != nullptr && elem->copy_fn != MPI_NULL_COPY_FN) {
@@ -99,7 +105,7 @@ int Comm::dup(MPI_Comm* newcomm){
           return ret;
         }
         if (flag)
-          xbt_dict_set_ext((*newcomm)->m_attributes, key, sizeof(int), value_out, nullptr);
+          xbt_dict_set_ext((*newcomm)->attributes_, key, sizeof(int), value_out, nullptr);
       }
       }
     }
@@ -110,33 +116,33 @@ MPI_Group Comm::group()
 {
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->group();
-  return m_group;
+  return group_;
 }
 
 MPI_Topology Comm::topo() {
-  if (this != MPI_COMM_NULL)
-    return m_topo;
-  return nullptr;
+  return topo_;
 }
 
 int Comm::size()
 {
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->size();
-  return m_group->size();
+  return group_->size();
 }
 
 int Comm::rank()
 {
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->rank();
-  return m_group->rank(smpi_process_index());
+  return group_->rank(smpi_process_index());
 }
 
 void Comm::get_name (char* name, int* len)
 {
-  if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->get_name(name, len);
+  if (this == MPI_COMM_UNINITIALIZED){
+    smpi_process_comm_world()->get_name(name, len);
+    return;
+  }
   if(this == MPI_COMM_WORLD) {
     strncpy(name, "WORLD",5);
     *len = 5;
@@ -146,49 +152,51 @@ void Comm::get_name (char* name, int* len)
 }
 
 void Comm::set_leaders_comm(MPI_Comm leaders){
-  if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->set_leaders_comm(leaders);
-  m_leaders_comm=leaders;
+  if (this == MPI_COMM_UNINITIALIZED){
+    smpi_process_comm_world()->set_leaders_comm(leaders);
+    return;
+  }
+  leaders_comm_=leaders;
 }
 
 void Comm::set_intra_comm(MPI_Comm leaders){
-  m_intra_comm=leaders;
+  intra_comm_=leaders;
 }
 
 int* Comm::get_non_uniform_map(){
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->get_non_uniform_map();
-  return m_non_uniform_map;
+  return non_uniform_map_;
 }
 
 int* Comm::get_leaders_map(){
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->get_leaders_map();
-  return m_leaders_map;
+  return leaders_map_;
 }
 
 MPI_Comm Comm::get_leaders_comm(){
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->get_leaders_comm();
-  return m_leaders_comm;
+  return leaders_comm_;
 }
 
 MPI_Comm Comm::get_intra_comm(){
   if (this == MPI_COMM_UNINITIALIZED || this==MPI_COMM_WORLD) 
     return smpi_process_get_comm_intra();
-  else return m_intra_comm;
+  else return intra_comm_;
 }
 
 int Comm::is_uniform(){
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->is_uniform();
-  return m_is_uniform;
+  return is_uniform_;
 }
 
 int Comm::is_blocked(){
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process_comm_world()->is_blocked();
-  return m_is_blocked;
+  return is_blocked_;
 }
 
 MPI_Comm Comm::split(int color, int key)
@@ -235,7 +243,7 @@ MPI_Comm Comm::split(int color, int key)
         rankmap[2 * count + 1] = recvbuf[2 * i + 1];
         count++;
         qsort(rankmap, count, 2 * sizeof(int), &smpi_compare_rankmap);
-        group_out = new simgrid::SMPI::Group(count);
+        group_out = new simgrid::smpi::Group(count);
         if (i == 0) {
           group_root = group_out; /* Save root's group */
         }
@@ -247,15 +255,15 @@ MPI_Comm Comm::split(int color, int key)
         int reqs              = 0;
         for (int j = 0; j < count; j++) {
           if(rankmap[2 * j] != 0) {
-            group_snd[reqs]=new simgrid::SMPI::Group(group_out);
-            requests[reqs] = smpi_mpi_isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, this);
+            group_snd[reqs]=new simgrid::smpi::Group(group_out);
+            requests[reqs] = Request::isend(&(group_snd[reqs]), 1, MPI_PTR, rankmap[2 * j], system_tag, this);
             reqs++;
           }
         }
         if(i != 0) {
           group_out->destroy();
         }
-        smpi_mpi_waitall(reqs, requests, MPI_STATUS_IGNORE);
+        Request::waitall(reqs, requests, MPI_STATUS_IGNORE);
         xbt_free(requests);
       }
     }
@@ -265,52 +273,56 @@ MPI_Comm Comm::split(int color, int key)
     group_out = group_root; /* exit with root's group */
   } else {
     if(color != MPI_UNDEFINED) {
-      smpi_mpi_recv(&group_out, 1, MPI_PTR, 0, system_tag, this, MPI_STATUS_IGNORE);
+      Request::recv(&group_out, 1, MPI_PTR, 0, system_tag, this, MPI_STATUS_IGNORE);
     } /* otherwise, exit with group_out == nullptr */
   }
-  return group_out!=nullptr ? new simgrid::SMPI::Comm(group_out, nullptr) : MPI_COMM_NULL;
+  return group_out!=nullptr ? new simgrid::smpi::Comm(group_out, nullptr) : MPI_COMM_NULL;
 }
 
 void Comm::use(){
-  if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->use();
-  m_group->use();
-  m_refcount++;
+  if (this == MPI_COMM_UNINITIALIZED){
+    smpi_process_comm_world()->use();
+    return;
+  }
+  group_->use();
+  refcount_++;
 }
 
 void Comm::cleanup_attributes(){
-  if(m_attributes !=nullptr){
+  if(attributes_ !=nullptr){
     xbt_dict_cursor_t cursor = nullptr;
     char* key;
     void* value;
     int flag;
-    xbt_dict_foreach (m_attributes, cursor, key, value) {
+    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));
       if (elem != nullptr && elem->delete_fn != nullptr)
         elem->delete_fn(this, atoi(key), value, &flag);
     }
-    xbt_dict_free(&m_attributes);
+    xbt_dict_free(&attributes_);
   }
 }
 
 void Comm::cleanup_smp(){
-  if (m_intra_comm != MPI_COMM_NULL)
-    m_intra_comm->unuse();
-  if (m_leaders_comm != MPI_COMM_NULL)
-    m_leaders_comm->unuse();
-  if (m_non_uniform_map != nullptr)
-    xbt_free(m_non_uniform_map);
-  if (m_leaders_map != nullptr)
-    xbt_free(m_leaders_map);
+  if (intra_comm_ != MPI_COMM_NULL)
+    intra_comm_->unuse();
+  if (leaders_comm_ != MPI_COMM_NULL)
+    leaders_comm_->unuse();
+  if (non_uniform_map_ != nullptr)
+    xbt_free(non_uniform_map_);
+  if (leaders_map_ != nullptr)
+    xbt_free(leaders_map_);
 }
 
 void Comm::unuse(){
-  if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->unuse();
-  m_refcount--;
-  m_group->unuse();
+  if (this == MPI_COMM_UNINITIALIZED){
+    smpi_process_comm_world()->unuse();
+    return;
+  }
+  refcount_--;
+  group_->unuse();
 
-  if(m_refcount==0){
+  if(refcount_==0){
     this->cleanup_smp();
     this->cleanup_attributes();
     delete this;
@@ -329,7 +341,7 @@ void Comm::init_smp(){
   int leader = -1;
 
   if (this == MPI_COMM_UNINITIALIZED)
-    return smpi_process_comm_world()->init_smp();
+    smpi_process_comm_world()->init_smp();
 
   int comm_size = this->size();
   
@@ -363,7 +375,7 @@ void Comm::init_smp(){
     }
   }
   XBT_DEBUG("number of processes deployed on my node : %d", intra_comm_size);
-  MPI_Group group_intra = new simgrid::SMPI::Group(intra_comm_size);
+  MPI_Group group_intra = new simgrid::smpi::Group(intra_comm_size);
   i=0;
   process = nullptr;
   xbt_swag_foreach(process, process_list) {
@@ -374,7 +386,7 @@ void Comm::init_smp(){
     }
   }
 
-  MPI_Comm comm_intra = new simgrid::SMPI::Comm(group_intra, nullptr);
+  MPI_Comm comm_intra = new simgrid::smpi::Comm(group_intra, nullptr);
   leader=min_index;
 
   int * leaders_map= static_cast<int*>(xbt_malloc0(sizeof(int)*comm_size));
@@ -389,8 +401,8 @@ void Comm::init_smp(){
      smpi_switch_data_segment(smpi_process_index());
    }
 
-  if(m_leaders_map==nullptr){
-    m_leaders_map= leaders_map;
+  if(leaders_map_==nullptr){
+    leaders_map_= leaders_map;
   }else{
     xbt_free(leaders_map);
   }
@@ -399,25 +411,25 @@ void Comm::init_smp(){
   for(i=0; i<comm_size; i++){
       int already_done=0;
       for(j=0;j<leader_group_size; j++){
-        if(m_leaders_map[i]==leader_list[j]){
+        if(leaders_map_[i]==leader_list[j]){
             already_done=1;
         }
       }
       if(already_done==0){
-        leader_list[leader_group_size]=m_leaders_map[i];
+        leader_list[leader_group_size]=leaders_map_[i];
         leader_group_size++;
       }
   }
   qsort(leader_list, leader_group_size, sizeof(int),compare_ints);
 
-  MPI_Group leaders_group = new simgrid::SMPI::Group(leader_group_size);
+  MPI_Group leaders_group = new simgrid::smpi::Group(leader_group_size);
 
   MPI_Comm leader_comm = MPI_COMM_NULL;
   if(MPI_COMM_WORLD!=MPI_COMM_UNINITIALIZED && this!=MPI_COMM_WORLD){
     //create leader_communicator
     for (i=0; i< leader_group_size;i++)
       leaders_group->set_mapping(leader_list[i], i);
-    leader_comm = new simgrid::SMPI::Comm(leaders_group, nullptr);
+    leader_comm = new simgrid::smpi::Comm(leaders_group, nullptr);
     this->set_leaders_comm(leader_comm);
     this->set_intra_comm(comm_intra);
 
@@ -427,7 +439,7 @@ void Comm::init_smp(){
       leaders_group->set_mapping(leader_list[i], i);
 
     if(this->get_leaders_comm()==MPI_COMM_NULL){
-      leader_comm = new simgrid::SMPI::Comm(leaders_group, nullptr);
+      leader_comm = new simgrid::smpi::Comm(leaders_group, nullptr);
       this->set_leaders_comm(leader_comm);
     }else{
       leader_comm=this->get_leaders_comm();
@@ -451,13 +463,13 @@ void Comm::init_smp(){
       }
     }
     if(is_uniform==0 && this->is_uniform()!=0){
-        m_non_uniform_map= non_uniform_map;
+        non_uniform_map_= non_uniform_map;
     }else{
         xbt_free(non_uniform_map);
     }
-    m_is_uniform=is_uniform;
+    is_uniform_=is_uniform;
   }
-  smpi_coll_tuned_bcast_mpich(&(m_is_uniform),1, MPI_INT, 0, comm_intra );
+  smpi_coll_tuned_bcast_mpich(&(is_uniform_),1, MPI_INT, 0, comm_intra );
 
   if(smpi_privatize_global_variables){ //we need to switch as the called function may silently touch global variables
      smpi_switch_data_segment(smpi_process_index());
@@ -479,10 +491,10 @@ void Comm::init_smp(){
 
   if(MPI_COMM_WORLD==MPI_COMM_UNINITIALIZED || this==MPI_COMM_WORLD){
     if(this->rank()==0){
-        m_is_blocked=global_blocked;
+        is_blocked_=global_blocked;
     }
   }else{
-    m_is_blocked=global_blocked;
+    is_blocked_=global_blocked;
   }
   xbt_free(leader_list);
   
@@ -504,10 +516,10 @@ int Comm::attr_delete(int keyval){
         return ret;
     }
   }
-  if(m_attributes==nullptr)
+  if(attributes_==nullptr)
     return MPI_ERR_ARG;
 
-  xbt_dict_remove_ext(m_attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
+  xbt_dict_remove_ext(attributes_, reinterpret_cast<const char*>(&keyval), sizeof(int));
   return MPI_SUCCESS;
 }
 
@@ -516,13 +528,13 @@ int Comm::attr_get(int keyval, void* attr_value, int* flag){
     static_cast<smpi_comm_key_elem>(xbt_dict_get_or_null_ext(smpi_comm_keyvals, reinterpret_cast<const char*>(&keyval), sizeof(int)));
   if(elem==nullptr)
     return MPI_ERR_ARG;
-  if(m_attributes==nullptr){
+  if(attributes_==nullptr){
     *flag=0;
     return MPI_SUCCESS;
   }
   try {
     *static_cast<void**>(attr_value) =
-        xbt_dict_get_ext(m_attributes, reinterpret_cast<const char*>(&keyval), sizeof(int));
+        xbt_dict_get_ext(attributes_, reinterpret_cast<const char*>(&keyval), sizeof(int));
     *flag=1;
   }
   catch (xbt_ex& ex) {
@@ -546,10 +558,10 @@ int Comm::attr_put(int keyval, void* attr_value){
     if(ret!=MPI_SUCCESS) 
       return ret;
   }
-  if(m_attributes==nullptr)
-    m_attributes = xbt_dict_new_homogeneous(nullptr);
+  if(attributes_==nullptr)
+    attributes_ = xbt_dict_new_homogeneous(nullptr);
 
-  xbt_dict_set_ext(m_attributes,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
+  xbt_dict_set_ext(attributes_,  reinterpret_cast<const char*>(&keyval), sizeof(int), attr_value, nullptr);
   return MPI_SUCCESS;
 }