From bbe5b7ba5ec3d9aac035aec0757445d88dd9b96f Mon Sep 17 00:00:00 2001 From: Paul Romano Date: Tue, 3 Sep 2019 21:49:32 -0500 Subject: [PATCH] Make sure MPI_Type_free is not called if MPI hasn't been initialized --- src/finalize.cpp | 4 +++- src/message_passing.cpp | 4 ++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/finalize.cpp b/src/finalize.cpp index 120903f3fe..7c39a7c198 100644 --- a/src/finalize.cpp +++ b/src/finalize.cpp @@ -127,7 +127,9 @@ int openmc_finalize() // Free all MPI types #ifdef OPENMC_MPI - MPI_Type_free(&mpi::bank); + int init_called; + MPI_Initialized(&init_called); + if (init_called) MPI_Type_free(&mpi::bank); #endif return 0; diff --git a/src/message_passing.cpp b/src/message_passing.cpp index 278bf924d3..aea17f9f49 100644 --- a/src/message_passing.cpp +++ b/src/message_passing.cpp @@ -8,8 +8,8 @@ int n_procs {1}; bool master {true}; #ifdef OPENMC_MPI -MPI_Comm intracomm; -MPI_Datatype bank; +MPI_Comm intracomm {MPI_COMM_NULL}; +MPI_Datatype bank {MPI_DATATYPE_NULL}; #endif extern "C" bool openmc_master() { return mpi::master; }