source: XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_send.cpp @ 1196

Last change on this file since 1196 was 1196, checked in by yushan, 7 years ago

add request_check. test client and complete OK

File size: 14.7 KB
Line 
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
12
13namespace ep_lib {
14
15
16  int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
17  {
18    if(!comm.is_ep)
19    {
20      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
21      ::MPI_Send(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
22      return 0;
23    }
24
25    MPI_Request request;
26    MPI_Status status;
27    MPI_Isend(buf, count, datatype, dest, tag, comm, &request);
28    MPI_Wait(&request, &status);
29
30    //check_sum_send(buf, count, datatype, dest, tag, comm);
31
32    return 0;
33  }
34
35
36  int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
37  {
38    if(!comm.is_ep)
39    {
40      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
41      ::MPI_Ssend(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
42      return 0;
43    }
44
45    MPI_Request request;
46    MPI_Status status;
47    MPI_Issend(buf, count, datatype, dest, tag, comm, &request);
48    MPI_Wait(&request, &status);
49    //check_sum_send(buf, count, datatype, dest, tag, comm);
50    return 0;
51  }
52 
53  int MPI_Bsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
54  {
55    if(!comm.is_ep)
56    {
57      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
58      ::MPI_Bsend(buf, count, static_cast< ::MPI_Datatype>(datatype), dest, tag, mpi_comm);
59      return 0;
60    }
61
62    MPI_Request request;
63    MPI_Status status;
64    //MPI_Ibsend(buf, count, datatype, dest, tag, comm, &request);
65    MPI_Wait(&request, &status);
66
67    //check_sum_send(buf, count, datatype, dest, tag, comm);
68
69    return 0;
70  }
71 
72
73
74
75  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
76  {
77    Debug("\nMPI_Isend with EP\n");
78    int src_rank;
79    MPI_Comm_rank(comm, &src_rank);
80
81   
82
83    if(!comm.is_ep)
84    {
85      ::MPI_Request mpi_request;
86      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
87      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
88
89      request->mpi_request = mpi_request;
90
91      request->ep_src = src_rank;
92      request->ep_tag = tag;
93      request->ep_datatype = datatype;
94      request->type = 1;
95      request->comm = comm;
96
97      return 0;
98    }
99
100    if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
101
102    // EP intracomm
103
104    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
105
106    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
107    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
108    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc);
109    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
110
111    request->ep_src  = src_rank;
112    request->ep_tag  = tag;
113    request->ep_datatype = datatype;
114
115    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
116    ::MPI_Request mpi_request;
117
118    ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
119
120    request->mpi_request = mpi_request;
121    request->type = 1;          // used in wait
122    request->comm = comm;
123    request->buf = const_cast<void*>(buf);
124
125    //Message_Check(comm);
126
127    return 0;
128  }
129
130
131
132
133  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
134  {
135    Debug("\nMPI_Issend with EP\n");
136
137    int src_rank;
138    MPI_Comm_rank(comm, &src_rank);
139
140   
141
142    if(!comm.is_ep)
143    {
144      ::MPI_Request mpi_request;
145      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
146      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
147
148      request->mpi_request = mpi_request;
149      request->ep_src = src_rank;
150      request->ep_tag = tag;
151      request->ep_datatype = datatype;
152      request->type = 1;
153      request->comm = comm;
154
155      return 0;
156    }
157
158    if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
159
160    // EP intracomm
161
162    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
163
164    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
165    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
166    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc);
167    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
168   
169    request->ep_src = src_rank;
170    request->ep_tag = tag;
171    request->ep_datatype = datatype;
172
173    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
174    ::MPI_Request mpi_request;
175
176    ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
177
178    request->mpi_request = mpi_request;
179    request->type = 1;          // used in wait
180    request->comm = comm;
181    request->buf = NULL;
182   
183
184    //Message_Check(comm);
185
186    return 0;
187  }
188 
189  int MPI_Ibsend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
190  {
191    Debug("\nMPI_Isend with EP\n");
192    int src_rank;
193    MPI_Comm_rank(comm, &src_rank);
194
195 
196
197    if(!comm.is_ep)
198    {
199      ::MPI_Request mpi_request;
200      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
201      ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
202
203      request->mpi_request = mpi_request;
204
205      request->ep_src = src_rank;
206      request->ep_tag = tag;
207      request->ep_datatype = datatype;
208      request->type = 1;
209      request->comm = comm;
210
211      return 0;
212    }
213
214    if(comm.is_intercomm) return 0;//MPI_Ibsend_intercomm(buf, count, datatype, dest, tag, comm, request);
215
216   // EP intracomm
217
218    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
219
220    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
221    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
222    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc);
223    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
224
225    request->ep_src  = src_rank;
226    request->ep_tag  = tag;
227    request->ep_datatype = datatype;
228
229    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
230    ::MPI_Request mpi_request;
231
232    ::MPI_Ibsend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
233
234    request->mpi_request = mpi_request;
235    request->type = 1;          // used in wait
236    request->comm = comm;
237    request->buf = const_cast<void*>(buf);
238
239    //Message_Check(comm);
240
241    return 0; 
242  }
243
244
245
246  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
247  {
248    Debug("MPI_Isend with intercomm\n");
249
250    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
251
252    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
253    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
254
255    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
256    int src_comm_label;
257
258    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
259    {
260      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
261      {
262        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
263        break;
264      }
265    }
266
267    //Message_Check(comm);
268
269
270    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
271    {
272      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
273      int ep_src_loc = comm.rank_map->at(inter_src).first;
274      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
275      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
276      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
277
278      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
279      ::MPI_Request mpi_request;
280 
281      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
282
283      request->mpi_request = mpi_request;
284      request->type = 1;                // used in wait
285      request->comm = comm;
286
287      request->ep_src = src_ep_rank;
288      request->ep_tag = tag;
289      request->ep_datatype = datatype;
290    }
291
292    else   // dest_remote_comm_label != src_comm_label
293    { 
294      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
295      int ep_src_loc = comm.rank_map->at(inter_src).first;
296      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
297      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
298      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
299
300      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
301      ::MPI_Request mpi_request;
302
303      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
304
305      request->mpi_request = mpi_request;
306      request->type = 1;                // used in wait
307      request->comm = comm;
308   
309      request->ep_src = src_ep_rank;
310      request->ep_tag = tag;
311      request->ep_datatype = datatype;
312    }
313
314    return 0;
315
316  }
317
318
319  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
320  {
321    Debug("MPI_Issend with intercomm\n");
322
323    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
324
325    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
326    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
327
328    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
329    int src_comm_label;
330
331    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
332    {
333      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
334      {
335        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
336        break;
337      }
338    }
339
340    //Message_Check(comm);
341
342
343    if(dest_remote_comm_label == src_comm_label)       // dest rank (loc, mpi) differs
344    {
345      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
346      int ep_src_loc = comm.rank_map->at(inter_src).first;
347      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
348      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
349      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
350
351      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
352      ::MPI_Request mpi_request;
353 
354      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
355
356      request->mpi_request = mpi_request;
357      request->type = 1;                // used in wait
358      request->comm = comm;
359
360      request->ep_src = src_ep_rank;
361      request->ep_tag = tag;
362      request->ep_datatype = datatype;
363    }
364
365    else   // dest_remote_comm_label != src_comm_label
366    { 
367      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
368      int ep_src_loc = comm.rank_map->at(inter_src).first;
369      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
370      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
371      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
372
373      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
374      ::MPI_Request mpi_request;
375
376      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
377
378      request->mpi_request = mpi_request;
379      request->type = 1;                // used in wait
380      request->comm = comm;
381   
382      request->ep_src = src_ep_rank;
383      request->ep_tag = tag;
384      request->ep_datatype = datatype;
385    }
386
387    return 0;
388
389  }
390 
391  int MPI_Ibsend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
392  {
393    printf("MPI_Ibsend with intercomm not yet implemented\n");
394    MPI_Abort(comm, 0);
395    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
396
397    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
398    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
399
400    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
401    int src_comm_label;
402
403    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
404    {
405      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
406      {
407        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
408        break;
409      }
410    }
411
412    //Message_Check(comm);
413
414
415    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
416    {
417      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
418      int ep_src_loc = comm.rank_map->at(inter_src).first;
419      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
420      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
421      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
422
423      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
424      ::MPI_Request mpi_request;
425 
426      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
427
428      request->mpi_request = mpi_request;
429      request->type = 1;                // used in wait
430      request->comm = comm;
431
432      request->ep_src = src_ep_rank;
433      request->ep_tag = tag;
434      request->ep_datatype = datatype;
435    }
436
437    else   // dest_remote_comm_label != src_comm_label
438    { 
439      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
440      int ep_src_loc = comm.rank_map->at(inter_src).first;
441      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
442      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
443      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
444
445      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
446      ::MPI_Request mpi_request;
447
448      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
449
450      request->mpi_request = mpi_request;
451      request->type = 1;                // used in wait
452      request->comm = comm;
453   
454      request->ep_src = src_ep_rank;
455      request->ep_tag = tag;
456      request->ep_datatype = datatype;
457    }
458
459    return 0;
460
461  }
462}
463
464
465
466
467
468
Note: See TracBrowser for help on using the repository browser.