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

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

add folder for MPI EP-RMA development. Current: MPI_Win, MPI_win_create, MPI_win_fence, MPI_win_free

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#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->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->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      //printf("call mpi_send for intracomm, dest = %d, tag = %d\n", dest, tag);
37    }
38    //check_sum_send(buf, count, datatype, dest, tag, comm);
39
40    return 0;
41  }
42
43
44  int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
45  {
46    if(!comm.is_ep)
47    {
48      return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm));
49    }
50
51    MPI_Request request;
52    MPI_Status status;
53    MPI_Issend(buf, count, datatype, dest, tag, comm, &request);
54    MPI_Wait(&request, &status);
55    //check_sum_send(buf, count, datatype, dest, tag, comm);
56    return 0;
57  }
58 
59
60
61
62
63  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
64  {
65    Debug("\nMPI_Isend with EP\n");
66    int src_rank;
67    MPI_Comm_rank(comm, &src_rank);
68
69   
70
71    if(!comm.is_ep)
72    {
73      ::MPI_Request mpi_request;
74      ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
75
76      request->mpi_request = new ::MPI_Request(mpi_request);
77
78      request->ep_src = src_rank;
79      request->ep_tag = tag;
80      request->ep_datatype = datatype;
81      request->type = 1;
82      request->comm = comm;
83
84      return 0;
85    }
86
87    if(comm.is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
88
89    // EP intracomm
90
91    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
92
93    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
94    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
95    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
96    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
97
98    request->ep_src  = src_rank;
99    request->ep_tag  = tag;
100    request->ep_datatype = datatype;
101
102    ::MPI_Request mpi_request;
103
104    ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
105
106    request->mpi_request = new ::MPI_Request(mpi_request);
107    request->type = 1;    // used in wait
108    request->comm = comm;
109    request->buf = const_cast<void*>(buf);
110
111    //Message_Check(comm);
112
113    return 0;
114  }
115
116
117
118
119  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
120  {
121    Debug("\nMPI_Issend with EP\n");
122
123    int src_rank;
124    MPI_Comm_rank(comm, &src_rank);
125
126   
127
128    if(!comm.is_ep)
129    {
130      ::MPI_Request mpi_request;
131      ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
132
133      request->mpi_request = new ::MPI_Request(mpi_request);
134      request->ep_src = src_rank;
135      request->ep_tag = tag;
136      request->ep_datatype = datatype;
137      request->type = 1;
138      request->comm = comm;
139
140      return 0;
141    }
142
143    if(comm.is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
144
145    // EP intracomm
146
147    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
148
149    int ep_src_loc  = comm.ep_comm_ptr->size_rank_info[1].first;
150    int ep_dest_loc = comm.ep_comm_ptr->comm_list->rank_map->at(dest).first;
151    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
152    int mpi_dest    = comm.ep_comm_ptr->comm_list->rank_map->at(dest).second;
153   
154    request->ep_src = src_rank;
155    request->ep_tag = tag;
156    request->ep_datatype = datatype;
157
158    ::MPI_Request mpi_request;
159
160    ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
161
162    request->mpi_request = new ::MPI_Request(mpi_request);
163    request->type = 1;    // used in wait
164    request->comm = comm;
165    request->buf = NULL;
166   
167
168    //Message_Check(comm);
169
170    return 0;
171  }
172 
173
174
175
176  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
177  {
178    Debug("MPI_Isend with intercomm\n");
179
180    //check_sum_send(buf, count, datatype, dest, tag, comm, 1);
181
182    int dest_remote_ep_rank    = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).first;
183    int dest_remote_comm_label = comm.ep_comm_ptr->intercomm->remote_rank_map->at(dest).second;
184
185    int src_ep_rank    = comm.ep_comm_ptr->intercomm->size_rank_info[0].first;
186    int src_comm_label;
187
188    src_comm_label = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).second;
189
190
191   
192
193    //Message_Check(comm);
194
195
196    if(dest_remote_comm_label == src_comm_label)       // mpi_dest differs
197    {
198      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
199      int ep_src_loc = comm.rank_map->at(inter_src).first;
200      int ep_dest_loc = comm.rank_map->at(dest_remote_ep_rank).first;
201      int mpi_dest    = comm.rank_map->at(dest_remote_ep_rank).second;
202      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
203
204      ::MPI_Request mpi_request;
205 
206      ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
207
208      request->mpi_request = new ::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_Request mpi_request;
226
227      ::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);
228
229      request->mpi_request = new ::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_Request mpi_request;
276 
277      ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm.mpi_comm), &mpi_request);
278
279      request->mpi_request = new ::MPI_Request(mpi_request);
280      request->type = 1;    // used in wait
281      request->comm = comm;
282
283      request->ep_src = src_ep_rank;
284      request->ep_tag = tag;
285      request->ep_datatype = datatype;
286    }
287
288    else   // dest_remote_comm_label != src_comm_label
289    { 
290      int inter_src = comm.ep_comm_ptr->intercomm->local_rank_map->at(src_ep_rank).first;
291      int ep_src_loc = comm.rank_map->at(inter_src).first;
292      int ep_dest_loc = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).first;
293      int mpi_dest    = comm.ep_comm_ptr->intercomm->intercomm_rank_map->at(dest_remote_ep_rank).second;
294      int mpi_tag = tag_combine(tag, ep_src_loc, ep_dest_loc);
295
296      ::MPI_Request mpi_request;
297
298      ::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);
299
300      request->mpi_request = new ::MPI_Request(mpi_request);
301      request->type = 1;    // used in wait
302      request->comm = comm;
303   
304      request->ep_src = src_ep_rank;
305      request->ep_tag = tag;
306      request->ep_datatype = datatype;
307    }
308
309    return 0;
310
311  }
312 
313}
314
315
316
317
318
319
Note: See TracBrowser for help on using the repository browser.