1 /* Copyright (c) 2010-2021. 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 s4u::Actor*. 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<s4u::Actor*> rank_to_actor_map_;
23 std::map<s4u::Actor*, int> actor_to_rank_map_;
24 std::vector<aid_t> rank_to_pid_map_;
25 std::vector<int> pid_to_rank_map_;
27 int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
29 int incl(const std::vector<int>& ranks, MPI_Group* newgroup) const;
30 int excl(const std::vector<bool>& excl_map, MPI_Group* newgroup) const;
34 explicit Group(int size)
35 : rank_to_actor_map_(size, nullptr), rank_to_pid_map_(size, -1), pid_to_rank_map_(size, MPI_UNDEFINED)
38 explicit Group(const Group* origin);
40 void set_mapping(s4u::Actor* actor, int rank);
41 int rank(aid_t pid) const;
42 aid_t actor_pid(int rank) const;
43 s4u::Actor* actor(int rank) const;
44 std::string name() const override {return std::string("MPI_Group");}
45 int rank(s4u::Actor* process) const;
47 static void unref(MPI_Group group);
48 int size() const { return static_cast<int>(rank_to_pid_map_.size()); }
49 int compare(const Group* group2) const;
50 int incl(int n, const int* ranks, MPI_Group* newgroup) const;
51 int excl(int n, const int* ranks, MPI_Group* newgroup) const;
52 int group_union(const Group* group2, MPI_Group* newgroup) const;
53 int intersection(const Group* group2, MPI_Group* newgroup) const;
54 int difference(const Group* group2, MPI_Group* newgroup) const;
55 int range_incl(int n, const int ranges[][3], MPI_Group* newgroup) const;
56 int range_excl(int n, const int ranges[][3], MPI_Group* newgroup) const;
58 static Group* f2c(int id);