geopm  3.1.1.dev296+g5916b956
GEOPM - Global Extensible Open Power Manager
MPIComm.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 MPICOMM_HPP_INCLUDE
7 #define MPICOMM_HPP_INCLUDE
8 
9 #include <memory>
10 #include <set>
11 #include <vector>
12 #include <string>
13 #include "Comm.hpp"
14 #ifndef GEOPM_TEST
15 #include <mpi.h>
16 #endif
17 
18 namespace geopm
19 {
22  class MPIComm : public Comm
23  {
24  public:
25  MPIComm();
26  MPIComm(const MPIComm &other) = delete;
27  MPIComm &operator=(const MPIComm &other) = delete;
28  MPIComm(MPI_Comm in_comm);
29  MPIComm(const MPIComm *in_comm);
30  MPIComm(const MPIComm *in_comm, std::vector<int> dimension, std::vector<int> periods, bool is_reorder);
31  MPIComm(const MPIComm *in_comm, int color, int key);
32  MPIComm(const MPIComm *in_comm, const std::string &tag, bool &is_ctl);
33  MPIComm(const MPIComm *in_comm, const std::string &tag);
34  MPIComm(const MPIComm *in_comm, const std::string &tag, int split_type);
35  virtual ~MPIComm();
36 
37  static std::string plugin_name(void);
38  static std::unique_ptr<Comm> make_plugin(void);
39  static MPIComm &comm_world(void);
40 
41  virtual std::shared_ptr<Comm> split() const override;
42  virtual std::shared_ptr<Comm> split(int color, int key) const override;
43  virtual std::shared_ptr<Comm> split(const std::string &tag, int split_type) const override;
44  virtual std::shared_ptr<Comm> split(std::vector<int> dimensions, std::vector<int> periods, bool is_reorder) const override;
45  virtual std::shared_ptr<Comm> split_cart(std::vector<int> dimensions) const override;
46 
47  virtual bool comm_supported(const std::string &description) const override;
48 
49  virtual int cart_rank(const std::vector<int> &coords) const override;
50  virtual int rank(void) const override;
51  virtual int num_rank(void) const override;
52  virtual void dimension_create(int num_ranks, std::vector<int> &dimension) const override;
53  virtual void alloc_mem(size_t size, void **base) override;
54  virtual void free_mem(void *base) override;
55  virtual size_t window_create(size_t size, void *base) override;
56  virtual void window_destroy(size_t window_id) override;
57  virtual void coordinate(int rank, std::vector<int> &coord) const override;
58  virtual std::vector<int> coordinate(int rank) const override;
59  virtual void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const override;
60  virtual void window_unlock(size_t window_id, int rank) const override;
61  virtual void barrier(void) const override;
62  virtual void broadcast(void *buffer, size_t size, int root) const override;
63  virtual bool test(bool is_true) const override;
64  virtual void reduce_max(double *send_buf, double *recv_buf, size_t count, int root) const override;
65  virtual void gather(const void *send_buf, size_t send_size, void *recv_buf,
66  size_t recv_size, int root) const override;
67  virtual void gatherv(const void *send_buf, size_t send_size, void *recv_buf,
68  const std::vector<size_t> &recv_sizes, const std::vector<off_t> &rank_offset, int root) const override;
69  virtual void window_put(const void *send_buf, size_t send_size, int rank, off_t disp, size_t window_id) const override;
70 
71  void tear_down(void) override;
72  protected:
73  void check_window(size_t window_id) const;
74  bool is_valid() const;
75  MPI_Comm m_comm;
76  size_t m_maxdims;
77  std::set<size_t> m_windows;
78  const std::string m_name;
79  bool m_is_torn_down = false;
80  };
81 }
82 
83 #endif
Abstract base class for interprocess communication in geopm.
Definition: Comm.hpp:20
Implementation of the Comm interface using MPI as the underlying communication mechanism.
Definition: MPIComm.hpp:23
MPIComm(const MPIComm &other)=delete
virtual int rank(void) const override
Process rank within communicator.
Definition: MPIComm.cpp:218
std::set< size_t > m_windows
Definition: MPIComm.hpp:77
virtual std::shared_ptr< Comm > split() const override
Definition: MPIComm.cpp:179
bool is_valid() const
Definition: MPIComm.cpp:250
const std::string m_name
Definition: MPIComm.hpp:78
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: MPIComm.cpp:166
size_t m_maxdims
Definition: MPIComm.hpp:76
virtual std::shared_ptr< Comm > split_cart(std::vector< int > dimensions) const override
Definition: MPIComm.cpp:199
virtual void window_unlock(size_t window_id, int rank) const override
End epoch for message passing and RMA.
Definition: MPIComm.cpp:288
virtual 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: MPIComm.cpp:346
bool m_is_torn_down
Definition: MPIComm.hpp:79
virtual 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: MPIComm.cpp:336
static MPIComm & comm_world(void)
Definition: MPIComm.cpp:51
virtual int num_rank(void) const override
Number of ranks in the communicator.
Definition: MPIComm.cpp:227
MPIComm & operator=(const MPIComm &other)=delete
static std::string plugin_name(void)
Definition: MPIComm.cpp:57
MPIComm(const MPIComm *in_comm, const std::string &tag)
virtual size_t window_create(size_t size, void *base) override
Create window for message passing and RMA.
Definition: MPIComm.cpp:268
static std::unique_ptr< Comm > make_plugin(void)
Definition: MPIComm.cpp:62
virtual void broadcast(void *buffer, size_t size, int root) const override
Broadcast a message to all ranks.
Definition: MPIComm.cpp:321
MPIComm()
Definition: MPIComm.cpp:67
virtual void coordinate(int rank, std::vector< int > &coord) const override
Coordinate in Cartesian grid for specified rank.
Definition: MPIComm.cpp:294
virtual void window_destroy(size_t window_id) override
Destroy window for message passing and RMA.
Definition: MPIComm.cpp:275
MPI_Comm m_comm
Definition: MPIComm.hpp:75
void check_window(size_t window_id) const
Definition: MPIComm.cpp:241
virtual void free_mem(void *base) override
Free memory that was allocated for message passing and RMA.
Definition: MPIComm.cpp:263
virtual bool comm_supported(const std::string &description) const override
Definition: MPIComm.cpp:204
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 override
Gather bytes into specified location from all processes.
Definition: MPIComm.cpp:354
virtual 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: MPIComm.cpp:236
virtual void alloc_mem(size_t size, void **base) override
Allocate memory for message passing and RMA.
Definition: MPIComm.cpp:258
virtual void barrier(void) const override
Barrier for all ranks.
Definition: MPIComm.cpp:314
virtual int cart_rank(const std::vector< int > &coords) const override
Process rank within Cartesian communicator.
Definition: MPIComm.cpp:209
virtual ~MPIComm()
Definition: MPIComm.cpp:161
virtual 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: MPIComm.cpp:379
virtual void window_lock(size_t window_id, bool is_exclusive, int rank, int assert) const override
Begin epoch for message passing and RMA.
Definition: MPIComm.cpp:282
virtual 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: MPIComm.cpp:329
Definition: Accumulator.cpp:12