1 /* Copyright (c) 2010-2023. 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>
15 namespace simgrid::smpi {
17 class Group : public F2C{
18 /* This is actually a map from int to aid_t. We could use std::map here, but looking up a value there costs
19 * O(log(n)). For a vector, this costs O(1). We hence go with the vector.
21 std::vector<aid_t> rank_to_pid_map_;
22 std::vector<int> pid_to_rank_map_;
24 int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
26 int incl(const std::vector<int>& ranks, MPI_Group* newgroup) const;
27 int excl(const std::vector<bool>& excl_map, MPI_Group* newgroup) const;
31 explicit Group(int size) : rank_to_pid_map_(size, -1), pid_to_rank_map_(size, MPI_UNDEFINED) {}
32 explicit Group(const Group* origin);
34 void set_mapping(aid_t pid, int rank);
35 int rank(aid_t pid) const;
36 aid_t actor(int rank) const;
37 std::string name() const override { return "MPI_Group"; }
39 static void unref(MPI_Group group);
40 int size() const { return static_cast<int>(rank_to_pid_map_.size()); }
41 int compare(const Group* group2) const;
42 int incl(int n, const int* ranks, MPI_Group* newgroup) const;
43 int excl(int n, const int* ranks, MPI_Group* newgroup) const;
44 int group_union(const Group* group2, MPI_Group* newgroup) const;
45 int intersection(const Group* group2, MPI_Group* newgroup) const;
46 int difference(const Group* group2, MPI_Group* newgroup) const;
47 int range_incl(int n, const int ranges[][3], MPI_Group* newgroup) const;
48 int range_excl(int n, const int ranges[][3], MPI_Group* newgroup) const;
50 static Group* f2c(int id);
52 } // namespace simgrid::smpi