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

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

save modif

File size: 4.1 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_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN);
63      int error_code = ::MPI_Wait(mpi_request, &mpi_status);
64      if (error_code != MPI_SUCCESS) {
65     
66         char error_string[BUFSIZ];
67         int length_of_error_string, error_class;
68     
69         ::MPI_Error_class(error_code, &error_class);
70         ::MPI_Error_string(error_class, error_string, &length_of_error_string);
71         printf("%s\n", error_string);
72      }
73     
74
75      status->mpi_status = new ::MPI_Status(mpi_status);
76      status->ep_src = request->ep_src;
77      status->ep_tag = request->ep_tag;
78      status->ep_datatype = request->ep_datatype;
79
80      //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
81    }
82
83    return MPI_SUCCESS;
84
85  }   /*end of mpi_wait*/
86
87
88
89
90
91
92  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
93  {
94    //int dest_rank;
95    //MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
96    //printf("proc %d enters waitall\n", dest_rank);
97
98    int finished = 0;
99    int finished_index[count];
100
101    for(int i=0; i<count; i++)
102    {
103      finished_index[i] = false;
104    }
105
106    while(finished < count)
107    {
108      for(int i=0; i<count; i++)
109      {
110        if(finished_index[i] == false) // this request has not been tested.
111        {
112          if(array_of_requests[i].type != 2) // isend or imrecv
113          {     
114            MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
115            //int tested=false;
116            //while(!tested) MPI_Test(&array_of_requests[i], &tested, &array_of_statuses[i]);
117            finished++;
118            finished_index[i] = true;
119          }
120          else // irecv
121          {
122            int flag = false;
123            MPI_Message message;
124
125            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]);
126
127            if(flag)
128            {
129              int recv_count;
130              MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &recv_count);
131              MPI_Mrecv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, &message, &array_of_statuses[i]);
132              //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);
133
134              finished++;
135              finished_index[i] = true;
136            }
137          }
138        }
139      }   
140    }
141    //printf("proc %d exits waitall\n", dest_rank);
142    return MPI_SUCCESS;
143  }  /* end of mpi_waitall*/
144
145
146}
Note: See TracBrowser for help on using the repository browser.