-/* 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. */
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_;
}
}
-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);
- rank_to_pid_map_[rank] = pid;
- 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;
}
}
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
-{
- 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;
-}
-
void Group::ref()
{
refcount_++;
*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();
{
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);
}
*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++;
}
{
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);
}
{
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);
}