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

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

EP update all

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