-
Notifications
You must be signed in to change notification settings - Fork 274
/
request_impl.c
1525 lines (1342 loc) · 53.1 KB
/
request_impl.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
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* Copyright (C) by Argonne National Laboratory
* See COPYRIGHT in top-level directory
*/
#include "mpiimpl.h"
/*
=== BEGIN_MPI_T_CVAR_INFO_BLOCK ===
cvars:
- name : MPIR_CVAR_REQUEST_ERR_FATAL
category : REQUEST
type : boolean
default : false
class : none
verbosity : MPI_T_VERBOSITY_USER_BASIC
scope : MPI_T_SCOPE_LOCAL
description : >-
By default, MPI_Waitall, MPI_Testall, MPI_Waitsome, and MPI_Testsome
return MPI_ERR_IN_STATUS when one of the request fails. If
MPIR_CVAR_REQUEST_ERR_FATAL is set to true, these routines will
return the error code of the request immediately. The default
MPI_ERRS_ARE_FATAL error handler will dump a error stack in this
case, which maybe more convenient for debugging. This cvar will also
make nonblocking shched return error right away as it issues
operations.
=== END_MPI_T_CVAR_INFO_BLOCK ===
*/
int MPIR_Status_set_cancelled_impl(MPI_Status * status, int flag)
{
MPIR_STATUS_SET_CANCEL_BIT(*status, flag ? TRUE : FALSE);
return MPI_SUCCESS;
}
int MPIR_Test_cancelled_impl(const MPI_Status * status, int *flag)
{
*flag = MPIR_STATUS_GET_CANCEL_BIT(*status);
return MPI_SUCCESS;
}
int MPIR_Cancel_impl(MPIR_Request * request_ptr)
{
int mpi_errno = MPI_SUCCESS;
switch (request_ptr->kind) {
case MPIR_REQUEST_KIND__SEND:
{
mpi_errno = MPID_Cancel_send(request_ptr);
MPIR_ERR_CHECK(mpi_errno);
break;
}
case MPIR_REQUEST_KIND__RECV:
{
mpi_errno = MPID_Cancel_recv(request_ptr);
MPIR_ERR_CHECK(mpi_errno);
break;
}
case MPIR_REQUEST_KIND__PREQUEST_SEND:
{
if (request_ptr->u.persist.real_request != NULL) {
if (request_ptr->u.persist.real_request->kind != MPIR_REQUEST_KIND__GREQUEST) {
/* jratt@us.ibm.com: I don't know about the bsend
* comment below, but the CC stuff on the next
* line is *really* needed for persistent Bsend
* request cancels. The CC of the parent was
* disconnected from the child to allow an
* MPI_Wait in user-level to complete immediately
* (mpid/dcmfd/src/persistent/mpid_startall.c).
* However, if the user tries to cancel the parent
* (and thereby cancels the child), we cannot just
* say the request is done. We need to re-link
* the parent's cc_ptr to the child CC, thus
* causing an MPI_Wait on the parent to block
* until the child is canceled or completed.
*/
request_ptr->cc_ptr = request_ptr->u.persist.real_request->cc_ptr;
mpi_errno = MPID_Cancel_send(request_ptr->u.persist.real_request);
MPIR_ERR_CHECK(mpi_errno);
} else {
/* This is needed for persistent Bsend requests */
/* FIXME why do we directly access the partner request's
* cc field? shouldn't our cc_ptr be set to the address
* of the partner req's cc field? */
mpi_errno = MPIR_Grequest_cancel(request_ptr->u.persist.real_request,
MPIR_cc_is_complete(&request_ptr->
u.persist.
real_request->cc));
MPIR_ERR_CHECK(mpi_errno);
}
} else {
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_REQUEST, "**requestpersistactive");
}
break;
}
case MPIR_REQUEST_KIND__PREQUEST_RECV:
{
if (request_ptr->u.persist.real_request != NULL) {
mpi_errno = MPID_Cancel_recv(request_ptr->u.persist.real_request);
MPIR_ERR_CHECK(mpi_errno);
} else {
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_REQUEST, "**requestpersistactive");
}
break;
}
case MPIR_REQUEST_KIND__PREQUEST_COLL:
{
if (request_ptr->u.persist_coll.real_request != NULL) {
MPIR_Assert_error("Cancel persistent collective not supported");
} else {
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_REQUEST, "**requestpersistactive");
}
break;
}
case MPIR_REQUEST_KIND__GREQUEST:
{
mpi_errno =
MPIR_Grequest_cancel(request_ptr, MPIR_cc_is_complete(&request_ptr->cc));
MPIR_ERR_CHECK(mpi_errno);
break;
}
/* --BEGIN ERROR HANDLING-- */
default:
{
MPIR_ERR_SETANDJUMP(mpi_errno, MPI_ERR_INTERN, "**cancelunknown");
}
/* --END ERROR HANDLING-- */
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Request_free_impl(MPIR_Request * request_ptr)
{
int mpi_errno = MPI_SUCCESS;
MPID_Progress_poke();
switch (request_ptr->kind) {
case MPIR_REQUEST_KIND__SEND:
case MPIR_REQUEST_KIND__RECV:
break;
case MPIR_REQUEST_KIND__PREQUEST_SEND:
/* Tell the device that we are freeing a persistent request object */
MPID_Prequest_free_hook(request_ptr);
/* If this is an active persistent request, we must also
* release the partner request. */
if (request_ptr->u.persist.real_request != NULL) {
if (request_ptr->u.persist.real_request->kind == MPIR_REQUEST_KIND__GREQUEST) {
/* This is needed for persistent Bsend requests */
mpi_errno = MPIR_Grequest_free(request_ptr->u.persist.real_request);
}
MPIR_Request_free(request_ptr->u.persist.real_request);
}
break;
case MPIR_REQUEST_KIND__PREQUEST_RECV:
/* Tell the device that we are freeing a persistent request object */
MPID_Prequest_free_hook(request_ptr);
/* If this is an active persistent request, we must also
* release the partner request. */
if (request_ptr->u.persist.real_request != NULL) {
MPIR_Request_free(request_ptr->u.persist.real_request);
}
break;
case MPIR_REQUEST_KIND__PREQUEST_COLL:
MPIR_Persist_coll_free_cb(request_ptr);
break;
case MPIR_REQUEST_KIND__GREQUEST:
mpi_errno = MPIR_Grequest_free(request_ptr);
break;
case MPIR_REQUEST_KIND__PART_SEND:
case MPIR_REQUEST_KIND__PART_RECV:
MPID_Part_request_free_hook(request_ptr);
break;
default:
mpi_errno = MPIR_Err_create_code(MPI_SUCCESS, MPIR_ERR_RECOVERABLE,
__func__, __LINE__, MPI_ERR_OTHER,
"**request_invalid_kind",
"**request_invalid_kind %d", request_ptr->kind);
goto fn_fail;
}
MPIR_Request_free(request_ptr);
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Request_get_status_impl(MPIR_Request * request_ptr, int *flag, MPI_Status * status)
{
int mpi_errno = MPI_SUCCESS;
if (!MPIR_Request_is_complete(request_ptr)) {
/* request not complete. poke the progress engine. Req #3130 */
mpi_errno = MPID_Progress_test(NULL);
MPIR_ERR_CHECK(mpi_errno);
}
if (MPIR_Request_is_complete(request_ptr)) {
MPIR_Request *prequest_ptr;
int rc;
switch (request_ptr->kind) {
case MPIR_REQUEST_KIND__SEND:
MPIR_Status_set_cancel_bit(status, MPIR_STATUS_GET_CANCEL_BIT(request_ptr->status));
mpi_errno = request_ptr->status.MPI_ERROR;
break;
case MPIR_REQUEST_KIND__RECV:
MPIR_Request_extract_status(request_ptr, status);
mpi_errno = request_ptr->status.MPI_ERROR;
break;
case MPIR_REQUEST_KIND__PREQUEST_SEND:
prequest_ptr = request_ptr->u.persist.real_request;
if (prequest_ptr != NULL) {
if (prequest_ptr->kind != MPIR_REQUEST_KIND__GREQUEST) {
MPIR_Status_set_cancel_bit(status,
MPIR_STATUS_GET_CANCEL_BIT(request_ptr->status));
mpi_errno = prequest_ptr->status.MPI_ERROR;
} else {
/* This is needed for persistent Bsend requests */
rc = MPIR_Grequest_query(prequest_ptr);
if (mpi_errno == MPI_SUCCESS) {
mpi_errno = rc;
}
MPIR_Status_set_cancel_bit(status,
MPIR_STATUS_GET_CANCEL_BIT
(prequest_ptr->status));
if (mpi_errno == MPI_SUCCESS) {
mpi_errno = prequest_ptr->status.MPI_ERROR;
}
}
} else {
if (request_ptr->status.MPI_ERROR != MPI_SUCCESS) {
/* if the persistent request failed to start then
* make the error code available */
MPIR_Status_set_cancel_bit(status,
MPIR_STATUS_GET_CANCEL_BIT(request_ptr->status));
mpi_errno = request_ptr->status.MPI_ERROR;
} else {
MPIR_Status_set_empty(status);
}
}
break;
case MPIR_REQUEST_KIND__PREQUEST_RECV:
prequest_ptr = request_ptr->u.persist.real_request;
if (prequest_ptr != NULL) {
MPIR_Request_extract_status(prequest_ptr, status);
mpi_errno = prequest_ptr->status.MPI_ERROR;
} else {
/* if the persistent request failed to start then
* make the error code available */
mpi_errno = request_ptr->status.MPI_ERROR;
MPIR_Status_set_empty(status);
}
break;
case MPIR_REQUEST_KIND__PREQUEST_COLL:
prequest_ptr = request_ptr->u.persist_coll.real_request;
if (prequest_ptr != NULL) {
MPIR_Request_extract_status(prequest_ptr, status);
mpi_errno = prequest_ptr->status.MPI_ERROR;
} else {
/* if the persistent request failed to start then
* make the error code available */
mpi_errno = request_ptr->status.MPI_ERROR;
MPIR_Status_set_empty(status);
}
break;
case MPIR_REQUEST_KIND__GREQUEST:
rc = MPIR_Grequest_query(request_ptr);
if (mpi_errno == MPI_SUCCESS) {
mpi_errno = rc;
}
MPIR_Status_set_cancel_bit(status, MPIR_STATUS_GET_CANCEL_BIT(request_ptr->status));
MPIR_Request_extract_status(request_ptr, status);
break;
default:
break;
}
*flag = TRUE;
} else {
*flag = FALSE;
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Test -- */
int MPIR_Test_state(MPIR_Request * request_ptr, int *flag, MPI_Status * status,
MPID_Progress_state * state)
{
int mpi_errno = MPI_SUCCESS;
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
if (MPIR_Request_has_poll_fn(request_ptr)) {
mpi_errno = MPIR_Grequest_poll(request_ptr, status);
MPIR_ERR_CHECK(mpi_errno);
}
if (MPIR_Request_is_complete(request_ptr))
*flag = TRUE;
else
*flag = FALSE;
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Test_impl(MPIR_Request * request_ptr, int *flag, MPI_Status * status)
{
return MPIR_Test_state(request_ptr, flag, status, NULL);
}
int MPIR_Test(MPI_Request * request, int *flag, MPI_Status * status)
{
int mpi_errno = MPI_SUCCESS;
MPIR_Request *request_ptr = NULL;
/* If this is a null request handle, then return an empty status */
if (*request == MPI_REQUEST_NULL) {
MPIR_Status_set_empty(status);
*flag = TRUE;
goto fn_exit;
}
MPIR_Request_get_ptr(*request, request_ptr);
MPIR_Assert(request_ptr != NULL);
mpi_errno = MPID_Test(request_ptr, flag, status);
MPIR_ERR_CHECK(mpi_errno);
if (*flag) {
mpi_errno = MPIR_Request_completion_processing(request_ptr, status);
if (!MPIR_Request_is_persistent(request_ptr) && !MPIR_Request_is_partitioned(request_ptr)) {
MPIR_Request_free(request_ptr);
*request = MPI_REQUEST_NULL;
}
MPIR_ERR_CHECK(mpi_errno);
/* Fall through to the exit */
} else if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptr))) {
MPIR_ERR_SET(mpi_errno, MPIX_ERR_PROC_FAILED_PENDING, "**failure_pending");
if (status != MPI_STATUS_IGNORE)
status->MPI_ERROR = mpi_errno;
goto fn_fail;
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Testall -- */
int MPIR_Testall_state(int count, MPIR_Request * request_ptrs[], int *flag,
MPI_Status array_of_statuses[], int requests_property,
MPID_Progress_state * state)
{
int i;
int mpi_errno = MPI_SUCCESS;
int n_completed = 0;
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
if (requests_property & MPIR_REQUESTS_PROPERTY__NO_GREQUESTS) {
for (i = 0; i < count; i++) {
if ((i + 1) % MPIR_CVAR_REQUEST_POLL_FREQ == 0) {
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
}
if (request_ptrs[i] == NULL || MPIR_Request_is_complete(request_ptrs[i])) {
n_completed++;
} else {
break;
}
}
} else {
for (i = 0; i < count; i++) {
if ((i + 1) % MPIR_CVAR_REQUEST_POLL_FREQ == 0) {
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
}
if (request_ptrs[i] != NULL) {
if (MPIR_Request_has_poll_fn(request_ptrs[i])) {
mpi_errno = MPIR_Grequest_poll(request_ptrs[i], &array_of_statuses[i]);
MPIR_ERR_CHECK(mpi_errno);
}
if (MPIR_Request_is_complete(request_ptrs[i])) {
n_completed++;
}
} else {
n_completed++;
}
}
}
*flag = (n_completed == count) ? TRUE : FALSE;
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Testall_impl(int count, MPIR_Request * request_ptrs[], int *flag,
MPI_Status array_of_statuses[], int requests_property)
{
return MPIR_Testall_state(count, request_ptrs, flag, array_of_statuses,
requests_property, NULL);
}
int MPIR_Testall(int count, MPI_Request array_of_requests[], int *flag,
MPI_Status array_of_statuses[])
{
MPIR_Request *request_ptr_array[MPIR_REQUEST_PTR_ARRAY_SIZE];
MPIR_Request **request_ptrs = request_ptr_array;
int i;
int n_completed;
int active_flag;
int rc = MPI_SUCCESS;
int proc_failure = FALSE;
int mpi_errno = MPI_SUCCESS;
int requests_property = MPIR_REQUESTS_PROPERTY__OPT_ALL;
int ignoring_status = (array_of_statuses == MPI_STATUSES_IGNORE);
MPIR_CHKLMEM_DECL(1);
int ii, icount, impi_errno;
n_completed = 0;
/* Convert MPI request handles to a request object pointers */
if (count > MPIR_REQUEST_PTR_ARRAY_SIZE) {
MPIR_CHKLMEM_MALLOC_ORJUMP(request_ptrs, MPIR_Request **,
count * sizeof(MPIR_Request *), mpi_errno, "request pointers",
MPL_MEM_OBJECT);
}
for (ii = 0; ii < count; ii += MPIR_CVAR_REQUEST_BATCH_SIZE) {
icount = count - ii > MPIR_CVAR_REQUEST_BATCH_SIZE ?
MPIR_CVAR_REQUEST_BATCH_SIZE : count - ii;
requests_property = MPIR_REQUESTS_PROPERTY__OPT_ALL;
for (i = ii; i < ii + icount; i++) {
if (array_of_requests[i] != MPI_REQUEST_NULL) {
MPIR_Request_get_ptr(array_of_requests[i], request_ptrs[i]);
/* Validate object pointers if error checking is enabled */
#ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS;
{
MPIR_Request_valid_ptr(request_ptrs[i], mpi_errno);
if (mpi_errno)
goto fn_fail;
}
MPID_END_ERROR_CHECKS;
}
#endif
if (request_ptrs[i]->kind != MPIR_REQUEST_KIND__RECV &&
request_ptrs[i]->kind != MPIR_REQUEST_KIND__SEND) {
requests_property &= ~MPIR_REQUESTS_PROPERTY__SEND_RECV_ONLY;
if (request_ptrs[i]->kind == MPIR_REQUEST_KIND__GREQUEST) {
requests_property &= ~MPIR_REQUESTS_PROPERTY__NO_GREQUESTS;
}
}
} else {
request_ptrs[i] = NULL;
requests_property &= ~MPIR_REQUESTS_PROPERTY__NO_NULL;
}
}
impi_errno = MPID_Testall(icount, &request_ptrs[ii], flag,
ignoring_status ? MPI_STATUSES_IGNORE : &array_of_statuses[ii],
requests_property);
if (impi_errno != MPI_SUCCESS) {
mpi_errno = impi_errno;
goto fn_fail;
}
for (i = ii; i < ii + icount; i++) {
if (request_ptrs[i] == NULL || MPIR_Request_is_complete(request_ptrs[i]))
n_completed += 1;
#ifdef HAVE_ERROR_CHECKING
{
MPID_BEGIN_ERROR_CHECKS;
{
if (request_ptrs[i] == NULL)
continue;
if (MPIR_Request_is_complete(request_ptrs[i])) {
rc = MPIR_Request_get_error(request_ptrs[i]);
if (rc != MPI_SUCCESS) {
if (MPIX_ERR_PROC_FAILED == MPIR_ERR_GET_CLASS(rc) ||
MPIX_ERR_PROC_FAILED_PENDING == MPIR_ERR_GET_CLASS(rc))
proc_failure = TRUE;
if (MPIR_CVAR_REQUEST_ERR_FATAL) {
mpi_errno = request_ptrs[i]->status.MPI_ERROR;
MPIR_ERR_CHECK(mpi_errno);
} else {
mpi_errno = MPI_ERR_IN_STATUS;
}
}
} else if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptrs[i]))) {
mpi_errno = MPI_ERR_IN_STATUS;
MPIR_ERR_SET(rc, MPIX_ERR_PROC_FAILED_PENDING, "**failure_pending");
if (!ignoring_status)
array_of_statuses[i].MPI_ERROR = rc;
proc_failure = TRUE;
}
}
MPID_END_ERROR_CHECKS;
}
#endif
}
}
*flag = (n_completed == count) ? TRUE : FALSE;
/* We only process completion of requests if all are finished, or
* there is an error. */
if (!(*flag || mpi_errno == MPI_ERR_IN_STATUS))
goto fn_exit;
if (ignoring_status && (requests_property & MPIR_REQUESTS_PROPERTY__SEND_RECV_ONLY)) {
for (i = 0; i < count; i++) {
if (request_ptrs[i] != NULL && MPIR_Request_is_complete(request_ptrs[i]))
MPIR_Request_completion_processing_fastpath(&array_of_requests[i], request_ptrs[i]);
}
goto fn_exit;
}
if (ignoring_status) {
for (i = 0; i < count; i++) {
if (request_ptrs[i] != NULL && MPIR_Request_is_complete(request_ptrs[i])) {
MPIR_Request_completion_processing(request_ptrs[i], MPI_STATUS_IGNORE);
if (!MPIR_Request_is_persistent(request_ptrs[i]) &&
!MPIR_Request_is_partitioned(request_ptrs[i])) {
MPIR_Request_free(request_ptrs[i]);
array_of_requests[i] = MPI_REQUEST_NULL;
}
}
}
goto fn_exit;
}
for (i = 0; i < count; i++) {
if (request_ptrs[i] != NULL) {
if (MPIR_Request_is_complete(request_ptrs[i])) {
active_flag = MPIR_Request_is_active(request_ptrs[i]);
rc = MPIR_Request_completion_processing(request_ptrs[i], &array_of_statuses[i]);
if (!MPIR_Request_is_persistent(request_ptrs[i]) &&
!MPIR_Request_is_partitioned(request_ptrs[i])) {
MPIR_Request_free(request_ptrs[i]);
array_of_requests[i] = MPI_REQUEST_NULL;
}
if (mpi_errno == MPI_ERR_IN_STATUS) {
if (active_flag) {
array_of_statuses[i].MPI_ERROR = rc;
} else {
array_of_statuses[i].MPI_ERROR = MPI_SUCCESS;
}
}
} else {
if (mpi_errno == MPI_ERR_IN_STATUS) {
if (!proc_failure)
array_of_statuses[i].MPI_ERROR = MPI_ERR_PENDING;
else
array_of_statuses[i].MPI_ERROR = MPIX_ERR_PROC_FAILED_PENDING;
}
}
} else {
MPIR_Status_set_empty(&array_of_statuses[i]);
if (mpi_errno == MPI_ERR_IN_STATUS) {
array_of_statuses[i].MPI_ERROR = MPI_SUCCESS;
}
}
}
fn_exit:
if (count > MPIR_REQUEST_PTR_ARRAY_SIZE) {
MPIR_CHKLMEM_FREEALL();
}
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Testany -- */
int MPIR_Testany_state(int count, MPIR_Request * request_ptrs[],
int *indx, int *flag, MPI_Status * status, MPID_Progress_state * state)
{
int i;
int n_inactive = 0;
int mpi_errno = MPI_SUCCESS;
mpi_errno = MPID_Progress_test(state);
/* --BEGIN ERROR HANDLING-- */
MPIR_ERR_CHECK(mpi_errno);
/* --END ERROR HANDLING-- */
for (i = 0; i < count; i++) {
if ((i + 1) % MPIR_CVAR_REQUEST_POLL_FREQ == 0) {
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
}
if (request_ptrs[i] != NULL && MPIR_Request_has_poll_fn(request_ptrs[i])) {
mpi_errno = MPIR_Grequest_poll(request_ptrs[i], status);
if (mpi_errno != MPI_SUCCESS)
goto fn_fail;
}
if (!MPIR_Request_is_active(request_ptrs[i])) {
n_inactive += 1;
} else if (MPIR_Request_is_complete(request_ptrs[i])) {
*flag = TRUE;
*indx = i;
goto fn_exit;
}
}
if (n_inactive == count) {
*flag = TRUE;
*indx = MPI_UNDEFINED;
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Testany_impl(int count, MPIR_Request * request_ptrs[],
int *indx, int *flag, MPI_Status * status)
{
return MPIR_Testany_state(count, request_ptrs, indx, flag, status, NULL);
}
int MPIR_Testany(int count, MPI_Request array_of_requests[], MPIR_Request * request_ptrs[],
int *indx, int *flag, MPI_Status * status)
{
int mpi_errno = MPI_SUCCESS;
int n_inactive = 0;
int last_disabled_anysource = -1;
int first_nonnull = count;
*flag = FALSE;
*indx = MPI_UNDEFINED;
for (int i = 0; i < count; i++) {
if (array_of_requests[i] != MPI_REQUEST_NULL) {
if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptrs[i]))) {
last_disabled_anysource = i;
}
if (MPIR_Request_is_complete(request_ptrs[i])) {
if (MPIR_Request_is_active(request_ptrs[i])) {
*indx = i;
*flag = TRUE;
break;
} else {
request_ptrs[i] = NULL;
}
} else {
if (first_nonnull == count)
first_nonnull = i;
}
} else {
request_ptrs[i] = NULL;
n_inactive += 1;
}
}
if (n_inactive == count) {
*flag = TRUE;
*indx = MPI_UNDEFINED;
if (status != NULL) /* could be null if count=0 */
MPIR_Status_set_empty(status);
goto fn_exit;
}
if (*indx == MPI_UNDEFINED) {
mpi_errno =
MPID_Testany(count - first_nonnull, &request_ptrs[first_nonnull], indx, flag, status);
/* --BEGIN ERROR HANDLING-- */
if (mpi_errno != MPI_SUCCESS) {
goto fn_fail;
}
/* --END ERROR HANDLING-- */
if (*indx != MPI_UNDEFINED) {
*indx += first_nonnull;
}
}
if (*indx != MPI_UNDEFINED) {
mpi_errno = MPIR_Request_completion_processing(request_ptrs[*indx], status);
if (!MPIR_Request_is_persistent(request_ptrs[*indx]) &&
!MPIR_Request_is_partitioned(request_ptrs[*indx])) {
MPIR_Request_free(request_ptrs[*indx]);
array_of_requests[*indx] = MPI_REQUEST_NULL;
}
MPIR_ERR_CHECK(mpi_errno);
goto fn_exit;
}
/* If none of the requests completed, mark the last anysource request as
* pending failure. */
if (unlikely(last_disabled_anysource != -1)) {
MPIR_ERR_SET(mpi_errno, MPIX_ERR_PROC_FAILED_PENDING, "**failure_pending");
if (status != MPI_STATUS_IGNORE)
status->MPI_ERROR = mpi_errno;
*flag = TRUE;
goto fn_fail;
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Testsome -- */
int MPIR_Testsome_state(int incount, MPIR_Request * request_ptrs[],
int *outcount, int array_of_indices[], MPI_Status array_of_statuses[],
MPID_Progress_state * state)
{
int i;
int n_inactive;
int mpi_errno = MPI_SUCCESS;
mpi_errno = MPID_Progress_test(state);
/* --BEGIN ERROR HANDLING-- */
MPIR_ERR_CHECK(mpi_errno);
/* --END ERROR HANDLING-- */
n_inactive = 0;
*outcount = 0;
for (i = 0; i < incount; i++) {
if ((i + 1) % MPIR_CVAR_REQUEST_POLL_FREQ == 0) {
mpi_errno = MPID_Progress_test(state);
MPIR_ERR_CHECK(mpi_errno);
}
if (request_ptrs[i] != NULL && MPIR_Request_has_poll_fn(request_ptrs[i])) {
mpi_errno = MPIR_Grequest_poll(request_ptrs[i], &array_of_statuses[i]);
if (mpi_errno != MPI_SUCCESS)
goto fn_fail;
}
if (!MPIR_Request_is_active(request_ptrs[i])) {
n_inactive += 1;
} else if (MPIR_Request_is_complete(request_ptrs[i])) {
array_of_indices[*outcount] = i;
*outcount += 1;
}
}
if (n_inactive == incount)
*outcount = MPI_UNDEFINED;
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
int MPIR_Testsome_impl(int incount, MPIR_Request * request_ptrs[],
int *outcount, int array_of_indices[], MPI_Status array_of_statuses[])
{
return MPIR_Testsome_state(incount, request_ptrs, outcount, array_of_indices,
array_of_statuses, NULL);
}
int MPIR_Testsome(int incount, MPI_Request array_of_requests[], MPIR_Request * request_ptrs[],
int *outcount, int array_of_indices[], MPI_Status array_of_statuses[])
{
int mpi_errno = MPI_SUCCESS;
int n_inactive;
int proc_failure = FALSE;
*outcount = 0;
n_inactive = 0;
for (int i = 0; i < incount; i++) {
if (array_of_requests[i] != MPI_REQUEST_NULL) {
if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptrs[i]))) {
proc_failure = TRUE;
int rc = MPI_SUCCESS;
MPIR_ERR_SET(rc, MPIX_ERR_PROC_FAILED_PENDING, "**failure_pending");
if (array_of_statuses != MPI_STATUSES_IGNORE)
array_of_statuses[i].MPI_ERROR = rc;
}
} else {
request_ptrs[i] = NULL;
n_inactive += 1;
}
}
if (n_inactive == incount) {
*outcount = MPI_UNDEFINED;
goto fn_exit;
}
mpi_errno = MPID_Testsome(incount, request_ptrs, outcount, array_of_indices, array_of_statuses);
/* --BEGIN ERROR HANDLING-- */
if (mpi_errno != MPI_SUCCESS)
goto fn_fail;
/* --END ERROR HANDLING-- */
if (proc_failure)
mpi_errno = MPI_ERR_IN_STATUS;
if (*outcount == MPI_UNDEFINED)
goto fn_exit;
for (int i = 0; i < *outcount; i++) {
int idx = array_of_indices[i];
MPI_Status *status_ptr = (array_of_statuses == MPI_STATUSES_IGNORE) ?
MPI_STATUS_IGNORE : &array_of_statuses[i];
int rc = MPIR_Request_completion_processing(request_ptrs[idx], status_ptr);
if (!MPIR_Request_is_persistent(request_ptrs[idx]) &&
!MPIR_Request_is_partitioned(request_ptrs[idx])) {
MPIR_Request_free(request_ptrs[idx]);
array_of_requests[idx] = MPI_REQUEST_NULL;
}
if (rc == MPI_SUCCESS) {
request_ptrs[idx] = NULL;
} else {
if (MPIR_CVAR_REQUEST_ERR_FATAL) {
mpi_errno = request_ptrs[idx]->status.MPI_ERROR;
MPIR_ERR_CHECK(mpi_errno);
} else {
mpi_errno = MPI_ERR_IN_STATUS;
if (status_ptr != MPI_STATUS_IGNORE) {
status_ptr->MPI_ERROR = rc;
}
}
}
}
if (mpi_errno == MPI_ERR_IN_STATUS) {
if (array_of_statuses != MPI_STATUSES_IGNORE) {
for (int i = 0; i < *outcount; i++) {
if (request_ptrs[array_of_indices[i]] == NULL) {
array_of_statuses[i].MPI_ERROR = MPI_SUCCESS;
}
}
}
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Wait -- */
/* MPID_Wait call MPIR_Wait_state with initialized progress state */
int MPIR_Wait_state(MPIR_Request * request_ptr, MPI_Status * status, MPID_Progress_state * state)
{
int mpi_errno = MPI_SUCCESS;
while (!MPIR_Request_is_complete(request_ptr)) {
mpi_errno = MPID_Progress_wait(state);
MPIR_ERR_CHECK(mpi_errno);
if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptr))) {
mpi_errno = MPIR_Request_handle_proc_failed(request_ptr);
goto fn_fail;
}
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* legacy interface (for ch3) */
int MPIR_Wait_impl(MPIR_Request * request_ptr, MPI_Status * status)
{
int mpi_errno = MPI_SUCCESS;
MPID_Progress_state progress_state;
MPIR_Assert(request_ptr != NULL);
MPID_Progress_start(&progress_state);
mpi_errno = MPIR_Wait_state(request_ptr, status, &progress_state);
MPID_Progress_end(&progress_state);
return mpi_errno;
}
int MPIR_Wait(MPI_Request * request, MPI_Status * status)
{
int mpi_errno = MPI_SUCCESS;
int active_flag;
MPIR_Request *request_ptr = NULL;
/* If this is a null request handle, then return an empty status */
if (*request == MPI_REQUEST_NULL) {
MPIR_Status_set_empty(status);
goto fn_exit;
}
MPIR_Request_get_ptr(*request, request_ptr);
MPIR_Assert(request_ptr != NULL);
if (!MPIR_Request_is_complete(request_ptr)) {
/* If this is an anysource request including a communicator with
* anysource disabled, convert the call to an MPI_Test instead so we
* don't get stuck in the progress engine. */
if (unlikely(MPIR_Request_is_anysrc_mismatched(request_ptr))) {
mpi_errno = MPIR_Test(request, &active_flag, status);
goto fn_exit;
}
if (MPIR_Request_has_poll_fn(request_ptr)) {
while (!MPIR_Request_is_complete(request_ptr)) {
mpi_errno = MPIR_Grequest_poll(request_ptr, status);
MPIR_ERR_CHECK(mpi_errno);
/* Avoid blocking other threads since I am inside an infinite loop */
MPID_THREAD_CS_YIELD(GLOBAL, MPIR_THREAD_GLOBAL_ALLFUNC_MUTEX);
}
} else {
mpi_errno = MPID_Wait(request_ptr, status);
MPIR_ERR_CHECK(mpi_errno);
}
}
mpi_errno = MPIR_Request_completion_processing(request_ptr, status);
if (!MPIR_Request_is_persistent(request_ptr) && !MPIR_Request_is_partitioned(request_ptr)) {
MPIR_Request_free(request_ptr);
*request = MPI_REQUEST_NULL;
}
MPIR_ERR_CHECK(mpi_errno);
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* -- Waitall -- */
/* MPID_Waitall call MPIR_Waitall_state with initialized progress state */
int MPIR_Waitall_state(int count, MPIR_Request * request_ptrs[], MPI_Status array_of_statuses[],
int requests_property, MPID_Progress_state * state)
{
int mpi_errno = MPI_SUCCESS;
if (requests_property & MPIR_REQUESTS_PROPERTY__NO_NULL) {
for (int i = 0; i < count; ++i) {
while (!MPIR_Request_is_complete(request_ptrs[i])) {
mpi_errno = MPID_Progress_wait(state);
MPIR_ERR_CHECK(mpi_errno);
}
}
} else {
for (int i = 0; i < count; i++) {
if (request_ptrs[i] == NULL) {
continue;
}
/* wait for ith request to complete */
while (!MPIR_Request_is_complete(request_ptrs[i])) {
/* generalized requests should already be finished */
MPIR_Assert(request_ptrs[i]->kind != MPIR_REQUEST_KIND__GREQUEST);
mpi_errno = MPID_Progress_wait(state);
MPIR_ERR_CHECK(mpi_errno);
}
}
}
fn_exit:
return mpi_errno;
fn_fail:
goto fn_exit;
}
/* legacy interface (for ch3) */