source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_send.cpp @ 1287

Last change on this file since 1287 was 1287, checked in by yushan, 6 years ago

EP updated

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