Skip to content

Commit af1ec9a

Browse files
authored
Merge pull request #7323 from bosilca/fix/7320
Trap wrong parameters to MPI_Init_thread.
2 parents 19acb32 + ecbd842 commit af1ec9a

File tree

2 files changed

+19
-9
lines changed

2 files changed

+19
-9
lines changed

ompi/errhandler/errhandler_predefined.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ void ompi_mpi_errors_are_fatal_comm_handler(struct ompi_communicator_t **comm,
6161

6262
va_start(arglist, error_code);
6363

64-
if (NULL != comm) {
64+
if ( (NULL != comm) && (NULL != *comm) ) {
6565
name = (*comm)->c_name;
6666
abort_comm = *comm;
6767
} else {

ompi/mpi/c/init_thread.c

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -47,26 +47,36 @@ static const char FUNC_NAME[] = "MPI_Init_thread";
4747
int MPI_Init_thread(int *argc, char ***argv, int required,
4848
int *provided)
4949
{
50-
int err;
50+
int err, safe_required = MPI_THREAD_SERIALIZED;
5151

5252
ompi_hook_base_mpi_init_thread_top(argc, argv, required, provided);
5353

54-
if ( MPI_PARAM_CHECK ) {
55-
if (required < MPI_THREAD_SINGLE || required > MPI_THREAD_MULTIPLE) {
56-
ompi_mpi_errors_are_fatal_comm_handler(NULL, NULL, FUNC_NAME);
57-
}
54+
/* Detect an incorrect thread support level, but dont report until we have the minimum
55+
* infrastructure setup.
56+
*/
57+
if( (MPI_THREAD_SINGLE == required) || (MPI_THREAD_SERIALIZED == required) ||
58+
(MPI_THREAD_FUNNELED == required) || (MPI_THREAD_MULTIPLE == required) ) {
59+
safe_required = required;
5860
}
5961

60-
*provided = required;
62+
*provided = safe_required;
6163

6264
/* Call the back-end initialization function (we need to put as
6365
little in this function as possible so that if it's profiled, we
6466
don't lose anything) */
6567

6668
if (NULL != argc && NULL != argv) {
67-
err = ompi_mpi_init(*argc, *argv, required, provided, false);
69+
err = ompi_mpi_init(*argc, *argv, safe_required, provided, false);
6870
} else {
69-
err = ompi_mpi_init(0, NULL, required, provided, false);
71+
err = ompi_mpi_init(0, NULL, safe_required, provided, false);
72+
}
73+
74+
if( safe_required != required ) {
75+
/* Trigger the error handler for the incorrect argument. Keep it separate from the
76+
* check on the ompi_mpi_init return and report a nice, meaningful error message to
77+
* the user. */
78+
return ompi_errhandler_invoke((ompi_errhandler_t*)&ompi_mpi_errors_are_fatal, NULL, OMPI_ERRHANDLER_TYPE_COMM,
79+
MPI_ERR_ARG, FUNC_NAME);
7080
}
7181

7282
/* Since we don't have a communicator to invoke an errorhandler on

0 commit comments

Comments
 (0)