Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
add a name() to all F2C objects.
[simgrid.git] / src / smpi / include / smpi_comm.hpp
1 /* Copyright (c) 2010-2021. 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
17 namespace simgrid{
18 namespace smpi{
19
20 class Comm : public F2C, public Keyval{
21   friend Topo;
22   MPI_Group group_;
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   int is_uniform_       = 1;
31   int* non_uniform_map_ = nullptr; // set if smp nodes have a different number of processes allocated
32   int is_blocked_       = 0;       // 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_;
39   MPI_Errhandler errhandler_ = MPI_ERRORS_ARE_FATAL;
40   MPI_Errhandler* errhandlers_ = nullptr; //for MPI_COMM_WORLD only
41
42 public:
43   static std::unordered_map<int, smpi_key_elem> keyvals_;
44   static int keyval_id_;
45
46   Comm() = default;
47   Comm(MPI_Group group, MPI_Topology topo, bool smp = false, int id = MPI_UNDEFINED);
48   int dup(MPI_Comm* newcomm);
49   int dup_with_info(MPI_Info info, MPI_Comm* newcomm);
50   MPI_Group group();
51   MPI_Topology topo() const { return topo_; }
52   void set_topo(MPI_Topology topo){topo_=topo;}
53   int size() const;
54   int rank() const;
55   int id() const;
56   void get_name(char* name, int* len) const;
57   std::string name() const;
58   void set_name(const char* name);
59   MPI_Info info();
60   void set_info( MPI_Info info);
61   MPI_Errhandler errhandler();
62   void set_errhandler( MPI_Errhandler errhandler);
63   void set_leaders_comm(MPI_Comm leaders);
64   void set_intra_comm(MPI_Comm leaders) { intra_comm_ = leaders; };
65   int* get_non_uniform_map() const;
66   int* get_leaders_map() const;
67   MPI_Comm get_leaders_comm() const;
68   MPI_Comm get_intra_comm() const;
69   MPI_Comm find_intra_comm(int* leader);
70   bool is_uniform() const;
71   bool is_blocked() const;
72   bool is_smp_comm() const;
73   MPI_Comm split(int color, int key);
74   void cleanup_smp();
75   void ref();
76   static void unref(MPI_Comm comm);
77   static void destroy(MPI_Comm comm);
78   void init_smp();
79
80   static void free_f(int id);
81   static Comm* f2c(int);
82
83   static int keyval_create(MPI_Comm_copy_attr_function* copy_fn, MPI_Comm_delete_attr_function* delete_fn, int* keyval,
84                            void* extra_state);
85   static int keyval_free(int* keyval);
86   static void keyval_cleanup();
87
88   void add_rma_win(MPI_Win win);
89   void remove_rma_win(MPI_Win win);
90   void finish_rma_calls() const;
91   MPI_Comm split_type(int type, int key, const Info* info);
92 };
93
94 } // namespace smpi
95 } // namespace simgrid
96
97 #endif