From 05322608a28f1f9fe1495f0c581173a8511dbd1e Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 9 Dec 2022 17:17:26 +0100 Subject: [PATCH] ENH: Pstream waitRequest ignore placeholder (negative) requests --- src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 2 ++ src/Pstream/mpi/UPstream.C | 30 +++++++++---------- 2 files changed, 17 insertions(+), 15 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index 2ad8042b09..a5111d019e 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -456,10 +456,12 @@ public: //- Wait until request i has finished. // A no-op if parRun() == false + // or for placeholder (negative) request indices static void waitRequest(const label i); //- Non-blocking comms: has request i finished? // A no-op and returns true if parRun() == false + // or for placeholder (negative) request indices static bool finishedRequest(const label i); static int allocateTag(const char* const msg = nullptr); diff --git a/src/Pstream/mpi/UPstream.C b/src/Pstream/mpi/UPstream.C index b9e2ab76a1..f4f21af3f0 100644 --- a/src/Pstream/mpi/UPstream.C +++ b/src/Pstream/mpi/UPstream.C @@ -453,7 +453,7 @@ void Foam::UPstream::shutdown(int errNo) // Clean mpi communicators forAll(myProcNo_, communicator) { - if (myProcNo_[communicator] != -1) + if (myProcNo_[communicator] >= 0) { freePstreamCommunicator(communicator); } @@ -730,9 +730,9 @@ void Foam::UPstream::waitRequests(const label start) void Foam::UPstream::waitRequest(const label i) { - if (!UPstream::parRun()) + if (!UPstream::parRun() || i < 0) { - return; // No-op for non-parallel + return; // No-op for non-parallel, or placeholder indices } if (debug) @@ -741,13 +741,13 @@ void Foam::UPstream::waitRequest(const label i) << endl; } - if (i < 0 || i >= PstreamGlobals::outstandingRequests_.size()) + if (i >= PstreamGlobals::outstandingRequests_.size()) { FatalErrorInFunction - << "There are " << PstreamGlobals::outstandingRequests_.size() - << " outstanding send requests and you are asking for i=" << i - << nl - << "Maybe you are mixing blocking/non-blocking comms?" + << "You asked for request=" << i + << " from " << PstreamGlobals::outstandingRequests_.size() + << " outstanding requests!" << nl + << "Mixing use of blocking/non-blocking comms?" << Foam::abort(FatalError); } @@ -781,9 +781,9 @@ void Foam::UPstream::waitRequest(const label i) bool Foam::UPstream::finishedRequest(const label i) { - if (!UPstream::parRun()) + if (!UPstream::parRun() || i < 0) { - return true; // No-op for non-parallel + return true; // No-op for non-parallel, or placeholder indices } if (debug) @@ -792,13 +792,13 @@ bool Foam::UPstream::finishedRequest(const label i) << endl; } - if (i < 0 || i >= PstreamGlobals::outstandingRequests_.size()) + if (i >= PstreamGlobals::outstandingRequests_.size()) { FatalErrorInFunction - << "There are " << PstreamGlobals::outstandingRequests_.size() - << " outstanding send requests and you are asking for i=" << i - << nl - << "Maybe you are mixing blocking/non-blocking comms?" + << "You asked for request=" << i + << " from " << PstreamGlobals::outstandingRequests_.size() + << " outstanding requests!" << nl + << "Mixing use of blocking/non-blocking comms?" << Foam::abort(FatalError); }