Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
d16e40d15b546bb1848dd7126162d6fb0a225ee1
[simgrid.git] / src / smpi / include / smpi_group.hpp
1 /* Copyright (c) 2010-2021. The SimGrid Team.
2  * All rights reserved.                                                     */
3
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. */
6
7 #ifndef SMPI_GROUP_HPP_INCLUDED
8 #define SMPI_GROUP_HPP_INCLUDED
9
10 #include "smpi_f2c.hpp"
11 #include <smpi/smpi.h>
12 #include <map>
13 #include <vector>
14
15 namespace simgrid{
16 namespace smpi{
17
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.
21    */
22   std::vector<aid_t> rank_to_pid_map_;
23   std::vector<int> pid_to_rank_map_;
24
25   int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
26
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;
29
30 public:
31   Group() = default;
32   explicit Group(int size) : rank_to_pid_map_(size, -1), pid_to_rank_map_(size, MPI_UNDEFINED) {}
33   explicit Group(const Group* origin);
34
35   void set_mapping(aid_t pid, int rank);
36   int rank(aid_t pid) const;
37   aid_t actor_pid(int rank) const;
38   std::string name() const override {return std::string("MPI_Group");}
39   void ref();
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;
50
51   static Group* f2c(int id);
52 };
53 }
54 }
55
56 #endif