source: XIOS/dev/branch_yushan_merged/extern/src_ep_dev/ep_wait.cpp @ 1147

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

bug fixed in MPI_Gather(v)

File size: 3.4 KB
Line 
1/*!
2  \file ep_wait.cpp
3  \since 2 may 2016
4
5  \brief Definitions of MPI wait function: MPI_Wait, MPI_Waitall, MPI_Waitsome, MPI_Waitany
6  */
7
8#include "ep_lib.hpp"
9#include <mpi.h>
10#include "ep_declaration.hpp"
11
12using namespace std;
13
14
15
16namespace ep_lib
17{       
18
19  int MPI_Wait(MPI_Request *request, MPI_Status *status)
20  {
21
22    if(request->type == 1)
23    {
24      ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
25      ::MPI_Status mpi_status;
26      ::MPI_Wait(&mpi_request, &mpi_status);
27
28      status->mpi_status = &mpi_status;
29      status->ep_src = request->ep_src;
30      status->ep_tag = request->ep_tag;
31      status->ep_datatype = request->ep_datatype;
32
33      return 0;
34    }
35
36    if(request->type == 2)
37    {
38      int flag = false;
39      MPI_Message message;
40
41      while(!flag)
42      {
43        Message_Check(request->comm);
44        #pragma omp flush
45        MPI_Improbe(request->ep_src, request->ep_tag, request->comm, &flag, &message, status);
46      }
47
48      int count;
49      MPI_Get_count(status, request->ep_datatype, &count);
50      MPI_Mrecv(request->buf, count, request->ep_datatype, &message, status);
51      status->ep_datatype = request->ep_datatype;
52
53      //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
54
55      return 0;
56    }
57
58    if(request->type == 3)
59    {
60      ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
61      ::MPI_Status mpi_status;
62      ::MPI_Wait(&mpi_request, &mpi_status);
63
64      status->mpi_status = new ::MPI_Status(mpi_status);
65      status->ep_src = request->ep_src;
66      status->ep_tag = request->ep_tag;
67      status->ep_datatype = request->ep_datatype;
68
69      //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
70    }
71
72    return MPI_SUCCESS;
73
74  }   /*end of mpi_wait*/
75
76
77
78
79
80
81  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
82  {
83    int dest_rank;
84    MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
85
86    int finished = 0;
87    int finished_index[count];
88
89    for(int i=0; i<count; i++)
90    {
91      finished_index[i] = false;
92    }
93
94    while(finished < count)
95    {
96      for(int i=0; i<count; i++)
97      {
98        if(finished_index[i] == false) // this request has not been tested.
99        {
100          if(array_of_requests[i].type != 2) // isend or imrecv
101          {     
102            MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
103            finished++;
104            finished_index[i] = true;
105          }
106          else // irecv
107          {
108            int flag = false;
109            MPI_Message message;
110
111            MPI_Improbe(array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, &flag, &message, &array_of_statuses[i]);
112
113            if(flag)
114            {
115              int recv_count;
116              MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &recv_count);
117              MPI_Mrecv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, &message, &array_of_statuses[i]);
118              //check_sum_recv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, array_of_requests[i].ep_src, array_of_requests[i].ep_tag, array_of_requests[i].comm, 2);
119
120              finished++;
121              finished_index[i] = true;
122            }
123          }
124        }
125      }   
126    }
127    return MPI_SUCCESS;
128  }  /* end of mpi_waitall*/
129
130
131}
Note: See TracBrowser for help on using the repository browser.