Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Revert "address FIXME and kill useless code"
authorFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 6 Jul 2018 10:14:18 +0000 (12:14 +0200)
committerFrederic Suter <frederic.suter@cc.in2p3.fr>
Fri, 6 Jul 2018 10:14:18 +0000 (12:14 +0200)
This reverts commit 4bfa8a32e0083bcd28a78689625c4806c2fbbf46.

src/smpi/include/smpi_group.hpp
src/smpi/mpi/smpi_group.cpp

index da9180e..eb56ba4 100644 (file)
@@ -24,6 +24,7 @@ class Group : public F2C{
      */
     std::vector<simgrid::s4u::ActorPtr> rank_to_actor_map_;
     std::map<simgrid::s4u::ActorPtr, int> actor_to_rank_map_;
+    std::vector<int> index_to_rank_map_;
 
     int refcount_;
   public:
@@ -32,6 +33,7 @@ class Group : public F2C{
     explicit Group(Group* origin);
 
     void set_mapping(simgrid::s4u::ActorPtr actor, int rank);
+    int rank(int index);
     simgrid::s4u::ActorPtr actor(int rank);
     int rank(const simgrid::s4u::ActorPtr process);
     void ref();
index 12c412c..e3eed4d 100644 (file)
@@ -25,7 +25,7 @@ Group::Group()
   refcount_          = 1;       /* refcount_: start > 0 so that this group never gets freed */
 }
 
-Group::Group(int n) : size_(n), rank_to_actor_map_(size_, nullptr)
+Group::Group(int n) : size_(n), rank_to_actor_map_(size_, nullptr), index_to_rank_map_(size_, MPI_UNDEFINED)
 {
   refcount_ = 1;
 }
@@ -35,6 +35,8 @@ Group::Group(Group* origin)
   if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) {
     size_              = origin->size();
     refcount_          = 1;
+    // FIXME: cheinrich: There is no such thing as an index any more; the two maps should be removed
+    index_to_rank_map_ = origin->index_to_rank_map_;
     rank_to_actor_map_ = origin->rank_to_actor_map_;
     actor_to_rank_map_ = origin->actor_to_rank_map_;
   }
@@ -44,6 +46,11 @@ void Group::set_mapping(simgrid::s4u::ActorPtr actor, int rank)
 {
   if (0 <= rank && rank < size_) {
     int index                = actor->get_pid();
+    if (index != MPI_UNDEFINED) {
+      if ((unsigned)index >= index_to_rank_map_.size())
+        index_to_rank_map_.resize(index + 1, MPI_UNDEFINED);
+      index_to_rank_map_[index] = rank;
+    }
 
     rank_to_actor_map_[rank] = actor;
     if (actor != nullptr) {
@@ -52,6 +59,17 @@ void Group::set_mapping(simgrid::s4u::ActorPtr actor, int rank)
   }
 }
 
+int Group::rank(int index)
+{
+  int rank;
+  if (0 <= index && (unsigned)index < index_to_rank_map_.size())
+    rank = index_to_rank_map_[index];
+  else
+    rank = MPI_UNDEFINED;
+
+  return rank;
+}
+
 simgrid::s4u::ActorPtr Group::actor(int rank) {
   if (0 <= rank && rank < size_)
     return rank_to_actor_map_[rank];