Bridge++  Ver. 2.0.2
channel.h
Go to the documentation of this file.
1 
15 /*
16  std::vector version with the allocator templated
17  [5 May 2022 I.Kanamori]
18  */
19 #ifndef CHANNEL_H_INCLUDED
20 #define CHANNEL_H_INCLUDED
21 
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 
64  private:
65  friend class Communicator_impl;
66 };
67 
68 
69 
70 template<typename ALLOCATOR>
71 class Channel_impl {
72  public:
74  typedef ALLOCATOR allocator_t;
75  typedef std::vector<element_type, allocator_t> container_type;
76 
77  Channel_impl() : m_buf(0), m_ptr(nullptr) { }
78  // Channel_impl(const int count) : m_buf(count), m_ptr(&m_buf[0]) { } //!< constructor with buffer size (count bytes)
79  // Channel_impl(void *buf)
80  // : m_buf(0),
81  // m_ptr(reinterpret_cast<element_type *>(buf))
82  // { }
83 
84  // use default destructor
85  // ~Channel_impl(); //!< destructor
86 
88  inline element_type& operator[](unsigned int idx) { return m_ptr[idx]; }
90  inline element_type operator[](unsigned int idx) const { return m_ptr[idx]; }
92  inline element_type *ptr() const { return m_ptr; }
93 
94  // communication
95  int start() { return m_comm.start(); }
96  int wait() { return m_comm.wait(); }
97 
98  int send_init(int count, int idir, int ipm)
99  {
100  m_buf.resize(count);
101  m_ptr = &m_buf[0];
102  return m_comm.send_init(count, idir, ipm, (void *)m_ptr);
103  }
104 
105  int send_init(int count, int idir, int ipm, void *buf)
106  {
107  m_ptr = (element_type *)buf;
108  return 0;
109  }
110 
111  int recv_init(int count, int idir, int ipm)
112  {
113  m_buf.resize(count);
114  m_ptr = &m_buf[0];
115  return m_comm.recv_init(count, idir, ipm, (void *)m_ptr);
116  }
117 
118  int recv_init(int count, int idir, int ipm, void *buf)
119  {
120  m_ptr = (element_type *)buf;
121  return 0;
122  }
123 
124  private:
128 };
129 
130 
131 
132 // alias
133 template<typename T>
134 constexpr int alignment_size();
135 
136 template<int ALIGNMENT>
138 
139 // instance with default allocator
141 
143 
148 class ChannelSet {
149  public:
150  ChannelSet(int nchannel = 8);
151 
152  template<typename T>
154  {
155  return append();
156  }
157 
158  int start();
159  int wait();
160 
161  private:
162  int append();
163 };
164 #endif /* _CHANNEL_H_ */
ChannelSet::wait
int wait()
collective wait
Definition: channel.cpp:155
Channel_impl::m_buf
container_type m_buf
buffer
Definition: channel.h:125
Channel_impl::send_init
int send_init(int count, int idir, int ipm, void *buf)
Definition: channel.h:105
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: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:74
Channel_communicator::Channel_communicator
Channel_communicator()
constructor.
Definition: channel.cpp:90
Channel_impl::recv_init
int recv_init(int count, int idir, int ipm, void *buf)
Definition: channel.h:118
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:92
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
Channel class for asynchronous communication.
Definition: channel.h:51
Channel_impl::container_type
std::vector< element_type, allocator_t > container_type
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:98
Channel_impl::operator[]
element_type & operator[](unsigned int idx)
accessor to buffer
Definition: channel.h:88
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:73
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:111
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:90