Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Cosmetics in cmake
[simgrid.git] / src / smpi / mpi / smpi_group.cpp
index b199d12..4b07f91 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2023. The SimGrid Team. All rights reserved.          */
 
 /* This program is free software; you can redistribute it and/or modify it
  * under the terms of the license (GNU LGPL) which comes with this package. */
 
 simgrid::smpi::Group smpi_MPI_GROUP_EMPTY;
 
-namespace simgrid{
-namespace smpi{
+namespace simgrid::smpi {
 
 Group::Group(const Group* origin)
 {
   if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) {
-    // FIXME: cheinrich: There is no such thing as an index any more; the two maps should be removed
-    rank_to_pid_map_   = origin->rank_to_pid_map_;
-    pid_to_rank_map_   = origin->pid_to_rank_map_;
-    rank_to_actor_map_ = origin->rank_to_actor_map_;
-    actor_to_rank_map_ = origin->actor_to_rank_map_;
+    rank_to_pid_map_ = origin->rank_to_pid_map_;
+    pid_to_rank_map_ = origin->pid_to_rank_map_;
   }
 }
 
@@ -29,11 +25,8 @@ void Group::set_mapping(aid_t pid, int rank)
   if (0 <= rank && rank < size()) {
     if (static_cast<size_t>(pid) >= pid_to_rank_map_.size())
       pid_to_rank_map_.resize(pid + 1, MPI_UNDEFINED);
-    rank_to_pid_map_[rank]   = pid;
-    pid_to_rank_map_[pid]    = rank;
-    s4u::Actor* actor        = s4u::Actor::by_pid(pid).get();
-    rank_to_actor_map_[rank] = actor;
-    actor_to_rank_map_.insert({actor, rank});
+    rank_to_pid_map_[rank] = pid;
+    pid_to_rank_map_[pid]  = rank;
   }
 }
 
@@ -50,32 +43,11 @@ int Group::rank(aid_t pid) const
   return res;
 }
 
-aid_t Group::actor_pid(int rank) const
+aid_t Group::actor(int rank) const
 {
   return (0 <= rank && rank < size()) ? rank_to_pid_map_[rank] : -1;
 }
 
-s4u::Actor* Group::actor(int rank) const
-{
-  s4u::Actor* actor = (0 <= rank && rank < size()) ? rank_to_actor_map_[rank] : nullptr;
-  aid_t pid         = actor_pid(rank);
-  xbt_assert(actor == nullptr || pid == actor->get_pid(), "pid = %ld, actor->get_pid() = %ld", pid, actor->get_pid());
-  xbt_assert(actor != nullptr || pid == -1, "pid = %ld", pid);
-  return actor;
-}
-
-int Group::rank(s4u::Actor* actor) const
-{
-  auto iterator = actor_to_rank_map_.find(actor);
-  //I'm not in the communicator ... but maybe my parent is ?
-  if (iterator == actor_to_rank_map_.end())
-    iterator = actor_to_rank_map_.find(s4u::Actor::by_pid(actor->get_ppid()).get());
-  int res = (iterator == actor_to_rank_map_.end()) ? MPI_UNDEFINED : (*iterator).second;
-  int rank2 = rank(actor->get_pid());
-  xbt_assert(res == rank2, "res = %d, rank2 = %d", res, rank2);
-  return res;
-}
-
 void Group::ref()
 {
   refcount_++;
@@ -100,7 +72,7 @@ int Group::compare(const Group* group2) const
     result = MPI_UNEQUAL;
   } else {
     for (int i = 0; i < size(); i++) {
-      int rank = group2->rank(actor_pid(i));
+      int rank = group2->rank(actor(i));
       if (rank == MPI_UNDEFINED) {
         result = MPI_UNEQUAL;
         break;
@@ -122,7 +94,7 @@ int Group::incl(int n, const int* ranks, MPI_Group* newgroup) const
 
   *newgroup = new Group(n);
   for (int i = 0; i < n; i++) {
-    aid_t actor = this->actor_pid(ranks[i]);
+    aid_t actor = this->actor(ranks[i]);
     (*newgroup)->set_mapping(actor, i);
   }
   (*newgroup)->add_f();
@@ -148,7 +120,7 @@ int Group::group_union(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks2;
   for (int i = 0; i < group2->size(); i++) {
-    aid_t actor = group2->actor_pid(i);
+    aid_t actor = group2->actor(i);
     if (rank(actor) == MPI_UNDEFINED)
       ranks2.push_back(i);
   }
@@ -162,11 +134,11 @@ int Group::group_union(const Group* group2, MPI_Group* newgroup) const
   *newgroup = new Group(newsize);
   int i;
   for (i = 0; i < size(); i++) {
-    aid_t actor1 = actor_pid(i);
+    aid_t actor1 = actor(i);
     (*newgroup)->set_mapping(actor1, i);
   }
   for (int j : ranks2) {
-    aid_t actor2 = group2->actor_pid(j);
+    aid_t actor2 = group2->actor(j);
     (*newgroup)->set_mapping(actor2, i);
     i++;
   }
@@ -178,7 +150,7 @@ int Group::intersection(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks2;
   for (int i = 0; i < group2->size(); i++) {
-    aid_t actor = group2->actor_pid(i);
+    aid_t actor = group2->actor(i);
     if (rank(actor) != MPI_UNDEFINED)
       ranks2.push_back(i);
   }
@@ -189,7 +161,7 @@ int Group::difference(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks;
   for (int i = 0; i < size(); i++) {
-    aid_t actor = this->actor_pid(i);
+    aid_t actor = this->actor(i);
     if (group2->rank(actor) == MPI_UNDEFINED)
       ranks.push_back(i);
   }
@@ -241,5 +213,4 @@ MPI_Group Group::f2c(int id) {
   }
 }
 
-}
-}
+} // namespace simgrid::smpi