From 20c7f0970d0693d4afbabea5daa4d9cde0cd2f8a Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Tue, 20 Jun 2023 08:40:07 +0200 Subject: [PATCH] BUG: UPstream::shutdown misbehaves with external initialisation (fixes #2808) - freeCommmunicatorComponents needs an additional bounds check. When MPI is initialized outside of OpenFOAM, there are no UPstream communicator equivalents --- src/Pstream/mpi/UPstream.C | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/Pstream/mpi/UPstream.C b/src/Pstream/mpi/UPstream.C index f4f21af3f0..7990be8a7a 100644 --- a/src/Pstream/mpi/UPstream.C +++ b/src/Pstream/mpi/UPstream.C @@ -641,7 +641,16 @@ void Foam::UPstream::freePstreamCommunicator(const label communicator) } // Not touching the first two communicators (SELF, WORLD) - if (communicator > 1) + // or anything out-of bounds. + // + // No UPstream communicator indices when MPI is initialized outside + // of OpenFOAM - thus needs a bounds check too! + + if + ( + communicator > 1 + && (communicator < PstreamGlobals::MPICommunicators_.size()) + ) { if (MPI_COMM_NULL != PstreamGlobals::MPICommunicators_[communicator]) {