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

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

save dev

File size: 11.6 KB
RevLine 
[1381]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
[1503]14namespace ep_lib
15{
16 
[1381]17  int MPI_Send(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
18  {
[1503]19    if(!comm->is_ep)       return MPI_Send_mpi(buf, count, datatype, dest, tag, comm);
20    if(comm->is_intercomm) return MPI_Send_intercomm(buf, count, datatype, dest, tag, comm);
21   
22    Debug("\nMPI_Send with EP\n");
23   
24    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
25    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
26    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
27    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
[1381]28
[1503]29#ifdef _check_sum   
30    check_sum_send(buf, count, datatype, dest, tag, comm);
31#endif
[1381]32
[1503]33    return ::MPI_Send(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm));
[1381]34  }
35
36
37  int MPI_Ssend(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
38  {
[1503]39    if(!comm->is_ep)       return MPI_Ssend_mpi(buf, count, datatype, dest, tag, comm);
40    if(comm->is_intercomm) return MPI_Ssend_intercomm(buf, count, datatype, dest, tag, comm);
41   
42    Debug("\nMPI_Ssend with EP\n");
[1381]43
[1503]44    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
45    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
46    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
47    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
48   
49#ifdef _check_sum   
50    check_sum_send(buf, count, datatype, dest, tag, comm);
51#endif
52   
53    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm));
[1381]54  }
55 
56
57
58
59
60  int MPI_Isend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
61  {
[1503]62    if(!comm->is_ep)       return MPI_Isend_mpi(buf, count, datatype, dest, tag, comm, request);
63    if(comm->is_intercomm) return MPI_Isend_intercomm(buf, count, datatype, dest, tag, comm, request);
64
[1381]65    Debug("\nMPI_Isend with EP\n");
[1503]66   
[1381]67    int src_rank;
68    MPI_Comm_rank(comm, &src_rank);
69
70
[1503]71#ifdef _check_sum   
72    check_sum_send(buf, count, datatype, dest, tag, comm);
73#endif
[1500]74   
75    *request = new ep_request;
[1503]76    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend, *request = new ep_request");
[1381]77
[1500]78    (*request)->mpi_request = new ::MPI_Request;
[1503]79    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend, (*request)->mpi_request = new ::MPI_Request");
[1500]80   
81
82    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
[1503]83    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
[1381]84    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
[1503]85    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
[1381]86
[1500]87    (*request)->ep_src  = src_rank;
88    (*request)->ep_tag  = tag;
89    (*request)->ep_datatype = datatype;
[1381]90
[1500]91    (*request)->type = 1;    // used in wait
92    (*request)->comm = comm;
93    (*request)->buf = const_cast<void*>(buf);
[1381]94
95
[1503]96    return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
[1381]97  }
98
99
100
101
102  int MPI_Issend(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
103  {
[1503]104 
105    if(!comm->is_ep) return MPI_Issend_mpi(buf, count, datatype, dest, tag, comm, request);
106    if(comm->is_intercomm) return MPI_Issend_intercomm(buf, count, datatype, dest, tag, comm, request);
107
[1381]108    Debug("\nMPI_Issend with EP\n");
[1503]109   
[1381]110    int src_rank;
111    MPI_Comm_rank(comm, &src_rank);
112
[1503]113
114#ifdef _check_sum   
115    check_sum_send(buf, count, datatype, dest, tag, comm);
116#endif
[1381]117   
[1503]118    *request = new ep_request;
119    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend, *request = new ep_request");
[1381]120
[1503]121    (*request)->mpi_request = new ::MPI_Request;
122    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend, (*request)->mpi_request = new ::MPI_Request");
123   
[1381]124
[1503]125    int ep_src_loc  = comm->ep_comm_ptr->size_rank_info[1].first;
126    int ep_dest_loc = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).first;
127    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
128    int mpi_dest    = comm->ep_comm_ptr->comm_list[0]->ep_rank_map->at(dest).second;
[1381]129
[1503]130    (*request)->ep_src  = src_rank;
131    (*request)->ep_tag  = tag;
132    (*request)->ep_datatype = datatype;
[1381]133
[1503]134    (*request)->type = 1;    // used in wait
135    (*request)->comm = comm;
136    (*request)->buf = const_cast<void*>(buf);
137   
138    return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));   
139  }
140 
141  int MPI_Send_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
142  {
143    Debug("\nMPI_Send with MPI\n");
144    return ::MPI_Send(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm));
145  }
146 
147  int MPI_Send_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
148  {
[1515]149    Debug("\nMPI_Send_intercomm with EP\n");
[1503]150    MPI_Request request;
151    MPI_Status status;
152    MPI_Isend(buf, count, datatype, dest, tag, comm, &request);
153    MPI_Wait(&request, &status);
154    return MPI_SUCCESS;
155  }
156 
157 
158  int MPI_Ssend_mpi(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
159  {
160    Debug("\nMPI_Ssend with MPI\n");
161    return ::MPI_Ssend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm));
162  }
163 
[1381]164
[1503]165  int MPI_Ssend_intercomm(void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm)
166  {
[1515]167    Debug("\nMPI_Ssend_intercomm with EP\n");
[1503]168    MPI_Request request;
169    MPI_Status status;
170    MPI_Issend(buf, count, datatype, dest, tag, comm, &request);
171    MPI_Wait(&request, &status);
172    return MPI_SUCCESS;
173  }
174 
175  int MPI_Isend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
176  {
177    Debug("\nMPI_Isend with MPI\n");
178   
179    int src_rank;
180    MPI_Comm_rank(comm, &src_rank);
181   
182    *request = new ep_request;
[1515]183    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_mpi, *request = new ep_request");
[1381]184
[1503]185    (*request)->mpi_request = new ::MPI_Request;
[1515]186    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_mpi, (*request)->mpi_request = new ::MPI_Request");
[1503]187     
[1500]188    (*request)->ep_src = src_rank;
189    (*request)->ep_tag = tag;
190    (*request)->ep_datatype = datatype;
[1503]191    (*request)->type = 1;
[1500]192    (*request)->comm = comm;
[1381]193   
[1503]194    return ::MPI_Isend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
[1381]195  }
196 
197  int MPI_Isend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
198  {
[1515]199    Debug("\nMPI_Isend_intercomm with EP\n");
[1381]200
[1503]201#ifdef _check_sum   
202    check_sum_send(buf, count, datatype, dest, tag, comm);
203#endif
[1381]204
[1515]205    int src_comm_label  = comm->ep_comm_ptr->comm_label;
206    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
207   
208    int src_rank;
209    MPI_Comm_rank(comm, &src_rank);
[1381]210
[1515]211   
212    *request = new ep_request;
213    memcheck("new "<< *request <<" : in ep_lib::MPI_Isend_intercomm, *request = new ep_request");
[1381]214
[1515]215    (*request)->mpi_request = new ::MPI_Request;
216    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Isend_intercomm, (*request)->mpi_request = new ::MPI_Request");
217   
[1381]218
[1515]219    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
220    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
221    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
222    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
[1381]223
[1515]224#ifdef _showinfo
225    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
226#endif
227   
[1381]228
[1515]229    (*request)->ep_src  = src_rank;
230    (*request)->ep_tag  = tag;
231    (*request)->ep_datatype = datatype;
[1503]232
[1515]233    (*request)->type = 1;    // used in wait
234    (*request)->comm = comm;
235    (*request)->buf = const_cast<void*>(buf);
236
237
238    if(src_comm_label == dest_comm_label)
239    {
240      Debug("\nMPI_Isend_intercomm with EP_intracomm\n");
[1503]241      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
[1515]242    }
[1503]243
[1515]244    else
245    {
246      Debug("\nMPI_Isend_intercomm with EP_intercomm\n");
247      return ::MPI_Isend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
[1381]248    }
[1515]249  }
[1381]250
251
252
253
[1503]254  int MPI_Issend_mpi(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
255  {
256    Debug("\nMPI_Issend with MPI\n");
257   
258    int src_rank;
259    MPI_Comm_rank(comm, &src_rank);
260   
261    *request = new ep_request;
[1515]262    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_mpi, *request = new ep_request");
[1381]263
[1503]264    (*request)->mpi_request = new ::MPI_Request;
[1515]265    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_mpi, (*request)->mpi_request = new ::MPI_Request");
[1503]266     
267    (*request)->ep_src = src_rank;
268    (*request)->ep_tag = tag;
269    (*request)->ep_datatype = datatype;
270    (*request)->type = 1;
271    (*request)->comm = comm;
272   
273    return ::MPI_Issend(buf, count, to_mpi_type(datatype), dest, tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
[1381]274  }
275
276
277  int MPI_Issend_intercomm(const void *buf, int count, MPI_Datatype datatype, int dest, int tag, MPI_Comm comm, MPI_Request *request)
278  {
[1515]279    Debug("\nMPI_Issend_intercomm with EP\n");
[1381]280
[1503]281#ifdef _check_sum   
282    check_sum_send(buf, count, datatype, dest, tag, comm);
283#endif
[1381]284
[1515]285    int src_comm_label  = comm->ep_comm_ptr->comm_label;
286    int dest_comm_label = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.second;
287   
288    int src_rank;
289    MPI_Comm_rank(comm, &src_rank);
[1381]290
[1515]291   
292    *request = new ep_request;
293    memcheck("new "<< *request <<" : in ep_lib::MPI_Issend_intercomm, *request = new ep_request");
[1381]294
[1515]295    (*request)->mpi_request = new ::MPI_Request;
296    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Issend_intercomm, (*request)->mpi_request = new ::MPI_Request");
297   
[1381]298
[1515]299    int ep_src_loc  = comm->ep_rank_map->at(src_rank).first;
300    int ep_dest_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).first;
301    int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
302    int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(dest).second.first;
[1381]303
[1515]304#ifdef _showinfo
305    printf("ep_src_loc = %d, ep_dest_loc = %d, mpi_src = %d, mpi_dest = %d, mpi_tag = %d\n", ep_src_loc, ep_dest_loc, comm->ep_comm_ptr->size_rank_info[2].first, mpi_dest, mpi_tag);
306#endif
307   
308    (*request)->ep_src  = src_rank;
309    (*request)->ep_tag  = tag;
310    (*request)->ep_datatype = datatype;
[1381]311
[1515]312    (*request)->type = 1;    // used in wait
313    (*request)->comm = comm;
314    (*request)->buf = const_cast<void*>(buf);
[1503]315
[1515]316
317    if(src_comm_label == dest_comm_label)
318    {
319      Debug("\nMPI_Issend_intercomm with EP_intracomm\n");
[1503]320      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
[1381]321    }
322
[1515]323    else
324    {
325      Debug("\nMPI_Issend_intercomm with EP_intercomm\n");
326      return ::MPI_Issend(buf, count, to_mpi_type(datatype), mpi_dest, mpi_tag, to_mpi_comm(comm->ep_comm_ptr->intercomm->mpi_inter_comm), to_mpi_request_ptr(*request));
[1381]327    }
328  }
329 
330}
331
332
333
334
335
336
Note: See TracBrowser for help on using the repository browser.