From c9044d8e1b1d3b4b549af57f8c90e476899da777 Mon Sep 17 00:00:00 2001 From: Achim Gsell Date: Fri, 1 Jul 2016 16:10:37 +0200 Subject: [PATCH] src/h5core/private/h5_init.{c,h} - initialize MPI if not yet done --- src/h5core/private/h5_init.c | 8 +++++++- src/h5core/private/h5_init.h | 1 + 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/src/h5core/private/h5_init.c b/src/h5core/private/h5_init.c index 56b62b3..45be4ec 100644 --- a/src/h5core/private/h5_init.c +++ b/src/h5core/private/h5_init.c @@ -666,11 +666,17 @@ h5_err_t h5priv_initialize ( void ) { - h5_initialized = 1; memset (&h5_call_stack, 0, sizeof (h5_call_stack)); + // must be set here, otherwise next statement will fail! + h5_initialized = 1; H5_CORE_API_ENTER (h5_err_t, "%s", "void"); ret_value = H5_SUCCESS; #ifdef PARALLEL_IO + int mpi_is_initialized; + MPI_Initialized (&mpi_is_initialized); + if (!mpi_is_initialized) { + MPI_Init (NULL, NULL); + } if (h5priv_mpi_comm_rank (MPI_COMM_WORLD, &h5_myproc) < 0) { exit (42); } diff --git a/src/h5core/private/h5_init.h b/src/h5core/private/h5_init.h index 8f7d50c..5ad12c0 100644 --- a/src/h5core/private/h5_init.h +++ b/src/h5core/private/h5_init.h @@ -19,6 +19,7 @@ #if !defined (PARALLEL_IO) typedef int MPI_Comm; #define MPI_Init(argc, argv) +#define MPI_Initialized () (1) #define MPI_Comm_size(comm, nprocs) {(void)comm; *nprocs = 1; } #define MPI_Comm_rank(comm, myproc) {(void)comm; *myproc = 0; } #define MPI_Finalize()