Skip to content

Commit a1b7417

Browse files
committed
bugfix: Setting OMPI_MPI_THREAD_LEVEL to a value different than
`requested` in `MPI_Init_thread` would invoke the error handler, even though it is an useful override in some threaded library use cases. Signed-off-by: Aurelien Bouteiller <[email protected]>
1 parent 1d301f7 commit a1b7417

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

ompi/mpi/c/init_thread.c.in

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,22 +39,29 @@
3939
PROTOTYPE ERROR_CLASS init_thread(INT_OUT argc, ARGV argv, INT required,
4040
INT_OUT provided)
4141
{
42-
int err, safe_required = MPI_THREAD_SERIALIZED;
42+
int err, err_arg_required = false, safe_required = MPI_THREAD_SERIALIZED;
4343
char *env;
4444

4545
ompi_hook_base_mpi_init_thread_top(argc, argv, required, provided);
4646

4747
/* Detect an incorrect thread support level, but dont report until we have the minimum
4848
* infrastructure setup.
4949
*/
50-
if( (MPI_THREAD_SINGLE == required) || (MPI_THREAD_SERIALIZED == required) ||
51-
(MPI_THREAD_FUNNELED == required) || (MPI_THREAD_MULTIPLE == required) ) {
50+
err_arg_required = (required < MPI_THREAD_SINGLE || required > MPI_THREAD_MULTIPLE);
51+
if (!err_arg_required) {
52+
safe_required = required;
53+
}
5254

53-
if (NULL != (env = getenv("OMPI_MPI_THREAD_LEVEL"))) {
54-
safe_required = atoi(env);
55-
}
56-
else {
57-
safe_required = required;
55+
/* check for environment overrides for required thread level. If
56+
* there is, check to see that it is a valid/supported thread level.
57+
* if it is lower than argument required, set it anyway, program can
58+
* check provided == required to verify that required has been ignored
59+
*/
60+
if (NULL != (env = getenv("OMPI_MPI_THREAD_LEVEL"))) {
61+
int env_required = atoi(env);
62+
err_arg_required = err_arg_required || (env_required < MPI_THREAD_SINGLE || env_required > MPI_THREAD_MULTIPLE);
63+
if (!err_arg_required) {
64+
safe_required = env_required;
5865
}
5966
}
6067

@@ -70,7 +77,7 @@ PROTOTYPE ERROR_CLASS init_thread(INT_OUT argc, ARGV argv, INT required,
7077
err = ompi_mpi_init(0, NULL, safe_required, provided, false);
7178
}
7279

73-
if( safe_required != required ) {
80+
if (err_arg_required) {
7481
/* Trigger the error handler for the incorrect argument. Keep it separate from the
7582
* check on the ompi_mpi_init return and report a nice, meaningful error message to
7683
* the user. */

0 commit comments

Comments
 (0)