geopm  3.1.1.dev272+gdfb40a8d
GEOPM - Global Extensible Open Power Manager
Comm.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2015 - 2024 Intel Corporation
3  * SPDX-License-Identifier: BSD-3-Clause
4  */
5 
6 #ifndef COMM_HPP_INCLUDE
7 #define COMM_HPP_INCLUDE
8 
9 #include <memory>
10 #include <vector>
11 #include <string>
12 #include <list>
13 
14 #include "geopm/PluginFactory.hpp"
15 
16 namespace geopm
17 {
19  class Comm
20  {
21  public:
26  };
27 
30  };
31 
33  Comm() = default;
34  Comm(const Comm &other) = default;
35  Comm &operator=(const Comm &other) = default;
37  virtual ~Comm() = default;
39  static std::vector<std::string> comm_names(void);
40  static std::unique_ptr<Comm> make_unique(const std::string &comm_name);
41  static std::unique_ptr<Comm> make_unique(void);
42  virtual std::shared_ptr<Comm> split() const = 0;
43  virtual std::shared_ptr<Comm> split(int color, int key) const = 0;
44  virtual std::shared_ptr<Comm> split(const std::string &tag, int split_type) const = 0;
45  virtual std::shared_ptr<Comm> split(std::vector<int> dimensions, std::vector<int> periods, bool is_reorder) const = 0;
46  virtual std::shared_ptr<Comm> split_cart(std::vector<int> dimensions) const = 0;
47 
48  virtual bool comm_supported(const std::string &description) const = 0;
49 
50  // Introspection
55  virtual int cart_rank(const std::vector<int> &coords) const = 0;
57  virtual int rank(void) const = 0;
59  virtual int num_rank(void) const = 0;
67  virtual void dimension_create(int num_ranks, std::vector<int> &dimension) const = 0;
71  virtual void free_mem(void *base) = 0;
77  virtual void alloc_mem(size_t size, void **base) = 0;
86  virtual size_t window_create(size_t size, void *base) = 0;
90  virtual void window_destroy(size_t window_id) = 0;
101  virtual void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const = 0;
107  virtual void window_unlock(size_t window_id, int rank) const = 0;
115  virtual void coordinate(int rank, std::vector<int> &coord) const = 0;
116  virtual std::vector<int> coordinate(int rank) const = 0;
117  // Collective communication
119  virtual void barrier(void) const = 0;
127  virtual void broadcast(void *buffer, size_t size, int root) const = 0;
132  virtual bool test(bool is_true) const = 0;
141  virtual void reduce_max(double *send_buf, double *recv_buf, size_t count, int root) const = 0;
153  virtual void gather(const void *send_buf, size_t send_size, void *recv_buf,
154  size_t recv_size, int root) const = 0;
168  virtual void gatherv(const void *send_buf, size_t send_size, void *recv_buf,
169  const std::vector<size_t> &recv_sizes, const std::vector<off_t> &rank_offset, int root) const = 0;
181  virtual void window_put(const void *send_buf, size_t send_size, int rank, off_t disp, size_t window_id) const = 0;
185  virtual void tear_down(void) = 0;
186  static const std::string M_PLUGIN_PREFIX;
187  };
188 
189  class CommFactory : public PluginFactory<Comm>
190  {
191  public:
192  CommFactory();
193  virtual ~CommFactory() = default;
194  };
195 
196  CommFactory &comm_factory(void);
197 
198 
199  class NullComm : public Comm
200  {
201  public:
202  NullComm();
203  virtual ~NullComm() = default;
204  std::shared_ptr<Comm> split() const override;
205  std::shared_ptr<Comm> split(int color, int key) const override;
206  std::shared_ptr<Comm> split(const std::string &tag, int split_type) const override;
207  std::shared_ptr<Comm> split(std::vector<int> dimensions, std::vector<int> periods, bool is_reorder) const override;
208  std::shared_ptr<Comm> split_cart(std::vector<int> dimensions) const override;
209 
210  bool comm_supported(const std::string &description) const override;
211  int cart_rank(const std::vector<int> &coords) const override;
212  int rank(void) const override;
213  int num_rank(void) const override;
214  void dimension_create(int num_ranks, std::vector<int> &dimension) const override;
215  void free_mem(void *base) override;
216  void alloc_mem(size_t size, void **base) override;
217  size_t window_create(size_t size, void *base) override;
218  void window_destroy(size_t window_id) override;
219  void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const override;
220  void window_unlock(size_t window_id, int rank) const override;
221  void coordinate(int rank, std::vector<int> &coord) const override;
222  std::vector<int> coordinate(int rank) const override;
223  void barrier(void) const override;
224  void broadcast(void *buffer, size_t size, int root) const override;
225  bool test(bool is_true) const override;
226  void reduce_max(double *send_buf, double *recv_buf, size_t count, int root) const override;
227  void gather(const void *send_buf, size_t send_size, void *recv_buf,
228  size_t recv_size, int root) const override;
229  void gatherv(const void *send_buf, size_t send_size, void *recv_buf,
230  const std::vector<size_t> &recv_sizes, const std::vector<off_t> &rank_offset, int root) const override;
231  void window_put(const void *send_buf, size_t send_size, int rank, off_t disp, size_t window_id) const override;
232  void tear_down(void) override;
233  static std::string plugin_name(void);
234  static std::unique_ptr<Comm> make_plugin();
235  private:
236  mutable std::vector<std::vector<char> > m_window_buffers;
237  std::map<char *, int> m_window_buffers_map;
238  };
239 }
240 
241 #endif
Definition: Comm.hpp:190
CommFactory()
Definition: Comm.cpp:26
virtual ~CommFactory()=default
Abstract base class for interprocess communication in geopm.
Definition: Comm.hpp:20
virtual void free_mem(void *base)=0
Free memory that was allocated for message passing and RMA.
virtual void tear_down(void)=0
Clean up resources held by the comm. This allows static global objects to be cleaned up before the de...
virtual int rank(void) const =0
Process rank within communicator.
virtual int num_rank(void) const =0
Number of ranks in the communicator.
static const std::string M_PLUGIN_PREFIX
Definition: Comm.hpp:186
virtual void broadcast(void *buffer, size_t size, int root) const =0
Broadcast a message to all ranks.
virtual void gather(const void *send_buf, size_t send_size, void *recv_buf, size_t recv_size, int root) const =0
Gather bytes from all processes.
virtual void window_put(const void *send_buf, size_t send_size, int rank, off_t disp, size_t window_id) const =0
Perform message passing or RMA.
virtual std::shared_ptr< Comm > split_cart(std::vector< int > dimensions) const =0
virtual void window_unlock(size_t window_id, int rank) const =0
End epoch for message passing and RMA.
virtual void alloc_mem(size_t size, void **base)=0
Allocate memory for message passing and RMA.
virtual std::shared_ptr< Comm > split(int color, int key) const =0
static std::vector< std::string > comm_names(void)
Definition: Comm.cpp:50
virtual void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const =0
Begin epoch for message passing and RMA.
virtual void window_destroy(size_t window_id)=0
Destroy window for message passing and RMA.
m_comm_split_type_e
Definition: Comm.hpp:22
@ M_NUM_COMM_SPLIT_TYPE
Definition: Comm.hpp:25
@ M_COMM_SPLIT_TYPE_PPN1
Definition: Comm.hpp:23
@ M_COMM_SPLIT_TYPE_SHARED
Definition: Comm.hpp:24
virtual bool comm_supported(const std::string &description) const =0
static std::unique_ptr< Comm > make_unique(void)
Definition: Comm.cpp:62
virtual void coordinate(int rank, std::vector< int > &coord) const =0
Coordinate in Cartesian grid for specified rank.
m_split_color_e
Definition: Comm.hpp:28
@ M_SPLIT_COLOR_UNDEFINED
Definition: Comm.hpp:29
virtual void barrier(void) const =0
Barrier for all ranks.
virtual ~Comm()=default
Default destructor.
virtual size_t window_create(size_t size, void *base)=0
Create window for message passing and RMA.
Comm & operator=(const Comm &other)=default
virtual void gatherv(const void *send_buf, size_t send_size, void *recv_buf, const std::vector< size_t > &recv_sizes, const std::vector< off_t > &rank_offset, int root) const =0
Gather bytes into specified location from all processes.
virtual int cart_rank(const std::vector< int > &coords) const =0
Process rank within Cartesian communicator.
Comm()=default
Constructor for global communicator.
virtual std::shared_ptr< Comm > split(std::vector< int > dimensions, std::vector< int > periods, bool is_reorder) const =0
virtual void dimension_create(int num_ranks, std::vector< int > &dimension) const =0
Populate vector of optimal dimensions given the number of ranks the communicator.
virtual std::vector< int > coordinate(int rank) const =0
Comm(const Comm &other)=default
virtual bool test(bool is_true) const =0
Test whether or not all ranks in the communicator present the same input and return true/false accord...
virtual std::shared_ptr< Comm > split(const std::string &tag, int split_type) const =0
virtual std::shared_ptr< Comm > split() const =0
virtual void reduce_max(double *send_buf, double *recv_buf, size_t count, int root) const =0
Reduce distributed messages across all ranks using specified operation, store result on all ranks.
Definition: Comm.hpp:200
int rank(void) const override
Process rank within communicator.
Definition: Comm.cpp:117
void gatherv(const void *send_buf, size_t send_size, void *recv_buf, const std::vector< size_t > &recv_sizes, const std::vector< off_t > &rank_offset, int root) const override
Gather bytes into specified location from all processes.
Definition: Comm.cpp:273
NullComm()
Definition: Comm.cpp:67
static std::unique_ptr< Comm > make_plugin()
Definition: Comm.cpp:102
void broadcast(void *buffer, size_t size, int root) const override
Broadcast a message to all ranks.
Definition: Comm.cpp:237
size_t window_create(size_t size, void *base) override
Create window for message passing and RMA.
Definition: Comm.cpp:153
int num_rank(void) const override
Number of ranks in the communicator.
Definition: Comm.cpp:122
void reduce_max(double *send_buf, double *recv_buf, size_t count, int root) const override
Reduce distributed messages across all ranks using specified operation, store result on all ranks.
Definition: Comm.cpp:250
void window_unlock(size_t window_id, int rank) const override
End epoch for message passing and RMA.
Definition: Comm.cpp:198
void alloc_mem(size_t size, void **base) override
Allocate memory for message passing and RMA.
Definition: Comm.cpp:141
int cart_rank(const std::vector< int > &coords) const override
Process rank within Cartesian communicator.
Definition: Comm.cpp:112
void barrier(void) const override
Barrier for all ranks.
Definition: Comm.cpp:232
void gather(const void *send_buf, size_t send_size, void *recv_buf, size_t recv_size, int root) const override
Gather bytes from all processes.
Definition: Comm.cpp:259
void dimension_create(int num_ranks, std::vector< int > &dimension) const override
Populate vector of optimal dimensions given the number of ranks the communicator.
Definition: Comm.cpp:127
virtual ~NullComm()=default
void window_put(const void *send_buf, size_t send_size, int rank, off_t disp, size_t window_id) const override
Perform message passing or RMA.
Definition: Comm.cpp:287
void window_destroy(size_t window_id) override
Destroy window for message passing and RMA.
Definition: Comm.cpp:170
std::shared_ptr< Comm > split() const override
Definition: Comm.cpp:73
void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const override
Begin epoch for message passing and RMA.
Definition: Comm.cpp:186
void coordinate(int rank, std::vector< int > &coord) const override
Coordinate in Cartesian grid for specified rank.
Definition: Comm.cpp:213
bool test(bool is_true) const override
Test whether or not all ranks in the communicator present the same input and return true/false accord...
Definition: Comm.cpp:245
std::shared_ptr< Comm > split_cart(std::vector< int > dimensions) const override
Definition: Comm.cpp:93
void free_mem(void *base) override
Free memory that was allocated for message passing and RMA.
Definition: Comm.cpp:136
void tear_down(void) override
Clean up resources held by the comm. This allows static global objects to be cleaned up before the de...
Definition: Comm.cpp:305
bool comm_supported(const std::string &description) const override
Definition: Comm.cpp:107
static std::string plugin_name(void)
Definition: Comm.cpp:97
Definition: Accumulator.cpp:12
CommFactory & comm_factory(void)
Definition: Comm.cpp:37