Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Add default value for every member variable (useful with default constructor).
[simgrid.git] / src / smpi / include / smpi_comm.hpp
1 /* Copyright (c) 2010-2022. The SimGrid Team. All rights reserved.          */
2
3 /* This program is free software; you can redistribute it and/or modify it
4  * under the terms of the license (GNU LGPL) which comes with this package. */
5
6 #ifndef SMPI_COMM_HPP_INCLUDED
7 #define SMPI_COMM_HPP_INCLUDED
8
9 #include <list>
10 #include <string>
11 #include <memory>
12 #include "smpi_errhandler.hpp"
13 #include "smpi_keyvals.hpp"
14 #include "smpi_group.hpp"
15 #include "smpi_topo.hpp"
16 #include "smpi_config.hpp"
17
18 namespace simgrid::smpi {
19
20 class Comm : public F2C, public Keyval{
21   friend Topo;
22   MPI_Group group_         = MPI_GROUP_NULL;
23   SMPI_Topo_type topoType_ = MPI_INVALID_TOPO;
24   std::shared_ptr<Topo> topo_; // to be replaced by an union
25   int refcount_          = 1;
26   MPI_Comm leaders_comm_ = MPI_COMM_NULL; // inter-node communicator
27   MPI_Comm intra_comm_   = MPI_COMM_NULL; // intra-node communicator. For MPI_COMM_WORLD this can't be used, as var is
28                                           // global. Use an intracomm stored in the process data instead
29   int* leaders_map_     = nullptr;        // who is the leader of each process
30   bool is_uniform_      = true;
31   int* non_uniform_map_ = nullptr; // set if smp nodes have a different number of processes allocated
32   bool is_blocked_      = false;   // are ranks allocated on the same smp node contiguous?
33   bool is_smp_comm_     = false;   // set to false in case this is already an intra-comm or a leader-comm to avoid
34                                    // recursion
35   std::list<MPI_Win> rma_wins_; // attached windows for synchronization.
36   std::string name_;
37   MPI_Info info_ = MPI_INFO_NULL;
38   int id_                      = MPI_UNDEFINED;
39   MPI_Errhandler errhandler_ =  _smpi_cfg_default_errhandler_is_error ? MPI_ERRORS_ARE_FATAL : MPI_ERRORS_RETURN;;
40   MPI_Errhandler* errhandlers_ = nullptr; //for MPI_COMM_WORLD only
41
42   std::unordered_map<std::string, unsigned int> sent_messages_;
43   std::unordered_map<std::string, unsigned int> recv_messages_;
44   unsigned int collectives_count_ = 0;
45   std::vector<unsigned int> collectives_counts_; // for MPI_COMM_WORLD only
46
47 public:
48   static std::unordered_map<int, smpi_key_elem> keyvals_;
49   static int keyval_id_;
50
51   Comm() = default;
52   Comm(MPI_Group group, MPI_Topology topo, bool smp = false, int id = MPI_UNDEFINED);
53   int dup(MPI_Comm* newcomm);
54   int dup_with_info(MPI_Info info, MPI_Comm* newcomm);
55   MPI_Group group();
56   MPI_Topology topo() const { return topo_; }
57   void set_topo(MPI_Topology topo){topo_=topo;}
58   int size() const;
59   int rank() const;
60   int id() const;
61   void get_name(char* name, int* len) const;
62   std::string name() const override;
63   void set_name(const char* name);
64   MPI_Info info();
65   void set_info( MPI_Info info);
66   MPI_Errhandler errhandler();
67   void set_errhandler( MPI_Errhandler errhandler);
68   void set_leaders_comm(MPI_Comm leaders);
69   void set_intra_comm(MPI_Comm leaders) { intra_comm_ = leaders; };
70   int* get_non_uniform_map() const;
71   int* get_leaders_map() const;
72   MPI_Comm get_leaders_comm() const;
73   MPI_Comm get_intra_comm() const;
74   MPI_Comm find_intra_comm(int* leader);
75   bool is_uniform() const;
76   bool is_blocked() const;
77   bool is_smp_comm() const;
78   MPI_Comm split(int color, int key);
79   void cleanup_smp();
80   void ref();
81   static void unref(MPI_Comm comm);
82   static void destroy(MPI_Comm comm);
83   void init_smp();
84
85   static void free_f(int id);
86   static Comm* f2c(int);
87
88   static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
89                            void* extra_state);
90   static int keyval_free(int* keyval);
91   static void keyval_cleanup();
92
93   void add_rma_win(MPI_Win win);
94   void remove_rma_win(MPI_Win win);
95   void finish_rma_calls() const;
96   MPI_Comm split_type(int type, int key, const Info* info);
97   unsigned int get_sent_messages_count(int src, int dst, int tag);
98   void increment_sent_messages_count(int src, int dst, int tag);
99   unsigned int get_received_messages_count(int src, int dst, int tag);
100   void increment_received_messages_count(int src, int dst, int tag);
101   unsigned int get_collectives_count();
102   void increment_collectives_count();
103 };
104
105 } // namespace simgrid::smpi
106
107 #endif