-
Notifications
You must be signed in to change notification settings - Fork 0
/
impl-wait-functions.c
484 lines (420 loc) · 16.9 KB
/
impl-wait-functions.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
// SPDX-License-Identifier: MIT
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
#include <stdint.h>
#include <stdbool.h>
#include <string.h>
#include <assert.h>
#include <mpi.h>
//#include "muk-dl.h"
#include "muk-predefined.h"
#include "impl-scalar-types.h"
#include "wrap-handle-typedefs.h"
#define MUK_EXTERN extern
#include "impl-fpointers.h"
#include "impl-status.h"
#include "impl-constant-conversions.h"
#include "impl-handle-conversions.h"
#include "impl-keyval-map.h"
int WRAP_Cancel(WRAP_Request *request)
{
MPI_Request impl_request = CONVERT_MPI_Request(*request);
int rc = IMPL_Cancel(&impl_request);
// It is erroneous to call MPI_REQUEST_FREE or MPI_CANCEL for a request
// associated with a nonblocking collective operation.
cleanup_mapped_request(CONVERT_MPI_Request(*request));
*request = OUTPUT_MPI_Request(impl_request);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Get_count(const WRAP_Status *status, WRAP_Datatype datatype, int *count)
{
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Get_count(&impl_status, impl_datatype, count);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Get_count_c(const WRAP_Status *status, WRAP_Datatype datatype, WRAP_Count *count)
{
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
int rc = IMPL_Get_count_c(&impl_status, impl_datatype, count);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Get_elements(const WRAP_Status *status, WRAP_Datatype datatype, int *count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Get_elements(&impl_status, impl_datatype, count);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Get_elements_c(const WRAP_Status *status, WRAP_Datatype datatype, WRAP_Count *count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Get_elements_c(&impl_status, impl_datatype, count);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Get_elements_x(const WRAP_Status *status, WRAP_Datatype datatype, WRAP_Count *count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Get_elements_x(&impl_status, impl_datatype, count);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Request_free(WRAP_Request *request)
{
int rc;
MPI_Request impl_request = CONVERT_MPI_Request(*request);
#if 1
cleanup_mapped_request(impl_request);
#else
// look up the request before it is freed, because that will change it to MPI_REQUEST_NULL
// look for nonblocking alltoallw first
{
MPI_Datatype * sendtypes = NULL;
MPI_Datatype * recvtypes = NULL;
int found = find_nonblocking_request_alltoallw_buffers(impl_request, &sendtypes, &recvtypes);
if (found) {
if (sendtypes != NULL) {
free(sendtypes);
sendtypes = NULL;
}
if (recvtypes != NULL) {
free(recvtypes);
recvtypes = NULL;
}
rc = remove_nonblocking_request_alltoallw_buffers(impl_request);
if (!rc) {
printf("%s: found request=%lx but could not remove it\n",__func__,(intptr_t)impl_request);
}
}
}
// look for persistent alltoallw next
{
MPI_Datatype * sendtypes = NULL;
MPI_Datatype * recvtypes = NULL;
int found = find_persistent_request_alltoallw_buffers(impl_request, &sendtypes, &recvtypes);
if (found) {
if (sendtypes != NULL) {
free(sendtypes);
sendtypes = NULL;
}
if (recvtypes != NULL) {
free(recvtypes);
recvtypes = NULL;
}
remove_persistent_request_alltoallw_buffers(impl_request);
if (!rc) {
printf("%s: found request=%lx but could not remove it\n",__func__,(intptr_t)impl_request);
}
}
}
#endif
rc = IMPL_Request_free(&impl_request);
if (rc) goto end;
// It is erroneous to call MPI_REQUEST_FREE or MPI_CANCEL for a request
// associated with a nonblocking collective operation.
*request = OUTPUT_MPI_Request(impl_request);
end:
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Request_get_status(WRAP_Request request, int *flag, WRAP_Status *status)
{
const bool ignore = IS_STATUS_IGNORE(status);
MPI_Request impl_request = CONVERT_MPI_Request(request);
MPI_Status impl_status = {0};
if (impl_request == MPI_REQUEST_NULL) {
*flag = 1;
if (!ignore) WRAP_Status_empty(false,status);
return MPI_SUCCESS;
}
int rc = IMPL_Request_get_status(impl_request, flag, ignore ? MPI_STATUS_IGNORE : &impl_status);
if (*flag) {
if (!ignore) MPI_Status_to_WRAP_Status(&impl_status, status);
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Start(WRAP_Request *request)
{
MPI_Request impl_request = CONVERT_MPI_Request(*request);
int rc = IMPL_Start(&impl_request);
*request = OUTPUT_MPI_Request(impl_request);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Startall(int count, WRAP_Request array_of_requests[])
{
MPI_Request * impl_array_of_requests = calloc(count,sizeof(MPI_Request));
for (int i=0; i<count; i++) {
impl_array_of_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
int rc = IMPL_Startall(count, impl_array_of_requests);
for (int i=0; i<count; i++) {
array_of_requests[i] = OUTPUT_MPI_Request(impl_array_of_requests[i]);
}
free(impl_array_of_requests);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#ifdef SUPPORT_F08
int WRAP_Status_f082c(const WRAP_F08_status *f08_status, WRAP_Status *c_status)
{
int rc = IMPL_Status_f082c(f08_status, c_status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Status_f082f(const WRAP_F08_status *f08_status, WRAP_Fint *f_status)
{
int rc = IMPL_Status_f082f(f08_status, f_status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Status_f2f08(const WRAP_Fint *f_status, WRAP_F08_status *f08_status)
{
int rc = IMPL_Status_f2f08(f_status, f08_status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
#endif
int WRAP_Status_set_cancelled(WRAP_Status *status, int flag)
{
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Status_set_cancelled(&impl_status, flag);
MPI_Status_to_WRAP_Status(&impl_status, status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Status_set_elements(WRAP_Status *status, WRAP_Datatype datatype, int count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Status_set_elements(&impl_status, impl_datatype, count);
MPI_Status_to_WRAP_Status(&impl_status, status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Status_set_elements_c(WRAP_Status *status, WRAP_Datatype datatype, WRAP_Count count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Status_set_elements_c(&impl_status, impl_datatype, count);
MPI_Status_to_WRAP_Status(&impl_status, status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Status_set_elements_x(WRAP_Status *status, WRAP_Datatype datatype, WRAP_Count count)
{
MPI_Datatype impl_datatype = CONVERT_MPI_Datatype(datatype);
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Status_set_elements_x(&impl_status, impl_datatype, count);
MPI_Status_to_WRAP_Status(&impl_status, status);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Test(WRAP_Request *request, int *flag, WRAP_Status *status)
{
const bool ignore = IS_STATUS_IGNORE(status);
MPI_Request impl_request = CONVERT_MPI_Request(*request);
MPI_Status impl_status = {0};
int rc = IMPL_Test(&impl_request, flag, ignore ? MPI_STATUS_IGNORE : &impl_status);
if (*flag) {
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_status, status);
}
cleanup_mapped_request(CONVERT_MPI_Request(*request));
*request = OUTPUT_MPI_Request(impl_request);
}
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Test_cancelled(const WRAP_Status *status, int *flag)
{
MPI_Status impl_status = {0};
WRAP_Status_to_MPI_Status(status, &impl_status);
int rc = IMPL_Test_cancelled(&impl_status, flag);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Testall(int count, WRAP_Request array_of_requests[], int *flag, WRAP_Status *array_of_statuses)
{
const bool ignore = IS_STATUSES_IGNORE(array_of_statuses);
MPI_Request * impl_requests = calloc(count,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<count; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status * impl_statuses = NULL;
if (!ignore) {
impl_statuses = calloc(count, sizeof(MPI_Status));
if (impl_statuses == NULL) return MPI_ERR_INTERN;
}
int rc = IMPL_Testall(count, impl_requests, flag, ignore ? MPI_STATUSES_IGNORE : impl_statuses);
if (*flag) {
for (int i=0; i<count; i++) {
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_statuses[i], &array_of_statuses[i]);
}
if (impl_requests[i] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[i]));
}
array_of_requests[i] = OUTPUT_MPI_Request(impl_requests[i]);
}
}
free(impl_requests);
if (!ignore) free(impl_statuses);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Testany(int count, WRAP_Request array_of_requests[], int *indx, int *flag, WRAP_Status *status)
{
const bool ignore = IS_STATUS_IGNORE(status);
MPI_Request * impl_requests = calloc(count,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<count; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status impl_status = {0};
int rc = IMPL_Testany(count, impl_requests, indx, flag, ignore ? MPI_STATUS_IGNORE : &impl_status);
if (*flag) {
// If the array contains no active handles then the call returns immediately
// with flag = true, index = MPI_UNDEFINED, and an empty status.
if (*indx != MPI_UNDEFINED) {
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_status, status);
}
if (impl_requests[*indx] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[*indx]));
}
array_of_requests[*indx] = OUTPUT_MPI_Request(impl_requests[*indx]);
}
}
free(impl_requests);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Testsome(int incount, WRAP_Request array_of_requests[], int *outcount, int array_of_indices[], WRAP_Status *array_of_statuses)
{
const bool ignore = IS_STATUSES_IGNORE(array_of_statuses);
MPI_Request * impl_requests = calloc(incount,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<incount; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status * impl_statuses = NULL;
if (!ignore) {
impl_statuses = calloc(incount, sizeof(MPI_Status));
if (impl_statuses == NULL) return MPI_ERR_INTERN;
}
int rc = IMPL_Testsome(incount, impl_requests, outcount, array_of_indices, ignore ? MPI_STATUSES_IGNORE : impl_statuses);
if ((*outcount > 0) && (*outcount != MPI_UNDEFINED)) {
for (int i=0; i<*outcount; i++) {
const int j = array_of_indices[i];
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_statuses[j], &array_of_statuses[j]);
}
if (impl_requests[j] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[j]));
}
array_of_requests[j] = OUTPUT_MPI_Request(impl_requests[j]);
}
}
free(impl_requests);
if (!ignore) free(impl_statuses);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Wait(WRAP_Request *request, WRAP_Status *status)
{
const bool ignore = IS_STATUS_IGNORE(status);
MPI_Request impl_request = CONVERT_MPI_Request(*request);
MPI_Status impl_status = {0};
int rc = IMPL_Wait(&impl_request, ignore ? MPI_STATUS_IGNORE : &impl_status);
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_status, status);
}
cleanup_mapped_request(CONVERT_MPI_Request(*request));
*request = OUTPUT_MPI_Request(impl_request);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Waitall(int count, WRAP_Request array_of_requests[], WRAP_Status *array_of_statuses)
{
const bool ignore = IS_STATUSES_IGNORE(array_of_statuses);
MPI_Request * impl_requests = calloc(count,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<count; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status * impl_statuses = NULL;
if (!ignore) {
impl_statuses = calloc(count, sizeof(MPI_Status));
if (impl_statuses == NULL) return MPI_ERR_INTERN;
}
int rc = IMPL_Waitall(count, impl_requests, ignore ? MPI_STATUSES_IGNORE : impl_statuses);
// Active persistent requests are marked inactive. Requests of any other type are
// deallocated and the corresponding handles in the array are set to MPI_REQUEST_NULL.
// The list may contain null or inactive handles. The call sets to empty the status of
// each such entry.
for (int i=0; i<count; i++) {
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_statuses[i], &array_of_statuses[i]);
}
if (impl_requests[i] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[i]));
}
array_of_requests[i] = OUTPUT_MPI_Request(impl_requests[i]);
}
free(impl_requests);
if (!ignore) free(impl_statuses);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Waitany(int count, WRAP_Request array_of_requests[], int *indx, WRAP_Status *status)
{
const bool ignore = IS_STATUS_IGNORE(status);
MPI_Request * impl_requests = calloc(count,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<count; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status impl_status = {0};
int rc = IMPL_Waitany(count, impl_requests, indx, ignore ? MPI_STATUS_IGNORE : &impl_status);
// If the list contains no active handles (list has length zero
// or all entries are null or inactive), then the call returns
// immediately with index = MPI_UNDEFINED, and an empty status.
if (*indx != MPI_UNDEFINED) {
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_status, status);
}
if (impl_requests[*indx] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[*indx]));
}
array_of_requests[*indx] = OUTPUT_MPI_Request(impl_requests[*indx]);
}
free(impl_requests);
return RETURN_CODE_IMPL_TO_MUK(rc);
}
int WRAP_Waitsome(int incount, WRAP_Request array_of_requests[], int *outcount, int array_of_indices[], WRAP_Status *array_of_statuses)
{
const bool ignore = IS_STATUSES_IGNORE(array_of_statuses);
MPI_Request * impl_requests = calloc(incount,sizeof(MPI_Request));
if (impl_requests == NULL) return MPI_ERR_INTERN;
for (int i=0; i<incount; i++) {
impl_requests[i] = CONVERT_MPI_Request(array_of_requests[i]);
}
MPI_Status * impl_statuses = NULL;
if (!ignore) {
impl_statuses = calloc(incount, sizeof(MPI_Status));
if (impl_statuses == NULL) return MPI_ERR_INTERN;
}
int rc = IMPL_Waitsome(incount, impl_requests, outcount, array_of_indices, ignore ? MPI_STATUSES_IGNORE : impl_statuses);
if ((*outcount > 0) && (*outcount != MPI_UNDEFINED)) {
for (int i=0; i<*outcount; i++) {
const int j = array_of_indices[i];
if (!ignore) {
MPI_Status_to_WRAP_Status(&impl_statuses[j], &array_of_statuses[j]);
}
if (impl_requests[j] == MPI_REQUEST_NULL) {
cleanup_mapped_request(CONVERT_MPI_Request(array_of_requests[j]));
}
array_of_requests[j] = OUTPUT_MPI_Request(impl_requests[j]);
}
}
free(impl_requests);
if (!ignore) free(impl_statuses);
return RETURN_CODE_IMPL_TO_MUK(rc);
}