Bridge++  Ver. 2.0.2
channel.cpp
Go to the documentation of this file.
1 
14 #include "channel.h"
15 #include "layout.h"
16 
17 
18 /*
19  std::vector version with the allocator templated
20  this class is a template independent part
21  [5 May 2022 I.Kanamori]
22  */
23 
24 //====================================================================
25 // class Channel_communicator
26 
27 //====================================================================
28 
36 int Channel_communicator::send_init(int count, int idir, int ipm, void *buf)
37 {
38  LOG;
39 
40  assert(ipm == 1 || ipm == -1);
42 
43  // m_buf.resize(count);
44 
46  int tag = idir + max_dimension * (((ipm == Forward) ? 0 : 1) + 2 * Communicator::nodeid());
47 
48  int retv = MPI_Send_init(buf, sizeof(element_type) * count, MPI_BYTE, dest, tag, Communicator_impl::world(), &m_request);
49 
50  return retv;
51 }
52 
53 
54 //====================================================================
55 
63 int Channel_communicator::recv_init(int count, int idir, int ipm, void *buf)
64 {
65  LOG;
66 
67  assert(ipm == 1 || ipm == -1);
69 
70  // m_buf.resize(count);
71 
73  int tag = idir + max_dimension * (((ipm == Forward) ? 1 : 0) + 2 * src);
74 
75  int retv = MPI_Recv_init(buf, sizeof(element_type) * count, MPI_BYTE, src, tag, Communicator_impl::world(), &m_request);
76 
77  return retv;
78 }
79 
80 
81 //====================================================================
83 {
84  LOG;
85 }
86 
87 
88 //====================================================================
90 {
91  LOG;
92 }
93 
94 
95 //====================================================================
97 {
98  LOG;
99  return MPI_Start(&m_request);
100 }
101 
102 
103 //====================================================================
105 {
106  LOG;
107  return MPI_Wait(&m_request, &m_status);
108 }
109 
110 
111 //====================================================================
112 // class ChannelSet
113 ChannelSet::ChannelSet(int count)
114  : m_array(count), m_status(count), m_nreq(0)
115 {
116  LOG;
117 }
118 
119 
120 //====================================================================
121 int ChannelSet::append(const MPI_Request& r)
122 {
123  LOG;
124 
125  if (m_nreq >= m_array.size()) {
126  return MPI_ERR_BUFFER;
127  }
128  m_array[m_nreq++] = r;
129 
130  return MPI_SUCCESS;
131 }
132 
133 
134 //====================================================================
135 int ChannelSet::start()
136 {
137  LOG;
138  return MPI_Startall(m_nreq, &m_array[0]);
139 }
140 
141 
142 //====================================================================
143 int ChannelSet::wait()
144 {
145  LOG;
146  // return MPI_Waitall(m_nreq, &m_array[0], (MPI_Status *)0);
147  return MPI_Waitall(m_nreq, &m_array[0], &m_status[0]);
148 }
149 
150 
151 //====================================================================
152 // Channel with defaul allocator
153 template class Channel_impl<std::allocator<char> >;
154 
155 //====================================================================
156 //============================================================END=====
Communicator_impl::Layout::m_ndim
static int m_ndim
number of dimensions.
Definition: layout.h:46
Communicator_impl::Layout::m_ipe_dn
static int * m_ipe_dn
rank of downward neighbour in directions.
Definition: layout.h:54
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
layout.h
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
Channel_communicator::element_type
char element_type
Definition: channel.h:53
ChannelSet::append
int append()
implementation of adding the channel (template independent)
Definition: channel.cpp:86
Forward
@ Forward
Definition: bridge_defs.h:35
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_communicator::Channel_communicator
Channel_communicator()
constructor.
Definition: channel.cpp:90
channel.h
Channel_communicator::send_init
int send_init(int count, int idir, int ipm, void *buf)
Definition: channel.cpp:37
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::start
int start()
start asynchronous communication
Definition: channel.cpp:105
LOG
#define LOG
Definition: bridge_defs.h:21
Channel_communicator::max_dimension
static constexpr int max_dimension
Definition: channel.h:54
Channel_communicator::~Channel_communicator
virtual ~Channel_communicator()
destructor
Definition: channel.cpp:97
Communicator_impl::Layout::m_ipe_up
static int * m_ipe_up
rank of upward neighbour in directions.
Definition: layout.h:53
Channel_impl
Definition: channel.h:86