Bridge++  Ver. 2.0.2
channel.cpp
Go to the documentation of this file.
1 
14 #include "channel.h"
15 #include "layout.h"
16 #include <mpi-ext.h> // for Fujitsu extension
17 
18 
19 /*
20  std::vector version with the allocator templated
21  this class is a template independent part
22  [5 May 2022 I.Kanamori]
23  */
24 
25 //====================================================================
26 // class Channel_communicator
27 
28 //====================================================================
29 
37 int Channel_communicator::send_init(int count, int idir, int ipm, void *buf)
38 {
39  LOG;
40 
41  assert(ipm == 1 || ipm == -1);
43 
44  // m_buf.resize(count);
45 
46  int dest = (ipm == Forward) ?
48  int dir2 = 2 * idir + ((ipm == Forward) ? 0 : 1);
49  int tag = max_dimension * send_num[dir2] + dir2 + tag_offset;
50  send_num[dir2]++;
51 
52  int retv = FJMPI_Prequest_send_init(buf, sizeof(element_type) * count, MPI_BYTE, dest, tag, Communicator_impl::world(), &m_request);
53 
54  return retv;
55 }
56 
57 
58 //====================================================================
59 
67 int Channel_communicator::recv_init(int count, int idir, int ipm, void *buf)
68 {
69  LOG;
70 
71  assert(ipm == 1 || ipm == -1);
73 
74  // m_buf.resize(count);
75 
76  int src = (ipm == Forward) ?
78 
79  int dir2 = 2 * idir + ((ipm == Forward) ? 1 : 0);
80  int tag = max_dimension * recv_num[dir2] + dir2 + tag_offset;
81  recv_num[dir2]++;
82 
83  int retv = FJMPI_Prequest_recv_init(buf, sizeof(element_type) * count, MPI_BYTE, src, tag, Communicator_impl::world(), &m_request);
84 
85  return retv;
86 }
87 
88 
89 //====================================================================
91 {
92  LOG;
93 }
94 
95 
96 //====================================================================
98 {
99  LOG;
100  MPI_Request_free(&m_request);
101 }
102 
103 
104 //====================================================================
106 {
107  LOG;
108  return FJMPI_Prequest_start(&m_request);
109 }
110 
111 
112 //====================================================================
114 {
115  LOG;
116  return MPI_Wait(&m_request, &m_status);
117 }
118 
119 
120 int Channel_communicator::send_num[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
121 int Channel_communicator::recv_num[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
122 
123 //====================================================================
124 // class ChannelSet
126  : m_array(count), m_status(count), m_nreq(0)
127 {
128  LOG;
129 }
130 
131 
132 //====================================================================
133 int ChannelSet::append(const MPI_Request& r)
134 {
135  LOG;
136 
137  if (m_nreq >= m_array.size()) {
138  return MPI_ERR_BUFFER;
139  }
140  m_array[m_nreq++] = r;
141 
142  return MPI_SUCCESS;
143 }
144 
145 
146 //====================================================================
148 {
149  LOG;
150  return FJMPI_Prequest_startall(m_nreq, &m_array[0]);
151 }
152 
153 
154 //====================================================================
156 {
157  LOG;
158  // return MPI_Waitall(m_nreq, &m_array[0], (MPI_Status *)0);
159  return MPI_Waitall(m_nreq, &m_array[0], &m_status[0]);
160 }
161 
162 
163 //====================================================================
164 // Channel with defaul allocator
165 template class Channel_impl<std::allocator<char> >;
166 
167 //====================================================================
168 //============================================================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
channel.h
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_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
Channel_communicator::tag_offset
static constexpr int tag_offset
Definition: channel.h:78
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_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
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::send_num
static int send_num[8]
Definition: channel.h:75
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
layout.h
Channel_impl
Definition: channel.h:86