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 #ifndef CHANNEL_H_INCLUDED
19 #define CHANNEL_H_INCLUDED
20 
21 #include <mpi.h>
22 #include <cassert>
23 #include <vector>
24 
26 #include "aligned_allocator_impl.h"
27 
28 // forward declaration
29 class ChannelSet;
30 
32 
50  public:
51  typedef char element_type;
52  static constexpr int max_dimension = 8;
53 
55  // Channel_communicator(const int count); //!< constructor with buffer size (count bytes)
56  virtual ~Channel_communicator();
57 
58  int start();
59  int wait();
60 
61  int send_init(int count, int idir, int ipm, void *buf);
62  int recv_init(int count, int idir, int ipm, void *buf);
63 
65  MPI_Request& get_request() { return m_request; }
66 
67 
68  private:
69 
70  MPI_Request m_request;
71  MPI_Status m_status;
72 
73  friend class Communicator_impl;
74  // friend class ChannelSet;
75 };
76 
77 
78 
79 template<typename ALLOCATOR>
80 class Channel_impl {
81  public:
83  typedef ALLOCATOR allocator_t;
84  typedef std::vector<element_type, allocator_t> container_type;
85 
86  Channel_impl() : m_buf(0), m_ptr(nullptr) { }
87  Channel_impl(const int count) : m_buf(count), m_ptr(&m_buf[0]) { }
88  // use default destructor
89  // ~Channel_impl(); //!< destructor
90 
92  inline element_type& operator[](unsigned int idx) { return m_buf[idx]; }
94  inline element_type operator[](unsigned int idx) const { return m_buf[idx]; }
96  inline element_type *ptr() const { return m_ptr; }
97 
98  // communication
99  int start() { return m_comm.start(); }
100  int wait() { return m_comm.wait(); }
101 
102  int send_init(int count, int idir, int ipm)
103  {
104  m_buf.resize(count);
105  m_ptr = &m_buf[0];
106  return m_comm.send_init(count, idir, ipm, (void *)m_ptr);
107  }
108 
109  int recv_init(int count, int idir, int ipm)
110  {
111  m_buf.resize(count);
112  m_ptr = &m_buf[0];
113  return m_comm.recv_init(count, idir, ipm, (void *)m_ptr);
114  }
115 
116  MPI_Request& get_request() { return m_comm.get_request(); }
117 
118  private:
122 };
123 
124 
125 
126 // alias
127 template<typename T>
128 constexpr int alignment_size();
129 
130 template<int ALIGNMENT>
132 
133 // instance with default allocator
135 
137 
142 class ChannelSet {
143  public:
144  ChannelSet(int nchannel = 8);
145 
146  template<typename T>
148  {
149  return append(c.get_request());
150  }
151 
152  int start();
153  int wait();
154 
155  private:
156  int append(const MPI_Request& r);
157 
158  std::vector<MPI_Request> m_array;
159  std::vector<MPI_Status> m_status;
160  unsigned int m_nreq;
161 };
162 #endif /* _CHANNEL_H_ */
Channel_impl::get_request
MPI_Request & get_request()
Definition: channel.h:116
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:147
Channel_communicator::element_type
char element_type
Definition: channel.h:51
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::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:83
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:96
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
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:84
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:102
Channel_communicator::get_request
MPI_Request & get_request()
accessor to MPI_Request
Definition: channel.h:65
Channel_impl::operator[]
element_type & operator[](unsigned int idx)
accessor to buffer
Definition: channel.h:92
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:82
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:109
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:94