Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Update copyright lines.
[simgrid.git] / src / smpi / mpi / smpi_group.cpp
index cbd973a..d6eec8f 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (c) 2010-2019. The SimGrid Team. All rights reserved.          */
+/* Copyright (c) 2010-2021. 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. */
@@ -7,9 +7,6 @@
 #include "smpi_group.hpp"
 #include "smpi_comm.hpp"
 #include <string>
-#include <xbt/log.h>
-
-XBT_LOG_NEW_DEFAULT_SUBCATEGORY(smpi_group, smpi, "Logging specific to SMPI (group)");
 
 simgrid::smpi::Group mpi_MPI_GROUP_EMPTY;
 MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY;
@@ -17,7 +14,7 @@ MPI_Group MPI_GROUP_EMPTY=&mpi_MPI_GROUP_EMPTY;
 namespace simgrid{
 namespace smpi{
 
-Group::Group(Group* origin)
+Group::Group(const Group* origin)
 {
   if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) {
     size_              = origin->size();
@@ -65,6 +62,9 @@ s4u::Actor* Group::actor(int rank)
 int Group::rank(s4u::Actor* actor)
 {
   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;
 }
 
@@ -106,7 +106,6 @@ int Group::compare(MPI_Group group2)
 
 int Group::incl(int n, const int* ranks, MPI_Group* newgroup)
 {
-  int i=0;
   if (n == 0) {
     *newgroup = MPI_GROUP_EMPTY;
   } else if (n == size_) {
@@ -115,7 +114,7 @@ int Group::incl(int n, const int* ranks, MPI_Group* newgroup)
       this->ref();
   } else {
     *newgroup = new Group(n);
-    for (i = 0; i < n; i++) {
+    for (int i = 0; i < n; i++) {
       s4u::Actor* actor = this->actor(ranks[i]); // ranks[] was passed as a param!
       (*newgroup)->set_mapping(actor, i);
     }
@@ -208,22 +207,18 @@ int Group::excl(int n, const int *ranks, MPI_Group * newgroup){
   int oldsize = size_;
   int newsize = oldsize - n;
   *newgroup = new  Group(newsize);
-  int* to_exclude = new int[size_];
-  for (int i     = 0; i < oldsize; i++)
-    to_exclude[i]=0;
-  for (int i            = 0; i < n; i++)
-    to_exclude[ranks[i]]=1;
+  std::vector<bool> to_exclude(size_, false);
+  for (int i = 0; i < n; i++)
+    to_exclude[ranks[i]] = true;
   int j = 0;
   for (int i = 0; i < oldsize; i++) {
-    if(to_exclude[i]==0){
+    if (not to_exclude[i]) {
       s4u::Actor* actor = this->actor(i);
       (*newgroup)->set_mapping(actor, j);
       j++;
     }
   }
-  delete[] to_exclude;
   return MPI_SUCCESS;
-
 }
 
 static bool is_rank_in_range(int rank, int first, int last)
@@ -320,11 +315,10 @@ int Group::range_excl(int n, int ranges[][3], MPI_Group * newgroup){
 MPI_Group Group::f2c(int id) {
   if(id == -2) {
     return MPI_GROUP_EMPTY;
-  } else if(F2C::f2c_lookup() != nullptr && id >= 0) {
-    char key[KEY_SIZE];
-    return static_cast<MPI_Group>(F2C::f2c_lookup()->at(get_key(key, id)));
+  } else if (F2C::lookup() != nullptr && id >= 0) {
+    return static_cast<MPI_Group>(F2C::lookup()->at(id));
   } else {
-    return static_cast<MPI_Group>(MPI_GROUP_NULL);
+    return MPI_GROUP_NULL;
   }
 }