Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
In smpi::Group, 'index' is in fact a PID. Fix type and rename.
[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 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.
21    */
22   std::vector<s4u::Actor*> rank_to_actor_map_;
23   std::map<s4u::Actor*, int> actor_to_rank_map_;
24   std::vector<int> pid_to_rank_map_;
25
26   int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
27
28   int incl(const std::vector<int>& ranks, MPI_Group* newgroup) const;
29   int excl(const std::vector<bool>& excl_map, MPI_Group* newgroup) const;
30
31 public:
32   Group() = default;
33   explicit Group(int size) : rank_to_actor_map_(size, nullptr), pid_to_rank_map_(size, MPI_UNDEFINED) {}
34   explicit Group(const Group* origin);
35
36   void set_mapping(s4u::Actor* actor, int rank);
37   int rank(aid_t pid) const;
38   s4u::Actor* actor(int rank) const;
39   std::string name() const override {return std::string("MPI_Group");}
40   int rank(s4u::Actor* process) const;
41   void ref();
42   static void unref(MPI_Group group);
43   int size() const { return static_cast<int>(rank_to_actor_map_.size()); }
44   int compare(const Group* group2) const;
45   int incl(int n, const int* ranks, MPI_Group* newgroup) const;
46   int excl(int n, const int* ranks, MPI_Group* newgroup) const;
47   int group_union(const Group* group2, MPI_Group* newgroup) const;
48   int intersection(const Group* group2, MPI_Group* newgroup) const;
49   int difference(const Group* group2, MPI_Group* newgroup) const;
50   int range_incl(int n, const int ranges[][3], MPI_Group* newgroup) const;
51   int range_excl(int n, const int ranges[][3], MPI_Group* newgroup) const;
52
53   static Group* f2c(int id);
54 };
55 }
56 }
57
58 #endif