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

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

Bug fixed in MPI_(All)Gatherv with displs

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