source: XIOS/dev/branch_openmp/extern/ep_dev/ep_recv.cpp @ 1518

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

optimisation partially finished. To do : special case for intercomm_create and intercomm_merge

File size: 5.3 KB
Line 
1/*!
2   \file ep_recv.cpp
3   \since 2 may 2016
4
5   \brief Definitions of MPI receive functions: MPI_Recv, MPI_Mrecv, MPI_Irecv, MPI_Imrecv
6 */
7
8
9#include "ep_lib.hpp"
10#include <mpi.h>
11#include "ep_declaration.hpp"
12#include "ep_mpi.hpp"
13
14using namespace std;
15
16extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests;
17#pragma omp threadprivate(EP_PendingRequests)
18
19namespace ep_lib
20{
21
22  int MPI_Recv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
23  {
24
25    if(!comm->is_ep) return MPI_Recv_mpi(buf, count, datatype, src, tag, comm, status);
26   
27    Debug("MPI_Recv with EP");
28
29    MPI_Request request;
30    MPI_Irecv(buf, count, datatype, src, tag, comm, &request);
31    MPI_Wait(&request, status);
32
33    return 0;
34  }
35
36 
37
38
39  int MPI_Irecv(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
40  {
41    if(!comm->is_ep) return MPI_Irecv_mpi(buf, count, datatype, src, tag, comm, request);
42   
43    Debug("MPI_Irecv with EP");
44    int dest_rank;
45    MPI_Comm_rank(comm, &dest_rank);
46   
47    *request = new ep_request;   
48    memcheck("new " << *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
49
50    (*request)->mpi_request = new ::MPI_Request;
51    memcheck("new " << (*request)->mpi_request << " : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
52   
53    (*request)->buf = buf;
54    (*request)->comm = comm;
55    (*request)->type = 2;
56    (*request)->state = 0;
57   
58
59    (*request)->ep_src = src;
60    (*request)->ep_tag = tag;
61    (*request)->ep_datatype = datatype;
62 
63    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
64
65    EP_PendingRequests->push_back(request); 
66    int ep_rank = comm->ep_comm_ptr->size_rank_info[0].first;
67    memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());   
68
69#ifdef _showinfo
70    if(comm->is_intercomm)
71    {
72      int ep_dest_loc  = comm->ep_rank_map->at(dest_rank).first;
73      int ep_src_loc = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).first;
74      int mpi_tag     = tag_combine(tag, ep_src_loc, ep_dest_loc);
75      int mpi_dest    = comm->ep_comm_ptr->intercomm->intercomm_rank_map->at(src).second.first;
76
77      printf("Irecv : 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);
78    }                                                         
79#endif                                     
80
81    return Request_Check();
82  }
83 
84  int MPI_Mrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Status *status)
85  {
86    Debug("MPI_Mrecv with MPI/EP");
87
88    status->mpi_status = new ::MPI_Status;
89    memcheck("new " << status->mpi_status << " : in ep_lib::MPI_Mrecv, status->mpi_status = new ::MPI_Status");
90   
91    ::MPI_Mrecv(buf, count, to_mpi_type(datatype), static_cast< ::MPI_Message* >((*message)->mpi_message), to_mpi_status_ptr(*status));
92
93   
94    status->ep_src = (*message)->ep_src;
95    status->ep_datatype = datatype;
96    status->ep_tag = (*message)->ep_tag;
97
98    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Mrecv, delete (*message)->mpi_message");
99    delete (*message)->mpi_message;
100
101#ifdef _check_sum
102    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
103#endif
104
105    return Request_Check();
106  }
107
108
109  int MPI_Imrecv(void *buf, int count, MPI_Datatype datatype, MPI_Message *message, MPI_Request *request)
110  {
111    Debug("MPI_Imrecv with MPI/EP");
112
113    (*request)->type = 3;
114    (*request)->ep_datatype = datatype;
115    (*request)->ep_tag = (*message)->ep_tag;
116    (*request)->ep_src = (*message)->ep_src;
117       
118    ::MPI_Imrecv(buf, count, to_mpi_type(datatype), to_mpi_message_ptr(*message), to_mpi_request_ptr(*request));               
119   
120    memcheck("delete " << (*message)->mpi_message << " : in ep_lib::MPI_Imrecv, delete (*message)->mpi_message");
121    delete (*message)->mpi_message;
122
123#ifdef _check_sum
124    check_sum_recv(buf, count, datatype, message->ep_src, message->ep_tag);
125#endif
126
127   
128    return Request_Check();
129  }
130
131
132   int MPI_Recv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Status *status)
133  {
134    Debug("MPI_Recv with MPI");
135    status->ep_src = src;
136    status->ep_tag = tag;
137    status->ep_datatype = datatype;
138   
139    return ::MPI_Recv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_status_ptr(*status)); 
140  }
141 
142  int MPI_Irecv_mpi(void *buf, int count, MPI_Datatype datatype, int src, int tag, MPI_Comm comm, MPI_Request *request)
143  {
144    Debug("MPI_Irecv with MPI");
145    int dest_rank;
146    MPI_Comm_rank(comm, &dest_rank);
147   
148    *request = new ep_request;
149    memcheck("new "<< *request <<" : in ep_lib::MPI_Irecv, *request = new ep_request");
150
151    (*request)->mpi_request = new ::MPI_Request;
152    memcheck("new "<< (*request)->mpi_request <<" : in ep_lib::MPI_Irecv, (*request)->mpi_request = new ::MPI_Request");
153     
154    (*request)->ep_src = src;
155    (*request)->ep_datatype = datatype;
156    (*request)->type = 2;
157    (*request)->ep_tag = tag;
158   
159    return ::MPI_Irecv(buf, count, to_mpi_type(datatype), src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, to_mpi_comm(comm->mpi_comm), to_mpi_request_ptr(*request));
160  }
161}
162
163
164
Note: See TracBrowser for help on using the repository browser.