1 /* Copyright (c) 2010-2022. The SimGrid Team.
2 * All rights reserved. */
4 /* This program is free software; you can redistribute it and/or modify it
5 * under the terms of the license (GNU LGPL) which comes with this package. */
7 #ifndef SMPI_GROUP_HPP_INCLUDED
8 #define SMPI_GROUP_HPP_INCLUDED
10 #include "smpi_f2c.hpp"
11 #include <smpi/smpi.h>
18 class Group : public F2C{
19 /* This is actually a map from int to aid_t. We could use std::map here, but looking up a value there costs
20 * O(log(n)). For a vector, this costs O(1). We hence go with the vector.
22 std::vector<aid_t> rank_to_pid_map_;
23 std::vector<int> pid_to_rank_map_;
25 int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
27 int incl(const std::vector<int>& ranks, MPI_Group* newgroup) const;
28 int excl(const std::vector<bool>& excl_map, MPI_Group* newgroup) const;
32 explicit Group(int size) : rank_to_pid_map_(size, -1), pid_to_rank_map_(size, MPI_UNDEFINED) {}
33 explicit Group(const Group* origin);
35 void set_mapping(aid_t pid, int rank);
36 int rank(aid_t pid) const;
37 aid_t actor(int rank) const;
38 std::string name() const override {return std::string("MPI_Group");}
40 static void unref(MPI_Group group);
41 int size() const { return static_cast<int>(rank_to_pid_map_.size()); }
42 int compare(const Group* group2) const;
43 int incl(int n, const int* ranks, MPI_Group* newgroup) const;
44 int excl(int n, const int* ranks, MPI_Group* newgroup) const;
45 int group_union(const Group* group2, MPI_Group* newgroup) const;
46 int intersection(const Group* group2, MPI_Group* newgroup) const;
47 int difference(const Group* group2, MPI_Group* newgroup) const;
48 int range_incl(int n, const int ranges[][3], MPI_Group* newgroup) const;
49 int range_excl(int n, const int ranges[][3], MPI_Group* newgroup) const;
51 static Group* f2c(int id);