1 // RUN: %clang_analyze_cc1 -analyzer-checker=optin.mpi.MPI-Checker -verify %s
8 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
10 MPI_Request sendReq1
, recvReq1
;
11 MPI_Isend(&buf
, 1, MPI_DOUBLE
, rank
+ 1, 0, MPI_COMM_WORLD
, &sendReq1
);
12 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, rank
- 1, 0, MPI_COMM_WORLD
, &recvReq1
);
14 MPI_Wait(&sendReq1
, MPI_STATUS_IGNORE
);
15 MPI_Wait(&recvReq1
, MPI_STATUS_IGNORE
);
22 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
24 MPI_Request sendReq1
, recvReq1
;
25 MPI_Isend(&buf
, 1, MPI_DOUBLE
, rank
+ 1, 0, MPI_COMM_WORLD
, &sendReq1
);
26 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, rank
- 1, 0, MPI_COMM_WORLD
, &recvReq1
);
27 MPI_Wait(&sendReq1
, MPI_STATUS_IGNORE
);
28 MPI_Wait(&recvReq1
, MPI_STATUS_IGNORE
);
35 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
37 MPI_Request sendReq1
, recvReq1
;
38 MPI_Isend(&buf
, 1, MPI_DOUBLE
, rank
+ 1, 0, MPI_COMM_WORLD
, &sendReq1
);
39 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, rank
- 1, 0, MPI_COMM_WORLD
, &recvReq1
);
42 MPI_Wait(&sendReq1
, MPI_STATUS_IGNORE
);
43 MPI_Wait(&recvReq1
, MPI_STATUS_IGNORE
);
45 MPI_Wait(&sendReq1
, MPI_STATUS_IGNORE
);
46 MPI_Wait(&recvReq1
, MPI_STATUS_IGNORE
);
51 void missingWait1() { // Check missing wait for dead region.
54 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &sendReq1
);
55 } // expected-warning{{Request 'sendReq1' has no matching wait.}}
60 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
63 MPI_Request sendReq1
, recvReq1
;
65 MPI_Isend(&buf
, 1, MPI_DOUBLE
, rank
+ 1, 0, MPI_COMM_WORLD
, &sendReq1
);
66 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, rank
- 1, 0, MPI_COMM_WORLD
, &recvReq1
); // expected-warning{{Request 'sendReq1' has no matching wait.}}
67 MPI_Wait(&recvReq1
, MPI_STATUS_IGNORE
);
71 void doubleNonblocking() {
74 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
79 MPI_Isend(&buf
, 1, MPI_DOUBLE
, rank
+ 1, 0, MPI_COMM_WORLD
, &sendReq1
);
80 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, rank
- 1, 0, MPI_COMM_WORLD
, &sendReq1
); // expected-warning{{Double nonblocking on request 'sendReq1'.}}
81 MPI_Wait(&sendReq1
, MPI_STATUS_IGNORE
);
85 void doubleNonblocking2() {
88 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
91 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &req
);
92 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &req
); // expected-warning{{Double nonblocking on request 'req'.}}
93 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
96 void doubleNonblocking3() {
97 typedef struct { MPI_Request req
; } ReqStruct
;
102 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
104 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &rs
.req
);
105 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &rs
.req
); // expected-warning{{Double nonblocking on request 'rs.req'.}}
106 MPI_Wait(&rs
.req
, MPI_STATUS_IGNORE
);
109 void doubleNonblocking4() {
112 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
115 for (int i
= 0; i
< 2; ++i
) {
116 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
, &req
); // expected-warning{{Double nonblocking on request 'req'.}}
118 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
121 void tripleNonblocking() {
124 MPI_Isend(&buf
, 1, MPI_DOUBLE
, 0, 0, MPI_COMM_WORLD
, &sendReq
);
125 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, 0, 0, MPI_COMM_WORLD
, &sendReq
); // expected-warning{{Double nonblocking on request 'sendReq'.}}
126 MPI_Isend(&buf
, 1, MPI_DOUBLE
, 0, 0, MPI_COMM_WORLD
, &sendReq
); // expected-warning{{Double nonblocking on request 'sendReq'.}}
127 MPI_Wait(&sendReq
, MPI_STATUS_IGNORE
);
130 void missingNonBlocking() {
132 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
133 MPI_Request sendReq1
[10][10][10];
134 MPI_Wait(&sendReq1
[1][7][9], MPI_STATUS_IGNORE
); // expected-warning{{Request 'sendReq1[1][7][9]' has no matching nonblocking call.}}
137 void missingNonBlocking2() {
139 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
140 typedef struct { MPI_Request req
[2][2]; } ReqStruct
;
142 MPI_Request
*r
= &rs
.req
[0][1];
143 MPI_Wait(r
, MPI_STATUS_IGNORE
); // expected-warning{{Request 'rs.req[0][1]' has no matching nonblocking call.}}
146 void missingNonBlocking3() {
148 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
150 MPI_Wait(&sendReq
, MPI_STATUS_IGNORE
); // expected-warning{{Request 'sendReq' has no matching nonblocking call.}}
153 void missingNonBlockingMultiple() {
155 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
156 MPI_Request sendReq
[4];
157 for (int i
= 0; i
< 4; ++i
) {
158 MPI_Wait(&sendReq
[i
], MPI_STATUS_IGNORE
); // expected-warning-re 1+{{Request {{.*}} has no matching nonblocking call.}}
162 void missingNonBlockingWaitall() {
165 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
168 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
170 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
172 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
175 MPI_Waitall(4, req
, MPI_STATUSES_IGNORE
); // expected-warning{{Request 'req[2]' has no matching nonblocking call.}}
178 void missingNonBlockingWaitall2() {
181 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
184 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
186 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
189 MPI_Waitall(4, req
, MPI_STATUSES_IGNORE
); // expected-warning-re 2{{Request '{{(.*)[[1-2]](.*)}}' has no matching nonblocking call.}}
192 void missingNonBlockingWaitall3() {
195 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
198 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
200 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
203 MPI_Waitall(4, req
, MPI_STATUSES_IGNORE
); // expected-warning-re 2{{Request '{{(.*)[[1,3]](.*)}}' has no matching nonblocking call.}}
206 void missingNonBlockingWaitall4() {
208 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
210 MPI_Waitall(4, req
, MPI_STATUSES_IGNORE
); // expected-warning-re 4{{Request '{{(.*)[[0-3]](.*)}}' has no matching nonblocking call.}}
213 void noDoubleRequestUsage() {
222 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
224 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
226 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
228 MPI_Wait(&rs
.req
, MPI_STATUS_IGNORE
);
229 MPI_Wait(&rs
.req2
, MPI_STATUS_IGNORE
);
232 void noDoubleRequestUsage2() {
241 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
243 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
245 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
247 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
249 MPI_Wait(&rs
.req
[0], MPI_STATUS_IGNORE
);
250 MPI_Wait(&rs
.req
[1], MPI_STATUS_IGNORE
);
251 MPI_Wait(&rs
.req2
, MPI_STATUS_IGNORE
);
254 void nestedRequest() {
263 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
265 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
267 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
269 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
271 MPI_Waitall(2, rs
.req
, MPI_STATUSES_IGNORE
);
272 MPI_Wait(&rs
.req2
, MPI_STATUS_IGNORE
);
275 void singleRequestInWaitall() {
279 MPI_Comm_rank(MPI_COMM_WORLD
, &rank
);
281 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
283 MPI_Waitall(1, &r
, MPI_STATUSES_IGNORE
);
286 void multiRequestUsage() {
290 MPI_Isend(&buf
, 1, MPI_DOUBLE
, 1, 0, MPI_COMM_WORLD
, &req
);
291 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
293 MPI_Irecv(&buf
, 1, MPI_DOUBLE
, 1, 0, MPI_COMM_WORLD
, &req
);
294 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
297 void multiRequestUsage2() {
301 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
303 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
305 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
307 MPI_Wait(&req
, MPI_STATUS_IGNORE
);
311 void callNonblocking(MPI_Request
*req
) {
313 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
318 void callWait(MPI_Request
*req
) {
319 MPI_Wait(req
, MPI_STATUS_IGNORE
);
322 // Call nonblocking, wait wrapper functions.
323 void callWrapperFunctions() {
325 callNonblocking(&req
);
329 void externFunctions1() {
332 MPI_Ireduce(MPI_IN_PLACE
, &buf
, 1, MPI_DOUBLE
, MPI_SUM
, 0, MPI_COMM_WORLD
,
334 void callWaitExtern(MPI_Request
*req
);
335 callWaitExtern(&req
);
336 } // expected-warning{{Request 'req' has no matching wait.}}
338 void externFunctions2() {
340 void callNonblockingExtern(MPI_Request
*req
);
341 callNonblockingExtern(&req
);