1 | #ifdef _usingEP |
---|
2 | /*! |
---|
3 | \file ep_wait.cpp |
---|
4 | \since 2 may 2016 |
---|
5 | |
---|
6 | \brief Definitions of MPI wait function: MPI_Wait, MPI_Waitall, MPI_Waitsome, MPI_Waitany |
---|
7 | */ |
---|
8 | |
---|
9 | #include "ep_lib.hpp" |
---|
10 | #include <mpi.h> |
---|
11 | #include "ep_declaration.hpp" |
---|
12 | #include "ep_mpi.hpp" |
---|
13 | |
---|
14 | using namespace std; |
---|
15 | |
---|
16 | extern std::list< ep_lib::MPI_Request* > * EP_PendingRequests; |
---|
17 | #pragma omp threadprivate(EP_PendingRequests) |
---|
18 | |
---|
19 | |
---|
20 | |
---|
21 | namespace ep_lib |
---|
22 | { |
---|
23 | |
---|
24 | int MPI_Wait(MPI_Request *request, MPI_Status *status) |
---|
25 | { |
---|
26 | if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) |
---|
27 | { |
---|
28 | printf("MPI_Wait : Error in request type\n"); |
---|
29 | exit(1); |
---|
30 | } |
---|
31 | |
---|
32 | while((*request)->type == 2) Request_Check(); |
---|
33 | |
---|
34 | ::MPI_Status mpi_status; |
---|
35 | |
---|
36 | ::MPI_Wait(to_mpi_request_ptr(*request), &mpi_status); |
---|
37 | |
---|
38 | status->mpi_status = new ::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 | (*request)->state = 2; |
---|
44 | |
---|
45 | memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Wait, delete (*request)->mpi_request"); |
---|
46 | |
---|
47 | delete (*request)->mpi_request; |
---|
48 | delete *request; |
---|
49 | *request=0; |
---|
50 | |
---|
51 | return Request_Check(); |
---|
52 | |
---|
53 | } /*end of mpi_wait*/ |
---|
54 | |
---|
55 | |
---|
56 | |
---|
57 | |
---|
58 | |
---|
59 | |
---|
60 | int MPI_Waitall(int count, MPI_Request *array_of_requests, MPI_Status *array_of_statuses) |
---|
61 | { |
---|
62 | std::vector<int> finished(count, 0); |
---|
63 | |
---|
64 | ::MPI_Request* mpi_request = new ::MPI_Request[count]; |
---|
65 | ::MPI_Status* mpi_status = new ::MPI_Status[count]; |
---|
66 | |
---|
67 | while(std::accumulate(finished.begin(), finished.end(), 0) < count) |
---|
68 | { |
---|
69 | |
---|
70 | for(int i=0; i<count; i++) |
---|
71 | { |
---|
72 | if(array_of_requests[i]->type !=1 && array_of_requests[i]->type !=2 && array_of_requests[i]->type !=3) |
---|
73 | { |
---|
74 | printf("Error in request type\n"); |
---|
75 | |
---|
76 | exit(1); |
---|
77 | } |
---|
78 | |
---|
79 | if(array_of_requests[i]->type == 2) Request_Check(); |
---|
80 | if(array_of_requests[i]->type != 2 && finished.at(i) == 0) |
---|
81 | { |
---|
82 | finished.at(i) = 1; |
---|
83 | mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); |
---|
84 | } |
---|
85 | } |
---|
86 | } |
---|
87 | |
---|
88 | ::MPI_Waitall(count, mpi_request, mpi_status); |
---|
89 | |
---|
90 | for(int i=0; i<count; i++) |
---|
91 | { |
---|
92 | array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]); |
---|
93 | array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; |
---|
94 | array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; |
---|
95 | array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; |
---|
96 | |
---|
97 | array_of_requests[i]->state = 2; |
---|
98 | |
---|
99 | memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Waitall, array_of_requests["<<i<<"]->mpi_request"); |
---|
100 | delete array_of_requests[i]->mpi_request; |
---|
101 | delete array_of_requests[i]; |
---|
102 | array_of_requests[i] = 0; |
---|
103 | } |
---|
104 | |
---|
105 | delete[] mpi_request; |
---|
106 | delete[] mpi_status; |
---|
107 | |
---|
108 | return Request_Check(); |
---|
109 | } /* end of mpi_waitall*/ |
---|
110 | |
---|
111 | |
---|
112 | } |
---|
113 | |
---|
114 | #endif |
---|