18
18
* reserved.
19
19
* Copyright (c) 2024 Triad National Security, LLC. All rights
20
20
* reserved.
21
+ * Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
21
22
* $COPYRIGHT$
22
23
*
23
24
* Additional copyrights may follow
@@ -40,21 +41,36 @@ PROTOTYPE ERROR_CLASS init_thread(INT_OUT argc, ARGV argv, INT required,
40
41
INT_OUT provided )
41
42
{
42
43
int err , safe_required = MPI_THREAD_SERIALIZED ;
44
+ bool err_arg_required = false;
43
45
char * env ;
44
46
45
47
ompi_hook_base_mpi_init_thread_top (argc , argv , required , provided );
46
48
47
49
/* Detect an incorrect thread support level, but dont report until we have the minimum
48
50
* infrastructure setup.
49
51
*/
50
- if ( (MPI_THREAD_SINGLE == required ) || (MPI_THREAD_SERIALIZED == required ) ||
51
- (MPI_THREAD_FUNNELED == required ) || (MPI_THREAD_MULTIPLE == required ) ) {
52
+ err_arg_required = (required != MPI_THREAD_SINGLE && required != MPI_THREAD_FUNNELED &&
53
+ required != MPI_THREAD_SERIALIZED && required != MPI_THREAD_MULTIPLE );
54
+ if (!err_arg_required ) {
55
+ safe_required = required ;
56
+ }
52
57
53
- if (NULL != (env = getenv ("OMPI_MPI_THREAD_LEVEL" ))) {
54
- safe_required = atoi (env );
55
- }
56
- else {
57
- safe_required = required ;
58
+ /* check for environment overrides for required thread level. If
59
+ * there is, check to see that it is a valid/supported thread level.
60
+ * If valid, the environment variable always override the provided thread
61
+ * level (even if lower than argument `required`). A user program can
62
+ * check `provided != required` to check if `required` has been overruled.
63
+ */
64
+ if (NULL != (env = getenv ("OMPI_MPI_THREAD_LEVEL" ))) {
65
+ int env_required = atoi (env );
66
+ /* In the future we may have to contend with non-sequential (MPI ABI) values
67
+ * If you are implementing MPI ABI changes please refer to
68
+ * https://github.com/open-mpi/ompi/pull/13211#discussion_r2085086844
69
+ */
70
+ err_arg_required |= (env_required != MPI_THREAD_SINGLE && env_required != MPI_THREAD_FUNNELED &&
71
+ env_required != MPI_THREAD_SERIALIZED && env_required != MPI_THREAD_MULTIPLE );
72
+ if (!err_arg_required ) {
73
+ safe_required = env_required ;
58
74
}
59
75
}
60
76
@@ -70,7 +86,7 @@ PROTOTYPE ERROR_CLASS init_thread(INT_OUT argc, ARGV argv, INT required,
70
86
err = ompi_mpi_init (0 , NULL , safe_required , provided , false);
71
87
}
72
88
73
- if ( safe_required != required ) {
89
+ if ( err_arg_required ) {
74
90
/* Trigger the error handler for the incorrect argument. Keep it separate from the
75
91
* check on the ompi_mpi_init return and report a nice, meaningful error message to
76
92
* the user. */
0 commit comments