Skip to content

Commit 7efba63

Browse files
bosilcaThananon Patinyasakdikul
authored andcommitted
Be conservative with the array_of_indices
We were assuming that the array_of_indices has the same size as the number of requests (incount), instead of the numberr of actually active requests. While the patch is trivial, the question of the size of the array_of_indices should be clarified in the MPI Forum. cherry-picked from: a5fbfa4 (PR #4897 ) Signed-off-by: George Bosilca <[email protected]>
1 parent a7dfd94 commit 7efba63

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

ompi/request/req_wait.c

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Copyright (c) 2004-2010 The Trustees of Indiana University and Indiana
44
* University Research and Technology
55
* Corporation. All rights reserved.
6-
* Copyright (c) 2004-2016 The University of Tennessee and The University
6+
* Copyright (c) 2004-2018 The University of Tennessee and The University
77
* of Tennessee Research Foundation. All rights
88
* reserved.
99
* Copyright (c) 2004-2008 High Performance Computing Center Stuttgart,
@@ -378,13 +378,13 @@ int ompi_request_default_wait_some(size_t count,
378378
int * indices,
379379
ompi_status_public_t * statuses)
380380
{
381-
size_t num_requests_null_inactive=0, num_requests_done=0;
381+
size_t num_requests_null_inactive, num_requests_done, num_active_reqs;
382382
int rc = MPI_SUCCESS;
383383
ompi_request_t **rptr = NULL;
384384
ompi_request_t *request = NULL;
385385
ompi_wait_sync_t sync;
386386
size_t sync_sets = 0, sync_unsets = 0;
387-
387+
388388
if (OPAL_UNLIKELY(0 == count)) {
389389
*outcount = MPI_UNDEFINED;
390390
return OMPI_SUCCESS;
@@ -397,6 +397,7 @@ int ompi_request_default_wait_some(size_t count,
397397
rptr = requests;
398398
num_requests_null_inactive = 0;
399399
num_requests_done = 0;
400+
num_active_reqs = 0;
400401
for (size_t i = 0; i < count; i++, rptr++) {
401402
request = *rptr;
402403
/*
@@ -407,14 +408,14 @@ int ompi_request_default_wait_some(size_t count,
407408
num_requests_null_inactive++;
408409
continue;
409410
}
410-
indices[i] = OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, &sync);
411-
if( !indices[i] ) {
411+
indices[num_active_reqs] = OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, REQUEST_PENDING, &sync);
412+
if( !indices[num_active_reqs] ) {
412413
/* If the request is completed go ahead and mark it as such */
413414
assert( REQUEST_COMPLETE(request) );
414415
num_requests_done++;
415416
}
417+
num_active_reqs++;
416418
}
417-
sync_sets = count - num_requests_null_inactive - num_requests_done;
418419

419420
if(num_requests_null_inactive == count) {
420421
*outcount = MPI_UNDEFINED;
@@ -423,6 +424,7 @@ int ompi_request_default_wait_some(size_t count,
423424
return rc;
424425
}
425426

427+
sync_sets = num_active_reqs - num_requests_done;
426428
if( 0 == num_requests_done ) {
427429
/* One completed request is enough to satisfy the some condition */
428430
SYNC_WAIT(&sync);
@@ -433,6 +435,7 @@ int ompi_request_default_wait_some(size_t count,
433435

434436
rptr = requests;
435437
num_requests_done = 0;
438+
num_active_reqs = 0;
436439
for (size_t i = 0; i < count; i++, rptr++) {
437440
request = *rptr;
438441

@@ -452,13 +455,14 @@ int ompi_request_default_wait_some(size_t count,
452455
* either slowly (in case of partial completion)
453456
* OR in parallel with `i` (in case of full set completion)
454457
*/
455-
if( !indices[i] ){
458+
if( !indices[num_active_reqs] ) {
456459
indices[num_requests_done++] = i;
457460
} else if( !OPAL_ATOMIC_CMPSET_PTR(&request->req_complete, &sync, REQUEST_PENDING) ) {
458461
indices[num_requests_done++] = i;
459462
}
463+
num_active_reqs++;
460464
}
461-
sync_unsets = count - num_requests_null_inactive - num_requests_done;
465+
sync_unsets = num_active_reqs - num_requests_done;
462466

463467
if( sync_sets == sync_unsets ){
464468
/* nobody knows about us,

0 commit comments

Comments
 (0)