Bridge++  Ver. 1.2.x
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
channel.h
Go to the documentation of this file.
1 
14 #ifndef _CHANNEL_H_
15 #define _CHANNEL_H_
16 
17 #include "configure.h"
18 #include "defs.h"
19 
20 #include <cstdio>
21 #include <valarray>
22 #include <mpi.h>
23 #include <cassert>
24 
25 #include "communicator.h"
26 
27 static const int max_dimension = 8;
28 
29 // forward declaration
30 class ChannelSet;
31 
33 
51 class Channel {
52  public:
53  typedef char element_type;
54  typedef std::valarray<element_type> container_type;
55 
56  Channel();
57  Channel(const int count);
58  virtual ~Channel();
59 
60  int start();
61  int wait();
62 
64  inline element_type& operator[](unsigned int idx) { return m_buf[idx]; }
66  inline element_type operator[](unsigned int idx) const { return m_buf[idx]; }
68  inline const element_type *ptr() { return &m_buf[0]; }
69 
70  private:
72 
73  MPI_Request m_request;
74  MPI_Status m_status;
75 
76  friend class Communicator_impl;
77  friend class ChannelSet;
78 };
79 
81 
86 class ChannelSet {
87  public:
88  ChannelSet(int nchannel = 8);
89 
90  int append(Channel *const p);
91 
92  int start();
93  int wait();
94 
95  private:
96  std::valarray<MPI_Request> m_array;
97  unsigned int m_nreq;
98 };
99 #endif /* _CHANNEL_H_ */
std::valarray< element_type > container_type
Definition: channel.h:54
int wait()
Definition: channel.cpp:220
MPI_Status m_status
handler to MPI status information
Definition: channel.h:74
element_type operator[](unsigned int idx) const
accessor to buffer
Definition: channel.h:66
int start()
collective start
Definition: channel.cpp:141
int start()
Definition: channel.cpp:196
container_type m_buf
buffer
Definition: channel.h:71
int append(Channel *const p)
append channel to the set. there is no way to remove a channel.
Definition: channel.cpp:128
Channel class for asynchronous communication.
Definition: channel.h:16
MPI_Request m_request
handler to MPI persistent communication
Definition: channel.h:73
ChannelSet class for a collection of channels.
Definition: channel.h:86
Channel()
Definition: channel.cpp:89
unsigned int m_nreq
number of channels to hold.
Definition: channel.h:97
int wait()
collective wait
Definition: channel.cpp:148
element_type & operator[](unsigned int idx)
accessor to buffer
Definition: channel.h:64
std::valarray< MPI_Request > m_array
a collection of MPI request held in channels.
Definition: channel.h:96
static const int max_dimension
Definition: channel.h:27
static std::vector< container_type > m_buf
Definition: channel.h:29
const element_type * ptr()
accessor to buffer; returns pointer to the first element.
Definition: channel.h:68
char element_type
data transfer is byte-wise.
Definition: channel.h:53
virtual ~Channel()
Definition: channel.cpp:189
Implementation of Communicator with BGNET library.
ChannelSet(int nchannel=8)
constructor. default number of channels is 8 for upward and downward in 4 dimensions.
Definition: channel.cpp:122