Skip to content

Commit 5417155

Browse files
committed
Fix MPI_Waitany and MPI_Waitsome
(request handling related)
1 parent 8d011ea commit 5417155

File tree

2 files changed

+38
-5
lines changed

2 files changed

+38
-5
lines changed

ompi/request/req_wait.c

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* Copyright (c) 2012 Oak Ridge National Labs. All rights reserved.
1616
* Copyright (c) 2016 Los Alamos National Security, LLC. All rights
1717
* reserved.
18+
* Copyright (c) 2016 Mellanox Technologies. All rights reserved.
1819
* $COPYRIGHT$
1920
*
2021
* Additional copyrights may follow
@@ -116,7 +117,8 @@ int ompi_request_default_wait_any(size_t count,
116117
if (MPI_STATUS_IGNORE != status) {
117118
*status = ompi_status_empty;
118119
}
119-
WAIT_SYNC_RELEASE(&sync);
120+
/* No signal-in-flight can be in this case */
121+
WAIT_SYNC_RELEASE_NOWAIT(&sync);
120122
return rc;
121123
}
122124

@@ -140,6 +142,15 @@ int ompi_request_default_wait_any(size_t count,
140142
*index = i;
141143
}
142144
}
145+
146+
if( *index == completed ){
147+
/* Only one request has triggered. There was no
148+
* in-flight completions.
149+
* Drop the signalled flag so we won't block
150+
* in WAIT_SYNC_RELEASE
151+
*/
152+
WAIT_SYNC_SIGNALLED(&sync);
153+
}
143154

144155
request = requests[*index];
145156
assert( REQUEST_COMPLETE(request) );
@@ -361,7 +372,8 @@ int ompi_request_default_wait_some(size_t count,
361372
ompi_request_t **rptr = NULL;
362373
ompi_request_t *request = NULL;
363374
ompi_wait_sync_t sync;
364-
375+
size_t sync_sets = 0, sync_unsets = 0;
376+
365377
WAIT_SYNC_INIT(&sync, 1);
366378

367379
*outcount = 0;
@@ -386,10 +398,12 @@ int ompi_request_default_wait_some(size_t count,
386398
num_requests_done++;
387399
}
388400
}
401+
sync_sets = count - num_requests_null_inactive - num_requests_done;
389402

390403
if(num_requests_null_inactive == count) {
391404
*outcount = MPI_UNDEFINED;
392-
WAIT_SYNC_RELEASE(&sync);
405+
/* nobody will signall us */
406+
WAIT_SYNC_RELEASE_NOWAIT(&sync);
393407
return rc;
394408
}
395409

@@ -420,6 +434,14 @@ int ompi_request_default_wait_some(size_t count,
420434
num_requests_done++;
421435
}
422436
}
437+
sync_unsets = count - num_requests_null_inactive - num_requests_done;
438+
439+
if( sync_sets == sync_unsets ){
440+
/* nobody knows about us,
441+
* set signa-in-progress flag to false
442+
*/
443+
WAIT_SYNC_SIGNALLED(&sync);
444+
}
423445

424446
WAIT_SYNC_RELEASE(&sync);
425447

opal/threads/wait_sync.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,21 +43,32 @@ typedef struct ompi_wait_sync_t {
4343
* the critical path. */
4444
#define WAIT_SYNC_RELEASE(sync) \
4545
if (opal_using_threads()) { \
46-
while ((sync)->signaling) { \
46+
while ((sync)->signaling) { \
4747
continue; \
4848
} \
4949
pthread_cond_destroy(&(sync)->condition); \
5050
pthread_mutex_destroy(&(sync)->lock); \
5151
}
5252

53+
#define WAIT_SYNC_RELEASE_NOWAIT(sync) \
54+
if (opal_using_threads()) { \
55+
pthread_cond_destroy(&(sync)->condition); \
56+
pthread_mutex_destroy(&(sync)->lock); \
57+
}
58+
59+
5360
#define WAIT_SYNC_SIGNAL(sync) \
5461
if (opal_using_threads()) { \
5562
pthread_mutex_lock(&(sync->lock)); \
5663
pthread_cond_signal(&sync->condition); \
5764
pthread_mutex_unlock(&(sync->lock)); \
58-
sync->signaling = false; \
65+
sync->signaling = false; \
5966
}
6067

68+
#define WAIT_SYNC_SIGNALLED(sync){ \
69+
(sync)->signaling = false; \
70+
}
71+
6172
OPAL_DECLSPEC int sync_wait_mt(ompi_wait_sync_t *sync);
6273
static inline int sync_wait_st (ompi_wait_sync_t *sync)
6374
{

0 commit comments

Comments
 (0)