diff --git a/ompi/mpi/c/init_thread.c b/ompi/mpi/c/init_thread.c index 2cdad8ff3af..95ca9df25e2 100644 --- a/ompi/mpi/c/init_thread.c +++ b/ompi/mpi/c/init_thread.c @@ -48,6 +48,7 @@ int MPI_Init_thread(int *argc, char ***argv, int required, int *provided) { int err, safe_required = MPI_THREAD_SERIALIZED; + char *env; ompi_hook_base_mpi_init_thread_top(argc, argv, required, provided); @@ -56,7 +57,13 @@ int MPI_Init_thread(int *argc, char ***argv, int required, */ if( (MPI_THREAD_SINGLE == required) || (MPI_THREAD_SERIALIZED == required) || (MPI_THREAD_FUNNELED == required) || (MPI_THREAD_MULTIPLE == required) ) { - safe_required = required; + + if (NULL != (env = getenv("OMPI_MPI_THREAD_LEVEL"))) { + safe_required = atoi(env); + } + else { + safe_required = required; + } } *provided = safe_required; diff --git a/ompi/request/request.h b/ompi/request/request.h index 5be3f7b46ae..0e6fb80cbf7 100644 --- a/ompi/request/request.h +++ b/ompi/request/request.h @@ -448,39 +448,44 @@ static inline bool ompi_request_tag_is_collective(int tag) { static inline void ompi_request_wait_completion(ompi_request_t *req) { - if (opal_using_threads () && !REQUEST_COMPLETE(req)) { - void *_tmp_ptr; - ompi_wait_sync_t sync; + if (opal_using_threads ()) { + if(!REQUEST_COMPLETE(req)) { + void *_tmp_ptr; + ompi_wait_sync_t sync; + + #if OPAL_ENABLE_FT_MPI -redo: - if(OPAL_UNLIKELY( ompi_request_is_failed(req) )) { - return; - } + redo: + if(OPAL_UNLIKELY( ompi_request_is_failed(req) )) { + return; + } #endif /* OPAL_ENABLE_FT_MPI */ - _tmp_ptr = REQUEST_PENDING; + _tmp_ptr = REQUEST_PENDING; - WAIT_SYNC_INIT(&sync, 1); + WAIT_SYNC_INIT(&sync, 1); - if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, &sync)) { - SYNC_WAIT(&sync); - } else { - /* completed before we had a chance to swap in the sync object */ - WAIT_SYNC_SIGNALLED(&sync); - } + if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, &sync)) { + SYNC_WAIT(&sync); + } else { + /* completed before we had a chance to swap in the sync object */ + WAIT_SYNC_SIGNALLED(&sync); + } #if OPAL_ENABLE_FT_MPI - if (OPAL_UNLIKELY(OMPI_SUCCESS != sync.status)) { - OPAL_OUTPUT_VERBOSE((50, ompi_ftmpi_output_handle, "Status %d reported for sync %p rearming req %p", sync.status, (void*)&sync, (void*)req)); - _tmp_ptr = &sync; - if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, REQUEST_PENDING)) { - opal_output_verbose(10, ompi_ftmpi_output_handle, "Status %d reported for sync %p rearmed req %p", sync.status, (void*)&sync, (void*)req); - WAIT_SYNC_RELEASE(&sync); - goto redo; + if (OPAL_UNLIKELY(OMPI_SUCCESS != sync.status)) { + OPAL_OUTPUT_VERBOSE((50, ompi_ftmpi_output_handle, "Status %d reported for sync %p rearming req %p", sync.status, (void*)&sync, (void*)req)); + _tmp_ptr = &sync; + if (OPAL_ATOMIC_COMPARE_EXCHANGE_STRONG_PTR(&req->req_complete, &_tmp_ptr, REQUEST_PENDING)) { + opal_output_verbose(10, ompi_ftmpi_output_handle, "Status %d reported for sync %p rearmed req %p", sync.status, (void*)&sync, (void*)req); + WAIT_SYNC_RELEASE(&sync); + goto redo; + } } - } #endif /* OPAL_ENABLE_FT_MPI */ - assert(REQUEST_COMPLETE(req)); - WAIT_SYNC_RELEASE(&sync); + assert(REQUEST_COMPLETE(req)); + WAIT_SYNC_RELEASE(&sync); + } + opal_atomic_rmb(); } else { while(!REQUEST_COMPLETE(req)) { opal_progress();