From fe47dc5848b943920ecc4b49298c16787d97fddf Mon Sep 17 00:00:00 2001 From: Arnaud Giersch Date: Fri, 16 Apr 2021 22:51:42 +0200 Subject: [PATCH] Kill redundant member 'size_' from smpi::Group. --- src/smpi/include/smpi_group.hpp | 5 ++--- src/smpi/mpi/smpi_group.cpp | 29 ++++++++++++++--------------- 2 files changed, 16 insertions(+), 18 deletions(-) diff --git a/src/smpi/include/smpi_group.hpp b/src/smpi/include/smpi_group.hpp index 45edeef852..9e3aafde72 100644 --- a/src/smpi/include/smpi_group.hpp +++ b/src/smpi/include/smpi_group.hpp @@ -16,7 +16,6 @@ namespace simgrid{ namespace smpi{ class Group : public F2C{ - int size_ = 0; /* This is actually a map from int to s4u::Actor*. We could use std::map here, but looking up a value there costs * O(log(n)). For a vector, this costs O(1). We hence go with the vector. */ @@ -28,7 +27,7 @@ class Group : public F2C{ public: Group() = default; - explicit Group(int size) : size_(size), rank_to_actor_map_(size, nullptr), index_to_rank_map_(size, MPI_UNDEFINED) {} + explicit Group(int size) : rank_to_actor_map_(size, nullptr), index_to_rank_map_(size, MPI_UNDEFINED) {} explicit Group(const Group* origin); void set_mapping(s4u::Actor* actor, int rank); @@ -38,7 +37,7 @@ public: int rank(s4u::Actor* process) const; void ref(); static void unref(MPI_Group group); - int size() const { return size_; } + int size() const { return static_cast(rank_to_actor_map_.size()); } int compare(MPI_Group group2) const; int incl(int n, const int* ranks, MPI_Group* newgroup) const; int excl(int n, const int* ranks, MPI_Group* newgroup) const; diff --git a/src/smpi/mpi/smpi_group.cpp b/src/smpi/mpi/smpi_group.cpp index c3fee3cc17..b07678cf42 100644 --- a/src/smpi/mpi/smpi_group.cpp +++ b/src/smpi/mpi/smpi_group.cpp @@ -17,7 +17,6 @@ namespace smpi{ Group::Group(const Group* origin) { if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) { - size_ = origin->size(); // 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_; @@ -27,7 +26,7 @@ Group::Group(const Group* origin) void Group::set_mapping(s4u::Actor* actor, int rank) { - if (0 <= rank && rank < size_) { + if (0 <= rank && rank < size()) { int index = actor->get_pid(); if ((unsigned)index >= index_to_rank_map_.size()) index_to_rank_map_.resize(index + 1, MPI_UNDEFINED); @@ -50,7 +49,7 @@ int Group::rank(int index) const s4u::Actor* Group::actor(int rank) const { - if (0 <= rank && rank < size_) + if (0 <= rank && rank < size()) return rank_to_actor_map_[rank]; else return nullptr; @@ -85,10 +84,10 @@ int Group::compare(MPI_Group group2) const int result; result = MPI_IDENT; - if (size_ != group2->size()) { + if (size() != group2->size()) { result = MPI_UNEQUAL; } else { - for (int i = 0; i < size_; i++) { + for (int i = 0; i < size(); i++) { int rank = group2->rank(actor(i)); if (rank == MPI_UNDEFINED) { result = MPI_UNEQUAL; @@ -120,7 +119,7 @@ int Group::incl(int n, const int* ranks, MPI_Group* newgroup) const int Group::group_union(MPI_Group group2, MPI_Group* newgroup) const { - int size1 = size_; + int size1 = size(); int size2 = group2->size(); for (int i = 0; i < size2; i++) { s4u::Actor* actor = group2->actor(i); @@ -179,8 +178,8 @@ int Group::intersection(MPI_Group group2, MPI_Group* newgroup) const int Group::difference(MPI_Group group2, MPI_Group* newgroup) const { - int newsize = size_; - int size2 = size_; + int newsize = size(); + int size2 = size(); for (int i = 0; i < size2; i++) { s4u::Actor* actor = this->actor(i); int proc2 = group2->rank(actor); @@ -207,10 +206,10 @@ int Group::difference(MPI_Group group2, MPI_Group* newgroup) const int Group::excl(int n, const int* ranks, MPI_Group* newgroup) const { - int oldsize = size_; + int oldsize = size(); int newsize = oldsize - n; *newgroup = new Group(newsize); - std::vector to_exclude(size_, false); + std::vector to_exclude(size(), false); for (int i = 0; i < n; i++) to_exclude[ranks[i]] = true; int j = 0; @@ -235,7 +234,7 @@ int Group::range_incl(int n, int ranges[][3], MPI_Group* newgroup) const { std::vector to_incl; for (int i = 0; i < n; i++) - for (int j = ranges[i][0]; j >= 0 && j < size_ && is_rank_in_range(j, ranges[i][0], ranges[i][1]); + for (int j = ranges[i][0]; j >= 0 && j < size() && is_rank_in_range(j, ranges[i][0], ranges[i][1]); j += ranges[i][2]) to_incl.push_back(j); @@ -254,10 +253,10 @@ int Group::range_incl(int n, int ranges[][3], MPI_Group* newgroup) const int Group::range_excl(int n, int ranges[][3], MPI_Group* newgroup) const { - std::vector to_excl(size_, false); - int newsize = size_; + std::vector to_excl(size(), false); + int newsize = size(); for (int i = 0; i < n; i++) { - for (int j = ranges[i][0]; j >= 0 && j < size_ && is_rank_in_range(j, ranges[i][0], ranges[i][1]); + for (int j = ranges[i][0]; j >= 0 && j < size() && is_rank_in_range(j, ranges[i][0], ranges[i][1]); j += ranges[i][2]) { to_excl[j] = true; newsize--; @@ -269,7 +268,7 @@ int Group::range_excl(int n, int ranges[][3], MPI_Group* newgroup) const *newgroup = new Group(newsize); int j = 0; - for (int rank = 0; rank < size_; rank++) { + for (int rank = 0; rank < size(); rank++) { if (not to_excl[rank]) { s4u::Actor* actor = this->actor(rank); (*newgroup)->set_mapping(actor, j); -- 2.20.1