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 | ::MPI_Status mpi_status; |
---|
22 | ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status); |
---|
23 | |
---|
24 | if(*flag) |
---|
25 | { |
---|
26 | status->mpi_status=new ::MPI_Status(mpi_status); |
---|
27 | //printf("MPI_Test : delete (*request)->mpi_request => (*request)->mpi_request = %p\n", (*request)->mpi_request); |
---|
28 | delete (*request)->mpi_request; |
---|
29 | //printf("MPI_Test : delete *request => *request = %p\n", *request); |
---|
30 | delete *request; |
---|
31 | } |
---|
32 | } |
---|
33 | |
---|
34 | |
---|
35 | int MPI_Test2(MPI_Request *request, int *flag, MPI_Status *status) |
---|
36 | { |
---|
37 | Debug("MPI_Test with EP"); |
---|
38 | |
---|
39 | if(*request==0) return *flag=true; |
---|
40 | |
---|
41 | if((*request)->type !=1 && (*request)->type !=2 && (*request)->type !=3) |
---|
42 | { |
---|
43 | printf("MPI_Test : Error in request type\n"); |
---|
44 | exit(1); |
---|
45 | } |
---|
46 | |
---|
47 | if((*request)->type == 2) // irecv message not probed |
---|
48 | { |
---|
49 | *flag = false; |
---|
50 | return Request_Check(); |
---|
51 | } |
---|
52 | |
---|
53 | else //(*request)->type == 1 || (*request)->type == 3 // isend or imrecv |
---|
54 | { |
---|
55 | |
---|
56 | ::MPI_Status mpi_status; |
---|
57 | ::MPI_Test(to_mpi_request_ptr(*request), flag, &mpi_status); |
---|
58 | |
---|
59 | if(*flag) |
---|
60 | { |
---|
61 | |
---|
62 | status->mpi_status=new ::MPI_Status(mpi_status); |
---|
63 | status->ep_src = (*request)->ep_src; |
---|
64 | status->ep_tag = (*request)->ep_tag; |
---|
65 | status->ep_datatype = (*request)->ep_datatype; |
---|
66 | |
---|
67 | (*request)->state = 2; |
---|
68 | |
---|
69 | memcheck("delete "<< (*request)->mpi_request << " : in ep_lib::MPI_Test, delete (*request)->mpi_request"); |
---|
70 | delete (*request)->mpi_request; |
---|
71 | delete *request; |
---|
72 | *request=0; |
---|
73 | } |
---|
74 | } |
---|
75 | |
---|
76 | return Request_Check(); |
---|
77 | } |
---|
78 | |
---|
79 | |
---|
80 | int MPI_Testall(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses) |
---|
81 | { |
---|
82 | ::MPI_Request* mpi_request = new ::MPI_Request[count]; |
---|
83 | ::MPI_Status* mpi_status = new ::MPI_Status[count]; |
---|
84 | |
---|
85 | for(int i=0; i<count; i++) |
---|
86 | { |
---|
87 | mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); |
---|
88 | } |
---|
89 | |
---|
90 | ::MPI_Testall(count, mpi_request, flag, mpi_status); |
---|
91 | |
---|
92 | if(*flag) |
---|
93 | { |
---|
94 | for(int i=0; i<count; i++) |
---|
95 | { |
---|
96 | array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]); |
---|
97 | |
---|
98 | //printf("MPI_Testall : delete array_of_requests[%d]->mpi_request => array_of_requests[%d]->mpi_request = %p\n", i, i, array_of_requests[i]->mpi_request); |
---|
99 | delete array_of_requests[i]->mpi_request; |
---|
100 | //printf("MPI_Testall : delete array_of_requests[%d] => array_of_requests[%d] = %p\n", i, i, array_of_requests[i]); |
---|
101 | delete array_of_requests[i]; |
---|
102 | } |
---|
103 | } |
---|
104 | |
---|
105 | delete[] mpi_request; |
---|
106 | delete[] mpi_status; |
---|
107 | |
---|
108 | return 0; |
---|
109 | } /* end of mpi_waitall*/ |
---|
110 | |
---|
111 | |
---|
112 | int MPI_Testall2(int count, MPI_Request *array_of_requests, int *flag, MPI_Status *array_of_statuses) |
---|
113 | { |
---|
114 | Debug("MPI_Testall with EP"); |
---|
115 | *flag = false; |
---|
116 | |
---|
117 | int rank = array_of_requests[0]->comm->ep_comm_ptr->size_rank_info[0].first; |
---|
118 | |
---|
119 | for(int i=0; i<count; i++) |
---|
120 | { |
---|
121 | if(array_of_requests[i]->type == 2) |
---|
122 | { |
---|
123 | *flag=false; |
---|
124 | return Request_Check(); |
---|
125 | } |
---|
126 | } |
---|
127 | |
---|
128 | ::MPI_Request* mpi_request = new ::MPI_Request[count]; |
---|
129 | ::MPI_Status* mpi_status = new ::MPI_Status[count]; |
---|
130 | |
---|
131 | |
---|
132 | for(int i=0; i<count; i++) |
---|
133 | { |
---|
134 | mpi_request[i] = *static_cast< ::MPI_Request*>(array_of_requests[i]->mpi_request); |
---|
135 | } |
---|
136 | |
---|
137 | ::MPI_Testall(count, mpi_request, flag, mpi_status); |
---|
138 | |
---|
139 | if(*flag) |
---|
140 | { |
---|
141 | for(int i=0; i<count; i++) |
---|
142 | { |
---|
143 | array_of_statuses[i].mpi_status = new ::MPI_Status(mpi_status[i]); |
---|
144 | array_of_statuses[i].ep_src = array_of_requests[i]->ep_src; |
---|
145 | array_of_statuses[i].ep_tag = array_of_requests[i]->ep_tag; |
---|
146 | array_of_statuses[i].ep_datatype = array_of_requests[i]->ep_datatype; |
---|
147 | |
---|
148 | array_of_requests[i]->state = 2; |
---|
149 | |
---|
150 | memcheck("delete "<< array_of_requests[i]->mpi_request <<" : in ep_lib::MPI_Testall, array_of_requests["<<i<<"]->mpi_request"); |
---|
151 | delete array_of_requests[i]->mpi_request; |
---|
152 | delete array_of_requests[i]; |
---|
153 | array_of_requests[i]=0; |
---|
154 | |
---|
155 | } |
---|
156 | } |
---|
157 | |
---|
158 | return Request_Check(); |
---|
159 | } |
---|
160 | |
---|
161 | |
---|
162 | } |
---|
163 | |
---|
164 | #endif |
---|