source: XIOS/dev/branch_openmp/extern/ep_dev/ep_send.cpp @ 1501

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

save dev

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