@@ -399,13 +399,26 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
399399 /* Indicate that we have *started* MPI_INIT* */
400400 ompi_mpi_init_started = true;
401401
402- /* Setup enough to check get/set MCA params */
402+ /* Figure out the final MPI thread levels. If we were not
403+ compiled for support for MPI threads, then don't allow
404+ MPI_THREAD_MULTIPLE. Set this stuff up here early in the
405+ process so that other components can make decisions based on
406+ this value. */
403407
408+ ompi_mpi_thread_level (requested , provided );
409+
410+ /* Setup enough to check get/set MCA params */
404411 if (OPAL_SUCCESS != (ret = opal_init_util (& argc , & argv ))) {
405412 error = "ompi_mpi_init: opal_init_util failed" ;
406413 goto error ;
407414 }
408415
416+ /* If thread support was enabled, then setup OPAL to allow for them. This must be done
417+ * early to prevent a race condition that can occur with orte_init(). */
418+ if (* provided != MPI_THREAD_SINGLE ) {
419+ opal_set_using_threads (true);
420+ }
421+
409422 /* Convince OPAL to use our naming scheme */
410423 opal_process_name_print = _process_name_print_for_opal ;
411424 opal_compare_proc = _process_name_compare ;
@@ -509,13 +522,6 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
509522 goto error ;
510523 }
511524
512- /* Figure out the final MPI thread levels. If we were not
513- compiled for support for MPI threads, then don't allow
514- MPI_THREAD_MULTIPLE. Set this stuff up here early in the
515- process so that other components can make decisions based on
516- this value. */
517-
518- ompi_mpi_thread_level (requested , provided );
519525
520526 /* determine the bitflag belonging to the threadlevel_support provided */
521527 memset ( & threadlevel_bf , 0 , sizeof (uint8_t ));
@@ -529,13 +535,6 @@ int ompi_mpi_init(int argc, char **argv, int requested, int *provided)
529535 goto error ;
530536 }
531537
532- /* If thread support was enabled, then setup OPAL to allow for
533- them. */
534- if ((OPAL_ENABLE_PROGRESS_THREADS == 1 ) ||
535- (* provided != MPI_THREAD_SINGLE )) {
536- opal_set_using_threads (true);
537- }
538-
539538 /* initialize datatypes. This step should be done early as it will
540539 * create the local convertor and local arch used in the proc
541540 * init.
0 commit comments