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

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

save dev. recv_test OK

File size: 4.8 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_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN);
27      int error_code = ::MPI_Wait(&mpi_request, &mpi_status);
28      if (error_code != MPI_SUCCESS) {
29     
30         char error_string[BUFSIZ];
31         int length_of_error_string, error_class;
32     
33         ::MPI_Error_class(error_code, &error_class);
34         ::MPI_Error_string(error_class, error_string, &length_of_error_string);
35         printf("%s\n", error_string);
36      }
37
38      status->mpi_status = &mpi_status;
39      status->ep_src = request->ep_src;
40      status->ep_tag = request->ep_tag;
41      status->ep_datatype = request->ep_datatype;
42
43      return 0;
44    }
45
46    if(request->type == 2)
47    {
48      int flag = false;
49      MPI_Message message;
50
51      while(!flag)
52      {
53        Message_Check(request->comm);
54        #pragma omp flush
55        MPI_Improbe(request->ep_src, request->ep_tag, request->comm, &flag, &message, status);
56      }
57
58      int count;
59      request->type = 3;
60      MPI_Get_count(status, request->ep_datatype, &count);
61      MPI_Mrecv(request->buf, count, request->ep_datatype, &message, status);
62      status->ep_datatype = request->ep_datatype;
63
64      //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
65
66      return 0;
67    }
68
69    if(request->type == 3)
70    {
71      ::MPI_Request mpi_request = static_cast< ::MPI_Request >(request->mpi_request);
72      ::MPI_Status mpi_status;
73      ::MPI_Errhandler_set(MPI_COMM_WORLD_STD, MPI_ERRORS_RETURN);
74      int error_code = ::MPI_Wait(&mpi_request, &mpi_status);
75      if (error_code != MPI_SUCCESS) {
76     
77         char error_string[BUFSIZ];
78         int length_of_error_string, error_class;
79     
80         ::MPI_Error_class(error_code, &error_class);
81         ::MPI_Error_string(error_class, error_string, &length_of_error_string);
82         printf("%s\n", error_string);
83      }
84     
85
86      status->mpi_status = new ::MPI_Status(mpi_status);
87      status->ep_src = request->ep_src;
88      status->ep_tag = request->ep_tag;
89      status->ep_datatype = request->ep_datatype;
90
91      //check_sum_recv(request->buf, count, request->ep_datatype, request->ep_src, request->ep_tag, request->comm, 2);
92    }
93
94    return MPI_SUCCESS;
95
96  }   /*end of mpi_wait*/
97
98
99
100
101
102
103  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
104  {
105    //int dest_rank;
106    //MPI_Comm_rank(MPI_COMM_WORLD, &dest_rank);
107    //printf("proc %d enters waitall\n", dest_rank);
108
109    int finished = 0;
110    int finished_index[count];
111
112    for(int i=0; i<count; i++)
113    {
114      finished_index[i] = false;
115    }
116
117    while(finished < count)
118    {
119
120      for(int i=0; i<count; i++)
121      {
122        if(finished_index[i] == false) // this request has not been tested.
123        {
124          if(array_of_requests[i].type != 2) // isend or imrecv
125          {     
126            //MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
127            int tested;
128            MPI_Test(&array_of_requests[i], &tested, &array_of_statuses[i]);
129            if(!tested) MPI_Wait(&array_of_requests[i], &array_of_statuses[i]);
130            finished++;
131            finished_index[i] = true;
132          }
133          else // irecv
134          {
135            // parcours pending list
136            // find request in waitall
137                Message_Check(array_of_requests[i].comm);
138               // improbe + mrecv
139               // erase element in pending list
140 //             finished++;
141 //             finished_index[i] = true;
142           
143
144            int flag = false;
145            MPI_Message message;
146
147            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]);
148
149            if(flag)
150            {
151              int recv_count;
152              MPI_Get_count(&array_of_statuses[i], array_of_requests[i].ep_datatype, &recv_count);
153              MPI_Mrecv(array_of_requests[i].buf, recv_count, array_of_requests[i].ep_datatype, &message, &array_of_statuses[i]);
154              //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);
155
156              finished++;
157              finished_index[i] = true;
158            }
159          }
160        }
161      }   
162    }
163    //printf("proc %d exits waitall\n", dest_rank);
164    return MPI_SUCCESS;
165  }  /* end of mpi_waitall*/
166
167
168}
Note: See TracBrowser for help on using the repository browser.