Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
use previous buffer check feature in MPI checks, to crash when a buffer overflow...
[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   int size_ = 0;
20   /* This is actually a map from int to int. We could use std::map here, but looking up a value there costs O(log(n)).
21    * For a vector, this costs O(1). We hence go with the vector.
22    */
23   std::vector<s4u::Actor*> rank_to_actor_map_;
24   std::map<s4u::Actor*, int> actor_to_rank_map_;
25   std::vector<int> index_to_rank_map_;
26
27   int refcount_ = 1; /* refcount_: start > 0 so that this group never gets freed */
28
29 public:
30   Group() = default;
31   explicit Group(int size) : size_(size), rank_to_actor_map_(size, nullptr), index_to_rank_map_(size, MPI_UNDEFINED) {}
32   explicit Group(const Group* origin);
33
34   void set_mapping(s4u::Actor* actor, int rank);
35   int rank(int index);
36   s4u::Actor* actor(int rank);
37   std::string name() const override {return std::string("MPI_Group");}
38   int rank(s4u::Actor* process);
39   void ref();
40   static void unref(MPI_Group group);
41   int size() const { return size_; }
42   int compare(MPI_Group group2);
43   int incl(int n, const int* ranks, MPI_Group* newgroup);
44   int excl(int n, const int* ranks, MPI_Group* newgroup);
45   int group_union(MPI_Group group2, MPI_Group* newgroup);
46   int intersection(MPI_Group group2, MPI_Group* newgroup);
47   int difference(MPI_Group group2, MPI_Group* newgroup);
48   int range_incl(int n, int ranges[][3], MPI_Group* newgroup);
49   int range_excl(int n, int ranges[][3], MPI_Group* newgroup);
50
51   static Group* f2c(int id);
52 };
53 }
54 }
55
56 #endif