source: XIOS/dev/branch_openmp/extern/ep_dev/ep_wait.cpp @ 1381

Last change on this file since 1381 was 1381, checked in by yushan, 3 years ago

add folder for MPI EP-RMA development. Current: MPI_Win, MPI_win_create, MPI_win_fence, MPI_win_free

File size: 2.2 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
14extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests;
15#pragma omp threadprivate(EP_PendingRequests)
16
17
18
19namespace ep_lib
20{
21 
22  int MPI_Wait(MPI_Request *request, MPI_Status *status)
23  {
24    if(request->type !=1 && request->type !=2 && request->type !=3) 
25    {
26      printf("Error in request type\n");
27 
28      exit(1);
29    }
30
31    while(request->type == 2) Request_Check();
32
33    ::MPI_Status mpi_status;
34    ::MPI_Wait(static_cast< ::MPI_Request*>(request->mpi_request), &mpi_status);
35
36    status->mpi_status = &mpi_status;
37    status->ep_src = request->ep_src;
38    status->ep_tag = request->ep_tag;
39    status->ep_datatype = request->ep_datatype;
40   
41    return MPI_SUCCESS;
42
43  }   /*end of mpi_wait*/
44
45
46
47
48
49
50  int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses)
51  {
52    std::vector<int> finished(count, 0);
53
54    ::MPI_Request* mpi_request = new ::MPI_Request[count];
55    ::MPI_Status* mpi_status = new ::MPI_Status[count];
56
57    while(std::accumulate(finished.begin(), finished.end(), 0) < count)
58    {
59     
60      for(int i=0; i<count; i++)
61      {
62        if(array_of_requests[i].type !=1 && array_of_requests[i].type !=2 && array_of_requests[i].type !=3) 
63        {
64          printf("Error in request type\n");
65 
66          exit(1);
67        }
68       
69        if(array_of_requests[i].type == 2) Request_Check(); 
70        if(array_of_requests[i].type != 2 && finished.at(i) == 0) 
71        {
72          finished.at(i) = 1;
73          mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i].mpi_request);
74        }
75      }   
76    }
77
78    ::MPI_Waitall(count, mpi_request, mpi_status);
79
80    for(int i=0; i<count; i++)
81    {
82      array_of_statuses[i].mpi_status = &mpi_status[i];
83      array_of_statuses[i].ep_src = array_of_requests[i].ep_src;
84      array_of_statuses[i].ep_tag = array_of_requests[i].ep_tag;
85      array_of_statuses[i].ep_datatype = array_of_requests[i].ep_datatype;
86    }
87
88    delete[] mpi_request;
89    delete[] mpi_status;
90   
91   
92    return MPI_SUCCESS;
93  }  /* end of mpi_waitall*/
94
95
96}
97
Note: See TracBrowser for help on using the repository browser.