1 | /*! |
---|
2 | \file ep_send.hpp |
---|
3 | \since 2 may 2016 |
---|
4 | |
---|
5 | \brief Definitions of MPI send functions: MPI_Send, MPI_Ssend, MPI_Isend, MPI_Issend |
---|
6 | */ |
---|
7 | |
---|
8 | #include "ep_lib.hpp" |
---|
9 | #include <mpi.h> |
---|
10 | #include "ep_declaration.hpp" |
---|
11 | #include "ep_mpi.hpp" |
---|
12 | |
---|
13 | |
---|
14 | namespace ep_lib { |
---|
15 | |
---|
16 | |
---|
17 | int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
---|
18 | { |
---|
19 | if(!comm.is_ep) |
---|
20 | return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm)); |
---|
21 | |
---|
22 | MPI_Request request; |
---|
23 | MPI_Status status; |
---|
24 | MPI_Isend(buf, count, datatype, dest, tag, comm, &request); |
---|
25 | MPI_Wait(&request, &status); |
---|
26 | |
---|
27 | //check_sum_send(buf, count, datatype, dest, tag, comm); |
---|
28 | |
---|
29 | return 0; |
---|
30 | } |
---|
31 | |
---|
32 | |
---|
33 | int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm) |
---|
34 | { |
---|
35 | if(!comm.is_ep) |
---|
36 | { |
---|
37 | return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm)); |
---|
38 | } |
---|
39 | |
---|
40 | MPI_Request request; |
---|
41 | MPI_Status status; |
---|
42 | MPI_Issend(buf, count, datatype, dest, tag, comm, &request); |
---|
43 | MPI_Wait(&request, &status); |
---|
44 | //check_sum_send(buf, count, datatype, dest, tag, comm); |
---|
45 | return 0; |
---|
46 | } |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | |
---|
51 | |
---|
52 | int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
53 | { |
---|
54 | Debug("\nMPI_Isend with EP\n"); |
---|
55 | int src_rank; |
---|
56 | MPI_Comm_rank(comm, &src_rank); |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | if(!comm.is_ep) |
---|
61 | { |
---|
62 | ::MPI_Request mpi_request; |
---|
63 | ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
64 | |
---|
65 | request->mpi_request = mpi_request; |
---|
66 | |
---|
67 | request->ep_src = src_rank; |
---|
68 | request->ep_tag = tag; |
---|
69 | request->ep_datatype = datatype; |
---|
70 | request->type = 1; |
---|
71 | request->comm = comm; |
---|
72 | |
---|
73 | return 0; |
---|
74 | } |
---|
75 | |
---|
76 | if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request); |
---|
77 | |
---|
78 | // EP intracomm |
---|
79 | |
---|
80 | //check_sum_send(buf, count, datatype, dest, tag, comm, 1); |
---|
81 | |
---|
82 | int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first; |
---|
83 | int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; |
---|
84 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
85 | int mpi_dest = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; |
---|
86 | |
---|
87 | request->ep_src = src_rank; |
---|
88 | request->ep_tag = tag; |
---|
89 | request->ep_datatype = datatype; |
---|
90 | |
---|
91 | ::MPI_Request mpi_request; |
---|
92 | |
---|
93 | ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
94 | |
---|
95 | request->mpi_request = mpi_request; |
---|
96 | request->type = 1; // used in wait |
---|
97 | request->comm = comm; |
---|
98 | request->buf = const_cast<void*>(buf); |
---|
99 | |
---|
100 | //Message_Check(comm); |
---|
101 | |
---|
102 | return 0; |
---|
103 | } |
---|
104 | |
---|
105 | |
---|
106 | |
---|
107 | |
---|
108 | int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
109 | { |
---|
110 | Debug("\nMPI_Issend with EP\n"); |
---|
111 | |
---|
112 | int src_rank; |
---|
113 | MPI_Comm_rank(comm, &src_rank); |
---|
114 | |
---|
115 | |
---|
116 | |
---|
117 | if(!comm.is_ep) |
---|
118 | { |
---|
119 | ::MPI_Request mpi_request; |
---|
120 | ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
121 | |
---|
122 | request->mpi_request = mpi_request; |
---|
123 | request->ep_src = src_rank; |
---|
124 | request->ep_tag = tag; |
---|
125 | request->ep_datatype = datatype; |
---|
126 | request->type = 1; |
---|
127 | request->comm = comm; |
---|
128 | |
---|
129 | return 0; |
---|
130 | } |
---|
131 | |
---|
132 | if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request); |
---|
133 | |
---|
134 | // EP intracomm |
---|
135 | |
---|
136 | //check_sum_send(buf, count, datatype, dest, tag, comm, 1); |
---|
137 | |
---|
138 | int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first; |
---|
139 | int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first; |
---|
140 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
141 | int mpi_dest = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second; |
---|
142 | |
---|
143 | request->ep_src = src_rank; |
---|
144 | request->ep_tag = tag; |
---|
145 | request->ep_datatype = datatype; |
---|
146 | |
---|
147 | ::MPI_Request mpi_request; |
---|
148 | |
---|
149 | ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
150 | |
---|
151 | request->mpi_request = mpi_request; |
---|
152 | request->type = 1; // used in wait |
---|
153 | request->comm = comm; |
---|
154 | request->buf = NULL; |
---|
155 | |
---|
156 | |
---|
157 | //Message_Check(comm); |
---|
158 | |
---|
159 | return 0; |
---|
160 | } |
---|
161 | |
---|
162 | |
---|
163 | |
---|
164 | |
---|
165 | int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
166 | { |
---|
167 | Debug("MPI_Isend with intercomm\n"); |
---|
168 | |
---|
169 | //check_sum_send(buf, count, datatype, dest, tag, comm, 1); |
---|
170 | |
---|
171 | int dest_remote_ep_rank = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first; |
---|
172 | int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second; |
---|
173 | |
---|
174 | int src_ep_rank = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; |
---|
175 | int src_comm_label; |
---|
176 | |
---|
177 | src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second; |
---|
178 | |
---|
179 | |
---|
180 | |
---|
181 | |
---|
182 | //Message_Check(comm); |
---|
183 | |
---|
184 | |
---|
185 | if(dest_remote_comm_label == src_comm_label) // mpi_dest differs |
---|
186 | { |
---|
187 | int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; |
---|
188 | int ep_src_loc = comm.rank_map->at(inter_src).first; |
---|
189 | int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first; |
---|
190 | int mpi_dest = comm.rank_map->at(dest_remote_ep_rank).second; |
---|
191 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
192 | |
---|
193 | ::MPI_Request mpi_request; |
---|
194 | |
---|
195 | ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
196 | |
---|
197 | request->mpi_request = mpi_request; |
---|
198 | request->type = 1; // used in wait |
---|
199 | request->comm = comm; |
---|
200 | |
---|
201 | request->ep_src = src_ep_rank; |
---|
202 | request->ep_tag = tag; |
---|
203 | request->ep_datatype = datatype; |
---|
204 | } |
---|
205 | |
---|
206 | else // dest_remote_comm_label != src_comm_label |
---|
207 | { |
---|
208 | int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; |
---|
209 | int ep_src_loc = comm.rank_map->at(inter_src).first; |
---|
210 | int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first; |
---|
211 | int mpi_dest = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second; |
---|
212 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
213 | |
---|
214 | ::MPI_Request mpi_request; |
---|
215 | |
---|
216 | ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request); |
---|
217 | |
---|
218 | request->mpi_request = mpi_request; |
---|
219 | request->type = 1; // used in wait |
---|
220 | request->comm = comm; |
---|
221 | |
---|
222 | request->ep_src = src_ep_rank; |
---|
223 | request->ep_tag = tag; |
---|
224 | request->ep_datatype = datatype; |
---|
225 | } |
---|
226 | |
---|
227 | return 0; |
---|
228 | |
---|
229 | } |
---|
230 | |
---|
231 | |
---|
232 | int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request) |
---|
233 | { |
---|
234 | Debug("MPI_Issend with intercomm\n"); |
---|
235 | |
---|
236 | //check_sum_send(buf, count, datatype, dest, tag, comm, 1); |
---|
237 | |
---|
238 | int dest_remote_ep_rank = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first; |
---|
239 | int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second; |
---|
240 | |
---|
241 | int src_ep_rank = comm.ep_comm_ptr->intercomm->size_rank_info[0].first; |
---|
242 | int src_comm_label; |
---|
243 | |
---|
244 | for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++) |
---|
245 | { |
---|
246 | if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank) |
---|
247 | { |
---|
248 | src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second; |
---|
249 | break; |
---|
250 | } |
---|
251 | } |
---|
252 | |
---|
253 | //Message_Check(comm); |
---|
254 | |
---|
255 | |
---|
256 | if(dest_remote_comm_label == src_comm_label) // dest rank (loc, mpi) differs |
---|
257 | { |
---|
258 | int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; |
---|
259 | int ep_src_loc = comm.rank_map->at(inter_src).first; |
---|
260 | int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first; |
---|
261 | int mpi_dest = comm.rank_map->at(dest_remote_ep_rank).second; |
---|
262 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
263 | |
---|
264 | ::MPI_Request mpi_request; |
---|
265 | |
---|
266 | ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request); |
---|
267 | |
---|
268 | request->mpi_request = mpi_request; |
---|
269 | request->type = 1; // used in wait |
---|
270 | request->comm = comm; |
---|
271 | |
---|
272 | request->ep_src = src_ep_rank; |
---|
273 | request->ep_tag = tag; |
---|
274 | request->ep_datatype = datatype; |
---|
275 | } |
---|
276 | |
---|
277 | else // dest_remote_comm_label != src_comm_label |
---|
278 | { |
---|
279 | int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first; |
---|
280 | int ep_src_loc = comm.rank_map->at(inter_src).first; |
---|
281 | int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first; |
---|
282 | int mpi_dest = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second; |
---|
283 | int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc); |
---|
284 | |
---|
285 | ::MPI_Request mpi_request; |
---|
286 | |
---|
287 | ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.ep_comm_ptr->intercomm->mpi_inter_comm), &mpi_request); |
---|
288 | |
---|
289 | request->mpi_request = mpi_request; |
---|
290 | request->type = 1; // used in wait |
---|
291 | request->comm = comm; |
---|
292 | |
---|
293 | request->ep_src = src_ep_rank; |
---|
294 | request->ep_tag = tag; |
---|
295 | request->ep_datatype = datatype; |
---|
296 | } |
---|
297 | |
---|
298 | return 0; |
---|
299 | |
---|
300 | } |
---|
301 | |
---|
302 | } |
---|
303 | |
---|
304 | |
---|
305 | |
---|
306 | |
---|
307 | |
---|
308 | |
---|