source: XIOS/dev/branch_openmp/extern/ep_dev/ep_message.cpp @ 1538

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

tests in XIOS OK (client, complete, remap, toy)

File size: 6.6 KB
RevLine 
[1381]1/*!
2   \file ep_message.cpp
3   \since 2 may 2016
4
5   \brief Definitions of MPI endpoint function: Message_Check
6 */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11#include "ep_mpi.hpp"
12
13using namespace std;
14
15extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests;
16#pragma omp threadprivate(EP_PendingRequests)
17
18namespace ep_lib
19{
[1500]20  int Request_Check()
21  {
[1503]22    if(EP_PendingRequests == 0 ) EP_PendingRequests = new std::list< MPI_Request* >;
23   
24    if(EP_PendingRequests->size() == 0) return 0;
25   
[1522]26    show_EP_PendingRequests(EP_PendingRequests);
27   
[1500]28    MPI_Status status;
29    MPI_Message *message;
30    int probed = false;
31    int recv_count = 0;
32    std::list<MPI_Request* >::iterator it;
33   
[1527]34    show_EP_PendingRequests(EP_PendingRequests);
[1500]35   
[1522]36   
[1500]37    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++)
38    { 
[1522]39      if(*(*it) == 0)
40      {
41        EP_PendingRequests->erase(it);
42       
43        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
44        it = EP_PendingRequests->begin();
45        continue;
46      }
47     
[1538]48      if((*(*it))->state == 2)
49      {
50        EP_PendingRequests->erase(it);
51       
52        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
53        it = EP_PendingRequests->begin();
54        continue;
55      }
56     
[1500]57      Message_Check(((*(*it))->comm));
58    }
[1522]59   
60   
[1381]61
[1500]62
63    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); )
64    {
[1522]65      if(*(*it) == 0)
66      {
67        EP_PendingRequests->erase(it);
68       
69        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
70        it = EP_PendingRequests->begin();
71        continue;
72      }
73     
[1538]74      if((*(*it))->state == 2)
75      {
76        EP_PendingRequests->erase(it);
77       
78        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
79        it = EP_PendingRequests->begin();
80        continue;
81      }
82     
[1527]83      if((*(*it))->probed == false)
[1522]84      {
[1503]85        #pragma omp critical (_query0)
86        {
[1532]87          MPI_Iprobe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, ((*(*it))->comm), &probed, &status);
[1503]88          if(probed)
89          {
90            message = new MPI_Message;
91            *message = new ep_message;
[1500]92       
[1503]93            memcheck("new "<< message <<" : in ep_lib::Request_Check, message = new MPI_Message");
94            memcheck("new "<< *message <<" : in ep_lib::Request_Check, *message = new ep_message");
[1500]95         
96         
[1532]97            MPI_Improbe_endpoint((*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->comm, &probed, message, &status);
[1503]98       
99          }
100        }
[1500]101     
102       
103        if(probed)
104        {
[1517]105          MPI_Get_count(&status, (*(*it))->ep_datatype, &recv_count);
[1500]106         
107          MPI_Imrecv((*(*it))->buf, recv_count, (*(*it))->ep_datatype, message, *it);
108          (*(*it))->type = 3;
[1527]109          (*(*it))->probed = true;
[1500]110
[1503]111          memcheck("delete "<< status.mpi_status <<" : in ep_lib::Request_Check, delete status.mpi_status");
112          delete status.mpi_status;         
[1500]113
[1503]114          memcheck("delete "<< *message <<" : in ep_lib::Request_Check, delete *message");
115          memcheck("delete "<< message <<" : in ep_lib::Request_Check, delete message");
116
[1500]117          delete *message;
118          delete message;
119       
120          it++;
121          continue;     
[1503]122        }             
[1500]123      }
124     
[1522]125      it++;
[1500]126    }
[1522]127   
128    show_EP_PendingRequests(EP_PendingRequests);
[1500]129  }
130 
131 
132 
[1381]133  int Message_Check(MPI_Comm comm)
134  {
[1527]135    if(comm->is_ep) return Message_Check_endpoint(comm);
[1500]136  }
137 
138 
[1527]139  int Message_Check_endpoint(MPI_Comm comm)
[1500]140  {
141   
[1381]142    int flag = true;
[1500]143    ::MPI_Status status;
[1381]144    ::MPI_Message message;
145
146    while(flag) // loop until the end of global queue
147    {
148      Debug("Message probing for intracomm\n");
[1500]149     
[1381]150      #pragma omp critical (_mpi_call)
151      {
[1500]152        ::MPI_Iprobe(MPI_ANY_SOURCE, MPI_ANY_TAG, to_mpi_comm(comm->mpi_comm), &flag, &status);
[1381]153        if(flag)
154        {
155          Debug("find message in mpi comm \n");
[1500]156          ::MPI_Mprobe(status.MPI_SOURCE, status.MPI_TAG, to_mpi_comm(comm->mpi_comm), &message, &status);
[1381]157        }
158      }
159
160     
161      if(flag)
162      {
[1500]163        MPI_Message msg = new ep_message; 
164        msg->mpi_message = new ::MPI_Message(message);
[1381]165
[1503]166        memcheck("new "<< msg <<" : in ep_lib::Message_Check, msg = new ep_message");
167        memcheck("new "<< msg->mpi_message <<" : in ep_lib::Message_Check, msg->mpi_message = new ::MPI_Message");
[1500]168             
169
170        msg->ep_tag  = bitset<15>(status.MPI_TAG >> 16).to_ulong(); 
171        int src_loc  = bitset<8> (status.MPI_TAG >> 8) .to_ulong(); 
172        int dest_loc = bitset<8> (status.MPI_TAG)           .to_ulong();
173        int src_mpi  = status.MPI_SOURCE;
[1381]174             
[1515]175        msg->ep_src  = get_ep_rank(comm, src_loc,  src_mpi); 
176
177#ifdef _showinfo
178        printf("status.MPI_TAG = %d, src_loc = %d, dest_loc = %d, ep_tag = %d\n", status.MPI_TAG, src_loc, dest_loc, msg->ep_tag);
179#endif
180
[1500]181        msg->mpi_status = new ::MPI_Status(status); 
[1503]182        memcheck("new "<< msg->mpi_status <<" : in ep_lib::Message_Check, msg->mpi_status = new ::MPI_Status");
[1381]183
184        #pragma omp critical (_query)
185        {
186          #pragma omp flush
[1500]187          comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->push_back(msg); 
[1503]188          int dest_mpi = comm->ep_comm_ptr->size_rank_info[2].first;
189          memcheck("message_queue["<<dest_mpi<<","<<dest_loc<<"]->size = "<<comm->ep_comm_ptr->comm_list[dest_loc]->ep_comm_ptr->message_queue->size());
[1381]190          #pragma omp flush
191        }
192      }
193    }
194
195    return MPI_SUCCESS;
196  }
197
[1522]198 
199  void show_EP_PendingRequests(std::list< ep_lib::MPI_Request* > * EP_PendingRequest)
200  {
201#ifdef _showinfo
202    std::list<MPI_Request* >::iterator it;
203   
204    int i=0;
205   
206    for(it = EP_PendingRequests->begin(); it!=EP_PendingRequests->end(); it++)
207    { 
208      if(*(*it) == 0)
209      {
210        EP_PendingRequests->erase(it);
211           
212        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
213        it = EP_PendingRequests->begin();
214        continue;
215      }
[1538]216     
217      if((*(*it))->state == 2)
218      {
219        EP_PendingRequests->erase(it);
220       
221        memcheck("EP_PendingRequests["<<ep_rank<<"]->size() = " << EP_PendingRequests->size());
222        it = EP_PendingRequests->begin();
223        continue;
224      }
[1522]225         
226      if((*(*it))->ep_src>6)
227        printf("EP_PendingRequests[%d] : ep_src = %d, ep_tag = %d, type = %d, state = %d, comm = %d\n", i, (*(*it))->ep_src, (*(*it))->ep_tag, (*(*it))->type, (*(*it))->state, to_mpi_comm(((*(*it))->comm)->mpi_comm));
228      i++;
229    }
230#endif
[1381]231
[1522]232  }
233
[1500]234 
[1381]235
236}
[1532]237
Note: See TracBrowser for help on using the repository browser.