Bridge++  Ver. 2.0.2
channel.h
Go to the documentation of this file.
1 
14 /*
15  std::vector version with the allocator templated
16  [5 May 2022 I.Kanamori]
17  */
18 
19 #ifndef CHANNEL_H_INCLUDED
20 #define CHANNEL_H_INCLUDED
21 
22 #include <mpi.h>
23 #include <cassert>
24 #include <vector>
25 
27 #include "aligned_allocator_impl.h"
28 
29 
30 // forward declaration
31 class ChannelSet;
32 
34 
52  public:
53  typedef char element_type;
54  static constexpr int max_dimension = 8;
55 
57  // Channel_communicator(const int count); //!< constructor with buffer size (count bytes)
58  virtual ~Channel_communicator();
59 
60  int start();
61  int wait();
62 
63  int send_init(int count, int idir, int ipm, void *buf);
64  int recv_init(int count, int idir, int ipm, void *buf);
65 
67  MPI_Request& get_request() { return m_request; }
68 
69  private:
70 
71  MPI_Request m_request;
72  MPI_Status m_status;
73 
74  // offsetted not to use some t
75  static int send_num[8];
76  static int recv_num[8];
77 
78  static constexpr int tag_offset = 1000;
79 
80  friend class Communicator_impl;
81 };
82 
83 
84 
85 template<typename ALLOCATOR>
86 class Channel_impl {
87  public:
89  typedef ALLOCATOR allocator_t;
90  typedef std::vector<element_type, allocator_t> container_type;
91 
92  Channel_impl() : m_buf(0), m_ptr(nullptr) { }
93  // Channel_impl(const int count) : m_buf(count), m_ptr(&m_buf[0]) { } //!< constructor with buffer size (count bytes)
94  // use default destructor
95  // virtual ~Channel_impl(); //!< destructor
96 
98  inline element_type& operator[](unsigned int idx) { return m_buf[idx]; }
100  inline element_type operator[](unsigned int idx) const { return m_buf[idx]; }
102  inline element_type *ptr() const { return m_ptr; }
103 
104  // communication
105  int start() { return m_comm.start(); }
106  int wait() { return m_comm.wait(); }
107 
108  int send_init(int count, int idir, int ipm)
109  {
110  m_buf.resize(count);
111  m_ptr = &m_buf[0];
112  return m_comm.send_init(count, idir, ipm, (void *)&m_buf[0]);
113  }
114 
115  int recv_init(int count, int idir, int ipm)
116  {
117  m_buf.resize(count);
118  m_ptr = &m_buf[0];
119  return m_comm.recv_init(count, idir, ipm, (void *)&m_buf[0]);
120  }
121 
122  MPI_Request& get_request() { return m_comm.get_request(); }
123 
124  private:
128 };
129 
130 
131 // alias
132 template<typename T>
133 constexpr int alignment_size();
134 
135 template<int ALIGNMENT>
137 
138 // instance with default allocator
140 
141 
143 
148 class ChannelSet {
149  public:
150  ChannelSet(int nchannel = 8);
151 
152  template<typename T>
154  {
155  return append(c.get_request());
156  }
157 
158  int start();
159  int wait();
160 
161  private:
162  int append(const MPI_Request& r);
163 
164  std::vector<MPI_Request> m_array;
165  std::vector<MPI_Status> m_status;
166  unsigned int m_nreq;
167 };
168 #endif /* _CHANNEL_H_ */
Channel_impl::get_request
MPI_Request & get_request()
Definition: channel.h:122
ChannelSet::wait
int wait()
collective wait
Definition: channel.cpp:155
ChannelSet::m_nreq
unsigned int m_nreq
number of channels to hold.
Definition: channel.h:166
Channel_impl::m_buf
container_type m_buf
buffer
Definition: channel.h:125
Channel_communicator::m_status
MPI_Status m_status
handler to MPI status information
Definition: channel.h:72
Channel_communicator::m_request
MPI_Request m_request
handler to MPI persistent communication
Definition: channel.h:71
ChannelSet
ChannelSet class for a collection of channels.
Definition: channel.h:148
ChannelSet::append
int append(Channel_impl< T > &c)
Definition: channel.h:153
Channel_communicator::element_type
char element_type
Definition: channel.h:53
Communicator_impl
MPI-realisation of communicator class implementation.
Definition: communicator_mpi.h:32
ChannelSet::append
int append()
implementation of adding the channel (template independent)
Definition: channel.cpp:86
aligned_allocator_impl.h
allocator with alignment
Channel_communicator::tag_offset
static constexpr int tag_offset
Definition: channel.h:78
Channel_communicator::recv_init
int recv_init(int count, int idir, int ipm, void *buf)
Definition: channel.cpp:67
ChannelSet::ChannelSet
ChannelSet(int nchannel=8)
constructor. default number of channels is 8 for upward and downward in 4 dimensions.
Definition: channel.cpp:125
Channel_impl::allocator_t
ALLOCATOR allocator_t
Definition: channel.h:89
Channel_communicator::Channel_communicator
Channel_communicator()
constructor.
Definition: channel.cpp:90
Channel_impl::m_ptr
element_type * m_ptr
pointer to the buffer
Definition: channel.h:126
Channel_communicator::send_init
int send_init(int count, int idir, int ipm, void *buf)
Definition: channel.cpp:37
Channel_impl::ptr
element_type * ptr() const
accessor to buffer; returns pointer to the first element.
Definition: channel.h:102
AIndex_eo_qxs::idx
int idx(const int in, const int Nin, const int ist, const int Nx2, const int Ny, const int leo, const int Nvol2, const int ex)
Definition: aindex_eo.h:27
Channel_communicator::wait
int wait()
wait for completion
Definition: channel.cpp:113
ChannelSet::start
int start()
collective start
Definition: channel.cpp:147
Channel_communicator::recv_num
static int recv_num[8]
Definition: channel.h:76
ChannelSet::m_array
std::vector< MPI_Request > m_array
a collection of MPI request held in channels.
Definition: channel.h:164
ChannelSet::m_status
std::vector< MPI_Status > m_status
a collection of MPI status.
Definition: channel.h:165
Channel_communicator
Channel class for asynchronous communication.
Definition: channel.h:51
Channel_impl::container_type
std::vector< element_type, allocator_t > container_type
Definition: channel.h:90
Channel_communicator::send_num
static int send_num[8]
Definition: channel.h:75
Channel_communicator::start
int start()
start asynchronous communication
Definition: channel.cpp:105
communicator.h
Channel_impl::send_init
int send_init(int count, int idir, int ipm)
Definition: channel.h:108
Channel_communicator::get_request
MPI_Request & get_request()
accessor to MPI_Request
Definition: channel.h:67
Channel_impl::operator[]
element_type & operator[](unsigned int idx)
accessor to buffer
Definition: channel.h:98
Channel_communicator::max_dimension
static constexpr int max_dimension
Definition: channel.h:54
Channel_impl::element_type
Channel_communicator::element_type element_type
Definition: channel.h:88
Channel_impl::m_comm
Channel_communicator m_comm
template independent implementation
Definition: channel.h:127
Channel_communicator::~Channel_communicator
virtual ~Channel_communicator()
destructor
Definition: channel.cpp:97
Channel_impl::recv_init
int recv_init(int count, int idir, int ipm)
Definition: channel.h:115
alignment_size
constexpr int alignment_size()
Channel_impl
Definition: channel.h:86
Channel_impl::operator[]
element_type operator[](unsigned int idx) const
accessor to buffer
Definition: channel.h:100