Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Merge branch 'master' of framagit.org:simgrid/simgrid
[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{
19 namespace smpi{
20
21 class Comm : public F2C, public Keyval{
22   friend Topo;
23   MPI_Group group_;
24   SMPI_Topo_type topoType_ = MPI_INVALID_TOPO;
25   std::shared_ptr<Topo> topo_; // to be replaced by an union
26   int refcount_          = 1;
27   MPI_Comm leaders_comm_ = MPI_COMM_NULL; // inter-node communicator
28   MPI_Comm intra_comm_   = MPI_COMM_NULL; // intra-node communicator. For MPI_COMM_WORLD this can't be used, as var is
29                                           // global. Use an intracomm stored in the process data instead
30   int* leaders_map_     = nullptr;        // who is the leader of each process
31   int is_uniform_       = 1;
32   int* non_uniform_map_ = nullptr; // set if smp nodes have a different number of processes allocated
33   int is_blocked_       = 0;       // are ranks allocated on the same smp node contiguous ?
34   bool is_smp_comm_     = false;   // set to false in case this is already an intra-comm or a leader-comm to avoid
35                                    // recursion
36   std::list<MPI_Win> rma_wins_; // attached windows for synchronization.
37   std::string name_;
38   MPI_Info info_ = MPI_INFO_NULL;
39   int id_;
40   MPI_Errhandler errhandler_ =  _smpi_cfg_default_errhandler_is_error ? MPI_ERRORS_ARE_FATAL : MPI_ERRORS_RETURN;;
41   MPI_Errhandler* errhandlers_ = nullptr; //for MPI_COMM_WORLD only
42
43   std::unordered_map<std::string, unsigned int> sent_messages_;
44   std::unordered_map<std::string, unsigned int> recv_messages_;
45 public:
46   static std::unordered_map<int, smpi_key_elem> keyvals_;
47   static int keyval_id_;
48
49   Comm() = default;
50   Comm(MPI_Group group, MPI_Topology topo, bool smp = false, int id = MPI_UNDEFINED);
51   int dup(MPI_Comm* newcomm);
52   int dup_with_info(MPI_Info info, MPI_Comm* newcomm);
53   MPI_Group group();
54   MPI_Topology topo() const { return topo_; }
55   void set_topo(MPI_Topology topo){topo_=topo;}
56   int size() const;
57   int rank() const;
58   int id() const;
59   void get_name(char* name, int* len) const;
60   std::string name() const override;
61   void set_name(const char* name);
62   MPI_Info info();
63   void set_info( MPI_Info info);
64   MPI_Errhandler errhandler();
65   void set_errhandler( MPI_Errhandler errhandler);
66   void set_leaders_comm(MPI_Comm leaders);
67   void set_intra_comm(MPI_Comm leaders) { intra_comm_ = leaders; };
68   int* get_non_uniform_map() const;
69   int* get_leaders_map() const;
70   MPI_Comm get_leaders_comm() const;
71   MPI_Comm get_intra_comm() const;
72   MPI_Comm find_intra_comm(int* leader);
73   bool is_uniform() const;
74   bool is_blocked() const;
75   bool is_smp_comm() const;
76   MPI_Comm split(int color, int key);
77   void cleanup_smp();
78   void ref();
79   static void unref(MPI_Comm comm);
80   static void destroy(MPI_Comm comm);
81   void init_smp();
82
83   static void free_f(int id);
84   static Comm* f2c(int);
85
86   static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
87                            void* extra_state);
88   static int keyval_free(int* keyval);
89   static void keyval_cleanup();
90
91   void add_rma_win(MPI_Win win);
92   void remove_rma_win(MPI_Win win);
93   void finish_rma_calls() const;
94   MPI_Comm split_type(int type, int key, const Info* info);
95   unsigned int get_sent_messages_count(int src, int dst, int tag);
96   void increment_sent_messages_count(int src, int dst, int tag);
97   unsigned int get_received_messages_count(int src, int dst, int tag);
98   void increment_received_messages_count(int src, int dst, int tag);
99
100 };
101
102 } // namespace smpi
103 } // namespace simgrid
104
105 #endif