diff --git a/src/mpi/c/get_version.c b/src/mpi/c/get_version.c index d5a8045d33..f9bcbf7483 100644 --- a/src/mpi/c/get_version.c +++ b/src/mpi/c/get_version.c @@ -34,17 +34,36 @@ static const char FUNC_NAME[] = "MPI_Get_version"; int MPI_Get_version(int *version, int *subversion) { - if (MPI_PARAM_CHECK) { - OMPI_ERR_INIT_FINALIZE(FUNC_NAME); - if (NULL == version || NULL == subversion) { - return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, FUNC_NAME); + MPI_Comm null = NULL; + + if (MPI_PARAM_CHECK) { + /* Per MPI-2:3.1, this function can be invoked before + MPI_INIT, so we don't invoke the normal + MPI_ERR_INIT_FINALIZE() macro here */ + + if (NULL == version || NULL == subversion) { + /* Note that we have to check and see if we have + previously called MPI_INIT or not. If so, use the + normal OMPI_ERRHANDLER_INVOKE, because the user may + have changed the default errhandler on MPI_COMM_WORLD. + If we have not invoked MPI_INIT, then just abort + (i.e., use a NULL communicator, which will end up at the + default errhandler, which is abort). */ + + if (ompi_mpi_initialized && !ompi_mpi_finalized) { + return OMPI_ERRHANDLER_INVOKE(MPI_COMM_WORLD, MPI_ERR_ARG, + FUNC_NAME); + } else { + return OMPI_ERRHANDLER_INVOKE(null, MPI_ERR_ARG, + FUNC_NAME); + } + } } - } - /* According to the MPI-2 specification */ + /* According to the MPI-2 specification */ - *version = 2; - *subversion = 0; + *version = 2; + *subversion = 0; - return MPI_SUCCESS; + return MPI_SUCCESS; }