Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Have the communicators created together share a unique ID.
[simgrid.git] / src / smpi / mpi / smpi_comm.cpp
index 6baa559..380c314 100644 (file)
@@ -28,7 +28,7 @@ namespace smpi{
 std::unordered_map<int, smpi_key_elem> Comm::keyvals_;
 int Comm::keyval_id_=0;
 
-Comm::Comm(MPI_Group group, MPI_Topology topo, int smp) : group_(group), topo_(topo),is_smp_comm_(smp)
+Comm::Comm(MPI_Group group, MPI_Topology topo, int smp, int id) : group_(group), topo_(topo),is_smp_comm_(smp), id_(id)
 {
   refcount_        = 1;
   topoType_        = MPI_INVALID_TOPO;
@@ -39,6 +39,19 @@ Comm::Comm(MPI_Group group, MPI_Topology topo, int smp) : group_(group), topo_(t
   leaders_map_     = nullptr;
   is_blocked_      = 0;
   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 ){
+    int id;
+    if(this->rank()==0){
+      id=global_id_;
+      global_id_++;
+    }
+    Colls::bcast(&id, 1, MPI_INT, 0, this);
+    XBT_DEBUG("Communicator %p has id %d", this, id);
+    id_=id;//only set here, as we don't want to change it in the middle of the bcast
+    Colls::barrier(this);
+  }
 }
 
 void Comm::destroy(Comm* comm)
@@ -98,6 +111,8 @@ int Comm::dup(MPI_Comm* newcomm){
 
 int Comm::dup_with_info(MPI_Info info, MPI_Comm* newcomm){
   int ret = dup(newcomm);
+  if(ret != MPI_SUCCESS)
+    return ret;
   if((*newcomm)->info_!=MPI_INFO_NULL){
     simgrid::smpi::Info::unref((*newcomm)->info_);
     (*newcomm)->info_=MPI_INFO_NULL;
@@ -129,6 +144,11 @@ int Comm::rank()
   return group_->rank(s4u::Actor::self());
 }
 
+int Comm::id()
+{
+  return id_;
+}
+
 void Comm::get_name (char* name, int* len)
 {
   if (this == MPI_COMM_UNINITIALIZED){
@@ -210,7 +230,7 @@ MPI_Comm Comm::split(int color, int key)
 {
   if (this == MPI_COMM_UNINITIALIZED)
     return smpi_process()->comm_world()->split(color, key);
-  int system_tag = 123;
+  int system_tag = -123;
   int* recvbuf;
 
   MPI_Group group_root = nullptr;