1 | #ifdef _usingEP |
---|
2 | /*! |
---|
3 | \file ep_test.cpp |
---|
4 | \since 2 may 2016 |
---|
5 | |
---|
6 | \brief Definitions of MPI test function: MPI_Test, MPI_Testsome, MPI_Testany, MPI_Testall |
---|
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 | |
---|
17 | namespace ep_lib { |
---|
18 | |
---|
19 | int MPI_Test(MPI_Request *request, int *flag, MPI_Status *status) |
---|
20 | { |
---|
21 | Debug("MPI_Test with EP"); |
---|
22 | |
---|
23 | if(*request==0) return *flag=true; |
---|
24 | |
---|
25 | if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) |
---|
26 | { |
---|
27 | printf("MPI_Test : Error in request type\n"); |
---|
28 | exit(1); |
---|
29 | } |
---|
30 | |
---|
31 | if((*request)->type == 2) // irecv message not probed |
---|
32 | { |
---|
33 | *flag = false; |
---|
34 | return Request_Check(); |
---|
35 | } |
---|
36 | |
---|
37 | else //(*request)->type == 1 || (*request)->type == 3 // isend or imrecv |
---|
38 | { |
---|
39 | |
---|
40 | ::MPI_Status mpi_status; |
---|
41 | ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status); |
---|
42 | |
---|
43 | if(*flag) |
---|
44 | { |
---|
45 | |
---|
46 | status->mpi_status=new ::MPI_Status(mpi_status); |
---|
47 | status->ep_src = (*request)->ep_src; |
---|
48 | status->ep_tag = (*request)->ep_tag; |
---|
49 | status->ep_datatype = (*request)->ep_datatype; |
---|
50 | |
---|
51 | (*request)->state = 2; |
---|
52 | |
---|
53 | memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request"); |
---|
54 | delete (*request)->mpi_request; |
---|
55 | delete *request; |
---|
56 | *request=0; |
---|
57 | } |
---|
58 | } |
---|
59 | |
---|
60 | return Request_Check(); |
---|
61 | } |
---|
62 | |
---|
63 | |
---|
64 | int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses) |
---|
65 | { |
---|
66 | Debug("MPI_Testall with EP"); |
---|
67 | *flag = false; |
---|
68 | |
---|
69 | int rank = array_of_requests[0]->comm->ep_comm_ptr->size_rank_info[0].first; |
---|
70 | |
---|
71 | for(int i=0; i<count; i++) |
---|
72 | { |
---|
73 | if(array_of_requests[i]->type == 2) |
---|
74 | { |
---|
75 | *flag=false; |
---|
76 | return Request_Check(); |
---|
77 | } |
---|
78 | } |
---|
79 | |
---|
80 | ::MPI_Request* mpi_request = new ::MPI_Request[count]; |
---|
81 | ::MPI_Status* mpi_status = new ::MPI_Status[count]; |
---|
82 | |
---|
83 | |
---|
84 | for(int i=0; i<count; i++) |
---|
85 | { |
---|
86 | mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); |
---|
87 | } |
---|
88 | |
---|
89 | ::MPI_Testall(count, mpi_request, flag, mpi_status); |
---|
90 | |
---|
91 | if(*flag) |
---|
92 | { |
---|
93 | for(int i=0; i<count; i++) |
---|
94 | { |
---|
95 | array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]); |
---|
96 | array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; |
---|
97 | array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; |
---|
98 | array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; |
---|
99 | |
---|
100 | array_of_requests[i]->state = 2; |
---|
101 | |
---|
102 | memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request"); |
---|
103 | delete array_of_requests[i]->mpi_request; |
---|
104 | delete array_of_requests[i]; |
---|
105 | array_of_requests[i]=0; |
---|
106 | |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | return Request_Check(); |
---|
111 | } |
---|
112 | |
---|
113 | |
---|
114 | } |
---|
115 | |
---|
116 | #endif |
---|