Skip to content

Commit 785d110

Browse files
authored
Merge pull request #9311 from awlauria/v4.0.x_threads
v4.0.x: Thread fixes
2 parents 03a757f + 8819790 commit 785d110

File tree

2 files changed

+20
-12
lines changed

2 files changed

+20
-12
lines changed

ompi/mpi/c/init_thread.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ int MPI_Init_thread(int *argc, char ***argv, int required,
4848
int *provided)
4949
{
5050
int err;
51+
char *env;
52+
53+
if (NULL != (env = getenv("OMPI_MPI_THREAD_LEVEL"))) {
54+
required = atoi(env);
55+
}
5156

5257
ompi_hook_base_mpi_init_thread_top(argc, argv, required, provided);
5358

ompi/request/request.h

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -417,21 +417,24 @@ static inline int ompi_request_free(ompi_request_t** request)
417417

418418
static inline void ompi_request_wait_completion(ompi_request_t *req)
419419
{
420-
if (opal_using_threads () && !REQUEST_COMPLETE(req)) {
421-
void *_tmp_ptr = REQUEST_PENDING;
422-
ompi_wait_sync_t sync;
420+
if (opal_using_threads ()) {
421+
if(!REQUEST_COMPLETE(req)) {
422+
void *_tmp_ptr = REQUEST_PENDING;
423+
ompi_wait_sync_t sync;
423424

424-
WAIT_SYNC_INIT(&sync, 1);
425+
WAIT_SYNC_INIT(&sync, 1);
425426

426-
if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, &sync)) {
427-
SYNC_WAIT(&sync);
428-
} else {
429-
/* completed before we had a chance to swap in the sync object */
430-
WAIT_SYNC_SIGNALLED(&sync);
431-
}
427+
if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, &sync)) {
428+
SYNC_WAIT(&sync);
429+
} else {
430+
/* completed before we had a chance to swap in the sync object */
431+
WAIT_SYNC_SIGNALLED(&sync);
432+
}
432433

433-
assert(REQUEST_COMPLETE(req));
434-
WAIT_SYNC_RELEASE(&sync);
434+
assert(REQUEST_COMPLETE(req));
435+
WAIT_SYNC_RELEASE(&sync);
436+
}
437+
opal_atomic_rmb();
435438
} else {
436439
while(!REQUEST_COMPLETE(req)) {
437440
opal_progress();

0 commit comments

Comments
 (0)