source: XIOS/dev/branch_openmp/extern/src_ep_dev/ep_probe.cpp @ 1220

Last change on this file since 1220 was 1220, checked in by yushan, 7 years ago

test_remap_omp tested on ADA except two fields

File size: 3.5 KB
Line 
1#include "ep_lib.hpp"
2#include <mpi.h>
3#include "ep_declaration.hpp"
4
5namespace ep_lib
6{
7
8
9
10  int MPI_Iprobe(int src, int tag, MPI_Comm comm, int *flag, MPI_Status *status)
11  {
12    *flag = false;
13
14    if(!comm.is_ep)
15    {
16      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm >(comm.mpi_comm);
17      ::MPI_Status *mpi_status = static_cast< ::MPI_Status* >(status->mpi_status);
18      ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, mpi_comm, flag, mpi_status);
19
20      status->mpi_status = mpi_status;
21      status->ep_src = src;
22      status->ep_tag = tag;
23      return 0;
24    }
25
26    Debug("calling MPI_Iprobe EP\n");
27
28    Message_Check(comm);
29
30    #pragma omp flush
31
32    #pragma omp critical (_query)
33    if(!comm.ep_comm_ptr->message_queue->empty())
34    {
35      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
36      {
37        bool src_matched = src<0? true: it->ep_src == src;
38        bool tag_matched = tag<0? true: it->ep_tag == tag;
39       
40        if(src_matched && tag_matched)       
41        {
42          Debug("find message\n");
43          *flag = true;
44
45          ::MPI_Status mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status));
46
47          status->mpi_status = new ::MPI_Status(mpi_status);
48          status->ep_src = it->ep_src;
49          status->ep_tag = it->ep_tag;
50
51          break;
52        }
53
54      }
55    }
56
57    return 0;
58  }
59
60
61
62  int MPI_Improbe(int src, int tag, MPI_Comm comm, int *flag, MPI_Message *message, MPI_Status *status)
63  {
64    *flag = false;
65    if(!comm.is_ep)
66    {
67      Debug("calling MPI_Improbe MPI\n");
68
69      ::MPI_Comm mpi_comm = static_cast< ::MPI_Comm>(comm.mpi_comm);
70      ::MPI_Status mpi_status;
71      ::MPI_Message mpi_message;
72
73      #ifdef _openmpi
74      #pragma omp critical (_mpi_call)
75      {
76        ::MPI_Iprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, mpi_comm, flag, &mpi_status);
77        if(*flag)
78        {
79          ::MPI_Mprobe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, mpi_comm, &mpi_message, &mpi_status);
80        }
81      }
82      #elif _intelmpi
83        ::MPI_Improbe(src<0? MPI_ANY_SOURCE : src, tag<0? MPI_ANY_TAG: tag, mpi_comm, flag, &mpi_message, &mpi_status);
84      #endif
85       
86      status->mpi_status = new ::MPI_Status(mpi_status);
87      status->ep_src = src;
88      status->ep_tag = tag;
89
90      message->mpi_message = mpi_message;
91      message->ep_src = src;
92      message->ep_tag = tag;
93      return 0;
94    }
95
96   
97    //Message_Check(comm);
98
99    #pragma omp flush
100
101    #pragma omp critical (_query)
102    if(! comm.ep_comm_ptr->message_queue->empty())
103    {
104      for(Message_list::iterator it = comm.ep_comm_ptr->message_queue->begin(); it!= comm.ep_comm_ptr->message_queue->end(); ++it)
105      {
106        bool src_matched = src<0? true: it->ep_src == src;
107        bool tag_matched = tag<0? true: it->ep_tag == tag;
108       
109        if(src_matched && tag_matched)
110        {
111          *flag = true;
112
113          ::MPI_Status mpi_status;
114          mpi_status = *(static_cast< ::MPI_Status *>(it->mpi_status));
115
116          status->mpi_status = new ::MPI_Status(mpi_status);
117          status->ep_src = it->ep_src;
118          status->ep_tag = it->ep_tag;
119
120          message->mpi_message = it->mpi_message;
121          message->ep_tag = it->ep_tag;
122          message->ep_src = it->ep_src;
123
124          #pragma omp critical (_query2)
125          {             
126            delete it->mpi_status;
127            comm.ep_comm_ptr->message_queue->erase(it);
128            #pragma omp flush
129          }
130
131          break;
132        }
133
134      }
135    }
136  }
137
138}
139
Note: See TracBrowser for help on using the repository browser.