class Group : public F2C{
private:
int size_;
- int *rank_to_index_map_;
+ /* This is actually a map from int to int. 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.
+ */
+ std::vector<int> rank_to_index_map_;
std::unordered_map<int, int> index_to_rank_map_;
int refcount_;
public:
Group::Group()
{
size_ = 0; /* size */
- rank_to_index_map_ = nullptr; /* rank_to_index_map_ */
refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
}
-Group::Group(int n) : size_(n)
+Group::Group(int n) : size_(n), rank_to_index_map_(size_)
{
- rank_to_index_map_ = new int[size_];
refcount_ = 1;
for (int i = 0; i < size_; i++)
rank_to_index_map_[i] = MPI_UNDEFINED;
{
if (origin != MPI_GROUP_NULL && origin != MPI_GROUP_EMPTY) {
size_ = origin->size();
- rank_to_index_map_ = new int[size_];
refcount_ = 1;
- for (int i = 0; i < size_; i++) {
- rank_to_index_map_[i] = origin->rank_to_index_map_[i];
- }
+ rank_to_index_map_ = origin->rank_to_index_map_;
for (auto const& elm : origin->index_to_rank_map_) {
index_to_rank_map_.insert({elm.first, elm.second});
Group::~Group()
{
- delete[] rank_to_index_map_;
+ rank_to_index_map_.clear();
}
void Group::set_mapping(int index, int rank)