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

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

save dev. recv_test OK

File size: 9.9 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
54
55  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
56  {
57    Debug("\nMPI_Isend with EP\n");
58    int src_rank;
59    MPI_Comm_rank(comm, &src_rank);
60
61   
62
63    if(!comm.is_ep)
64    {
65      ::MPI_Request mpi_request;
66      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
67      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
68
69      request->mpi_request = mpi_request;
70
71      request->ep_src = src_rank;
72      request->ep_tag = tag;
73      request->ep_datatype = datatype;
74      request->type = 1;
75      request->comm = comm;
76
77      return 0;
78    }
79
80    if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
81
82    // EP intracomm
83
84    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
85
86    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
87    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
88    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc);
89    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
90
91    request->ep_src  = src_rank;
92    request->ep_tag  = tag;
93    request->ep_datatype = datatype;
94
95    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
96    ::MPI_Request mpi_request;
97
98    ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
99
100    request->mpi_request = mpi_request;
101    request->type = 1;          // used in wait
102    request->comm = comm;
103    request->buf = const_cast<void*>(buf);
104
105    Message_Check(comm);
106
107    return 0;
108  }
109
110
111
112
113  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
114  {
115    Debug("\nMPI_Issend with EP\n");
116
117    int src_rank;
118    MPI_Comm_rank(comm, &src_rank);
119
120   
121
122    if(!comm.is_ep)
123    {
124      ::MPI_Request mpi_request;
125      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
126      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype> (datatype), dest, tag, mpi_comm, &mpi_request);
127
128      request->mpi_request = mpi_request;
129      request->ep_src = src_rank;
130      request->ep_tag = tag;
131      request->ep_datatype = datatype;
132      request->type = 1;
133      request->comm = comm;
134
135      return 0;
136    }
137
138    if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
139
140    // EP intracomm
141
142    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
143
144    int ep_src_loc = comm.ep_comm_ptr->size_rank_info[1].first;
145    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
146    int mpi_tag                 = tag_combine(tag, ep_src_loc, ep_dest_loc);
147    int mpi_dest        = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
148   
149    request->ep_src = src_rank;
150    request->ep_tag = tag;
151    request->ep_datatype = datatype;
152
153    ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm> (comm.mpi_comm);
154    ::MPI_Request mpi_request;
155
156    ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype>(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
157
158    request->mpi_request = mpi_request;
159    request->type = 1;          // used in wait
160    request->comm = comm;
161    request->buf = NULL;
162   
163
164    //Message_Check(comm);
165
166    return 0;
167  }
168
169
170
171  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
172  {
173    Debug("MPI_Isend with intercomm\n");
174
175    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
176
177    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
178    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
179
180    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
181    int src_comm_label;
182
183    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
184    {
185      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
186      {
187        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
188        break;
189      }
190    }
191
192    Message_Check(comm);
193
194
195    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
196    {
197      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
198      int ep_src_loc = comm.rank_map->at(inter_src).first;
199      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
200      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
201      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
202
203      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
204      ::MPI_Request mpi_request;
205 
206      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
207
208      request->mpi_request = mpi_request;
209      request->type = 1;                // used in wait
210      request->comm = comm;
211
212      request->ep_src = src_ep_rank;
213      request->ep_tag = tag;
214      request->ep_datatype = datatype;
215    }
216
217    else   // dest_remote_comm_label != src_comm_label
218    { 
219      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
220      int ep_src_loc = comm.rank_map->at(inter_src).first;
221      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
222      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
223      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
224
225      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
226      ::MPI_Request mpi_request;
227
228      ::MPI_Isend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
229
230      request->mpi_request = mpi_request;
231      request->type = 1;                // used in wait
232      request->comm = comm;
233   
234      request->ep_src = src_ep_rank;
235      request->ep_tag = tag;
236      request->ep_datatype = datatype;
237    }
238
239    return 0;
240
241  }
242
243
244  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
245  {
246    Debug("MPI_Issend with intercomm\n");
247
248    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
249
250    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
251    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
252
253    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
254    int src_comm_label;
255
256    for(int i=0; i<comm.ep_comm_ptr->intercomm->local_rank_map->size(); i++)
257    {
258      if(comm.ep_comm_ptr->intercomm->local_rank_map->at(i).first == src_ep_rank)
259      {
260        src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(i).second;
261        break;
262      }
263    }
264
265    Message_Check(comm);
266
267
268    if(dest_remote_comm_label == src_comm_label)       // dest rank (loc, mpi) differs
269    {
270      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
271      int ep_src_loc = comm.rank_map->at(inter_src).first;
272      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
273      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
274      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
275
276      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm > (comm.mpi_comm);
277      ::MPI_Request mpi_request;
278 
279      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
280
281      request->mpi_request = mpi_request;
282      request->type = 1;                // used in wait
283      request->comm = comm;
284
285      request->ep_src = src_ep_rank;
286      request->ep_tag = tag;
287      request->ep_datatype = datatype;
288    }
289
290    else   // dest_remote_comm_label != src_comm_label
291    { 
292      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
293      int ep_src_loc = comm.rank_map->at(inter_src).first;
294      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
295      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
296      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
297
298      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.ep_comm_ptr->intercomm->mpi_inter_comm);
299      ::MPI_Request mpi_request;
300
301      ::MPI_Issend(buf, count, static_cast< ::MPI_Datatype >(datatype), mpi_dest, mpi_tag, mpi_comm, &mpi_request);
302
303      request->mpi_request = mpi_request;
304      request->type = 1;                // used in wait
305      request->comm = comm;
306   
307      request->ep_src = src_ep_rank;
308      request->ep_tag = tag;
309      request->ep_datatype = datatype;
310    }
311
312    return 0;
313
314  }
315}
316
317
318
319
320
Note: See TracBrowser for help on using the repository browser.