Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use the init-statement to declare variables inside the if statement (sonar).
[simgrid.git] / src / smpi / mpi / smpi_group.cpp
index 76c752a..86a3403 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2021. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2022. 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. */
@@ -16,22 +16,18 @@ namespace 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
-    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_;
   }
 }
 
-void Group::set_mapping(s4u::Actor* actor, int rank)
+void Group::set_mapping(aid_t pid, int rank)
 {
   if (0 <= rank && rank < size()) {
-    aid_t pid = actor->get_pid();
     if (static_cast<size_t>(pid) >= pid_to_rank_map_.size())
       pid_to_rank_map_.resize(pid + 1, MPI_UNDEFINED);
-    pid_to_rank_map_[pid]    = rank;
-    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;
   }
 }
 
@@ -48,21 +44,9 @@ int Group::rank(aid_t pid) const
   return res;
 }
 
-s4u::Actor* Group::actor(int rank) const
+aid_t Group::actor(int rank) const
 {
-  if (0 <= rank && rank < size())
-    return rank_to_actor_map_[rank];
-  else
-    return nullptr;
-}
-
-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());
-  return (iterator == actor_to_rank_map_.end()) ? MPI_UNDEFINED : (*iterator).second;
+  return (0 <= rank && rank < size()) ? rank_to_pid_map_[rank] : -1;
 }
 
 void Group::ref()
@@ -111,7 +95,7 @@ int Group::incl(int n, const int* ranks, MPI_Group* newgroup) const
 
   *newgroup = new Group(n);
   for (int i = 0; i < n; i++) {
-    s4u::Actor* actor = this->actor(ranks[i]);
+    aid_t actor = this->actor(ranks[i]);
     (*newgroup)->set_mapping(actor, i);
   }
   (*newgroup)->add_f();
@@ -137,7 +121,7 @@ int Group::group_union(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks2;
   for (int i = 0; i < group2->size(); i++) {
-    s4u::Actor* actor = group2->actor(i);
+    aid_t actor = group2->actor(i);
     if (rank(actor) == MPI_UNDEFINED)
       ranks2.push_back(i);
   }
@@ -151,11 +135,11 @@ int Group::group_union(const Group* group2, MPI_Group* newgroup) const
   *newgroup = new Group(newsize);
   int i;
   for (i = 0; i < size(); i++) {
-    s4u::Actor* actor1 = actor(i);
+    aid_t actor1 = actor(i);
     (*newgroup)->set_mapping(actor1, i);
   }
   for (int j : ranks2) {
-    s4u::Actor* actor2 = group2->actor(j);
+    aid_t actor2 = group2->actor(j);
     (*newgroup)->set_mapping(actor2, i);
     i++;
   }
@@ -167,7 +151,7 @@ int Group::intersection(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks2;
   for (int i = 0; i < group2->size(); i++) {
-    s4u::Actor* actor = group2->actor(i);
+    aid_t actor = group2->actor(i);
     if (rank(actor) != MPI_UNDEFINED)
       ranks2.push_back(i);
   }
@@ -178,7 +162,7 @@ int Group::difference(const Group* group2, MPI_Group* newgroup) const
 {
   std::vector<int> ranks;
   for (int i = 0; i < size(); i++) {
-    s4u::Actor* actor = this->actor(i);
+    aid_t actor = this->actor(i);
     if (group2->rank(actor) == MPI_UNDEFINED)
       ranks.push_back(i);
   }