ENH: add internal parRun guards to some UPstream methods

- simplifies coding
  * finishedRequest(), waitRequest(), waitRequests() with parRun guards
  * nRequests() is noexcept

- more consistent use of UPstream::defaultCommsType in branching
This commit is contained in:
Mark Olesen
2022-09-08 13:53:22 +02:00
parent 716d330547
commit 47e172e6ef
34 changed files with 146 additions and 158 deletions

View File

@ -55,7 +55,7 @@ void do_exchangeBuf
const bool wait const bool wait
) )
{ {
const label startOfRequests = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
// Set up receives // Set up receives
// ~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~
@ -132,7 +132,7 @@ void do_exchangeContainer
const bool wait const bool wait
) )
{ {
const label startOfRequests = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
// Set up receives // Set up receives
// ~~~~~~~~~~~~~~~ // ~~~~~~~~~~~~~~~

View File

@ -43,7 +43,8 @@ void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
{ {
auto& fldBf = fld.boundaryFieldRef(); auto& fldBf = fld.boundaryFieldRef();
const UPstream::commsTypes commsType(UPstream::defaultCommsType); const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -51,8 +52,6 @@ void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
const label startOfRequests = UPstream::nRequests();
forAll(fldBf, patchi) forAll(fldBf, patchi)
{ {
fvPatchField<Type>& tgtField = fldBf[patchi]; fvPatchField<Type>& tgtField = fldBf[patchi];
@ -68,11 +67,7 @@ void evaluateConstraintTypes(GeometricField<Type, fvPatchField, volMesh>& fld)
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == UPstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& commsType == UPstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }

View File

@ -396,19 +396,22 @@ public:
// Non-blocking comms // Non-blocking comms
//- Get number of outstanding requests //- Number of outstanding requests
static label nRequests(); static label nRequests() noexcept;
//- Truncate number of outstanding requests //- Truncate outstanding requests to given length
static void resetRequests(const label sz); static void resetRequests(const label n);
//- Wait until all requests (from start onwards) have finished. //- Wait until all requests (from start onwards) have finished.
// A no-op if parRun() == false
static void waitRequests(const label start = 0); static void waitRequests(const label start = 0);
//- Wait until request i has finished. //- Wait until request i has finished.
// A no-op if parRun() == false
static void waitRequest(const label i); static void waitRequest(const label i);
//- Non-blocking comms: has request i finished? //- Non-blocking comms: has request i finished?
// A no-op and returns true if parRun() == false
static bool finishedRequest(const label i); static bool finishedRequest(const label i);
static int allocateTag(const char*); static int allocateTag(const char*);

View File

@ -437,7 +437,8 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::evaluate()
/// InfoInFunction << nl; /// InfoInFunction << nl;
///} ///}
const UPstream::commsTypes commsType(UPstream::defaultCommsType); const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -445,19 +446,13 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::evaluate()
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
const label startOfRequests = UPstream::nRequests();
for (auto& pfld : *this) for (auto& pfld : *this)
{ {
pfld.initEvaluate(commsType); pfld.initEvaluate(commsType);
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == Pstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& commsType == Pstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
@ -506,7 +501,8 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::evaluateCoupled()
/// InfoInFunction << nl; /// InfoInFunction << nl;
///} ///}
const UPstream::commsTypes commsType(UPstream::defaultCommsType); const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -514,8 +510,6 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::evaluateCoupled()
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
const label startOfRequests = UPstream::nRequests();
for (auto& pfld : *this) for (auto& pfld : *this)
{ {
const auto* cpp = isA<CoupledPatchType>(pfld.patch()); const auto* cpp = isA<CoupledPatchType>(pfld.patch());
@ -527,11 +521,7 @@ void Foam::GeometricBoundaryField<Type, PatchField, GeoMesh>::evaluateCoupled()
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == UPstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& commsType == UPstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }

View File

@ -440,7 +440,7 @@ bool Foam::OFstreamCollator::write
// Gather all data onto master. Is done in local communicator since // Gather all data onto master. Is done in local communicator since
// not in write thread. Note that we do not store in contiguous // not in write thread. Note that we do not store in contiguous
// buffer since that would limit to 2G chars. // buffer since that would limit to 2G chars.
const label startOfRequests = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
if (Pstream::master(localComm_)) if (Pstream::master(localComm_))
{ {
for (label proci = 1; proci < slaveData.size(); proci++) for (label proci = 1; proci < slaveData.size(); proci++)
@ -479,7 +479,7 @@ bool Foam::OFstreamCollator::write
<< Foam::abort(FatalError); << Foam::abort(FatalError);
} }
} }
Pstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
{ {
std::lock_guard<std::mutex> guard(mutex_); std::lock_guard<std::mutex> guard(mutex_);

View File

@ -40,10 +40,12 @@ void Foam::LduMatrix<Type, DType, LUType>::initMatrixInterfaces
Field<Type>& result Field<Type>& result
) const ) const
{ {
const UPstream::commsTypes commsType = UPstream::defaultCommsType;
if if
( (
Pstream::defaultCommsType == Pstream::commsTypes::blocking commsType == UPstream::commsTypes::blocking
|| Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
forAll(interfaces_, interfacei) forAll(interfaces_, interfacei)
@ -59,12 +61,12 @@ void Foam::LduMatrix<Type, DType, LUType>::initMatrixInterfaces
psiif, psiif,
interfaceCoeffs[interfacei], interfaceCoeffs[interfacei],
//Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]), //Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]),
Pstream::defaultCommsType commsType
); );
} }
} }
} }
else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) else if (commsType == UPstream::commsTypes::scheduled)
{ {
const lduSchedule& patchSchedule = this->patchSchedule(); const lduSchedule& patchSchedule = this->patchSchedule();
@ -88,7 +90,7 @@ void Foam::LduMatrix<Type, DType, LUType>::initMatrixInterfaces
psiif, psiif,
interfaceCoeffs[interfacei], interfaceCoeffs[interfacei],
//Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]), //Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]),
Pstream::commsTypes::blocking UPstream::commsTypes::blocking
); );
} }
} }
@ -97,7 +99,7 @@ void Foam::LduMatrix<Type, DType, LUType>::initMatrixInterfaces
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unsupported communications type " << "Unsupported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType] << UPstream::commsTypeNames[commsType]
<< exit(FatalError); << exit(FatalError);
} }
} }
@ -112,17 +114,18 @@ void Foam::LduMatrix<Type, DType, LUType>::updateMatrixInterfaces
Field<Type>& result Field<Type>& result
) const ) const
{ {
const UPstream::commsTypes commsType = UPstream::defaultCommsType;
if if
( (
Pstream::defaultCommsType == Pstream::commsTypes::blocking commsType == UPstream::commsTypes::blocking
|| Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
// Block until all sends/receives have been finished // Block until all sends/receives have been finished
if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
IPstream::waitRequests(); UPstream::waitRequests();
OPstream::waitRequests();
} }
forAll(interfaces_, interfacei) forAll(interfaces_, interfacei)
@ -138,12 +141,12 @@ void Foam::LduMatrix<Type, DType, LUType>::updateMatrixInterfaces
psiif, psiif,
interfaceCoeffs[interfacei], interfaceCoeffs[interfacei],
//Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]), //Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]),
Pstream::defaultCommsType commsType
); );
} }
} }
} }
else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) else if (commsType == UPstream::commsTypes::scheduled)
{ {
const lduSchedule& patchSchedule = this->patchSchedule(); const lduSchedule& patchSchedule = this->patchSchedule();
@ -165,7 +168,7 @@ void Foam::LduMatrix<Type, DType, LUType>::updateMatrixInterfaces
psiif, psiif,
interfaceCoeffs[interfacei], interfaceCoeffs[interfacei],
//Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]), //Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]),
Pstream::commsTypes::scheduled commsType
); );
} }
else else
@ -179,7 +182,7 @@ void Foam::LduMatrix<Type, DType, LUType>::updateMatrixInterfaces
psiif, psiif,
interfaceCoeffs[interfacei], interfaceCoeffs[interfacei],
//Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]), //Amultiplier<Type, LUType>(interfaceCoeffs[interfacei]),
Pstream::commsTypes::scheduled commsType
); );
} }
} }
@ -214,7 +217,7 @@ void Foam::LduMatrix<Type, DType, LUType>::updateMatrixInterfaces
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unsupported communications type " << "Unsupported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType] << UPstream::commsTypeNames[commsType]
<< exit(FatalError); << exit(FatalError);
} }
} }

View File

@ -71,7 +71,7 @@ bool Foam::lduCalculatedProcessorField<Type>::ready() const
if if
( (
this->outstandingSendRequest_ >= 0 this->outstandingSendRequest_ >= 0
&& this->outstandingSendRequest_ < Pstream::nRequests() && this->outstandingSendRequest_ < UPstream::nRequests()
) )
{ {
if (!UPstream::finishedRequest(this->outstandingSendRequest_)) if (!UPstream::finishedRequest(this->outstandingSendRequest_))
@ -84,7 +84,7 @@ bool Foam::lduCalculatedProcessorField<Type>::ready() const
if if
( (
this->outstandingRecvRequest_ >= 0 this->outstandingRecvRequest_ >= 0
&& this->outstandingRecvRequest_ < Pstream::nRequests() && this->outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
if (!UPstream::finishedRequest(this->outstandingRecvRequest_)) if (!UPstream::finishedRequest(this->outstandingRecvRequest_))
@ -210,7 +210,7 @@ void Foam::lduCalculatedProcessorField<Type>::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);

View File

@ -56,7 +56,7 @@ void Foam::lduMatrix::Amul
const scalar* const __restrict__ upperPtr = upper().begin(); const scalar* const __restrict__ upperPtr = upper().begin();
const scalar* const __restrict__ lowerPtr = lower().begin(); const scalar* const __restrict__ lowerPtr = lower().begin();
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
// Initialise the update of interfaced interfaces // Initialise the update of interfaced interfaces
initMatrixInterfaces initMatrixInterfaces
@ -122,7 +122,7 @@ void Foam::lduMatrix::Tmul
const scalar* const __restrict__ lowerPtr = lower().begin(); const scalar* const __restrict__ lowerPtr = lower().begin();
const scalar* const __restrict__ upperPtr = upper().begin(); const scalar* const __restrict__ upperPtr = upper().begin();
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
// Initialise the update of interfaced interfaces // Initialise the update of interfaced interfaces
initMatrixInterfaces initMatrixInterfaces
@ -246,7 +246,7 @@ void Foam::lduMatrix::residual
// To compensate for this, it is necessary to turn the // To compensate for this, it is necessary to turn the
// sign of the contribution. // sign of the contribution.
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
// Initialise the update of interfaced interfaces // Initialise the update of interfaced interfaces
initMatrixInterfaces initMatrixInterfaces

View File

@ -40,10 +40,12 @@ void Foam::lduMatrix::initMatrixInterfaces
const direction cmpt const direction cmpt
) const ) const
{ {
const UPstream::commsTypes commsType = UPstream::defaultCommsType;
if if
( (
Pstream::defaultCommsType == Pstream::commsTypes::blocking commsType == UPstream::commsTypes::blocking
|| Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
forAll(interfaces, interfacei) forAll(interfaces, interfacei)
@ -59,12 +61,12 @@ void Foam::lduMatrix::initMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::defaultCommsType commsType
); );
} }
} }
} }
else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) else if (commsType == UPstream::commsTypes::scheduled)
{ {
const lduSchedule& patchSchedule = this->patchSchedule(); const lduSchedule& patchSchedule = this->patchSchedule();
@ -88,7 +90,7 @@ void Foam::lduMatrix::initMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::commsTypes::blocking UPstream::commsTypes::blocking
); );
} }
} }
@ -97,7 +99,7 @@ void Foam::lduMatrix::initMatrixInterfaces
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unsupported communications type " << "Unsupported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType] << UPstream::commsTypeNames[commsType]
<< exit(FatalError); << exit(FatalError);
} }
} }
@ -114,7 +116,9 @@ void Foam::lduMatrix::updateMatrixInterfaces
const label startRequest const label startRequest
) const ) const
{ {
if (Pstream::defaultCommsType == Pstream::commsTypes::blocking) const UPstream::commsTypes commsType = UPstream::defaultCommsType;
if (commsType == UPstream::commsTypes::blocking)
{ {
forAll(interfaces, interfacei) forAll(interfaces, interfacei)
{ {
@ -129,12 +133,12 @@ void Foam::lduMatrix::updateMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::defaultCommsType commsType
); );
} }
} }
} }
else if (Pstream::defaultCommsType == Pstream::commsTypes::nonBlocking) else if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Try and consume interfaces as they become available // Try and consume interfaces as they become available
bool allUpdated = false; bool allUpdated = false;
@ -160,7 +164,7 @@ void Foam::lduMatrix::updateMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::defaultCommsType commsType
); );
} }
else else
@ -210,12 +214,12 @@ void Foam::lduMatrix::updateMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::defaultCommsType commsType
); );
} }
} }
} }
else if (Pstream::defaultCommsType == Pstream::commsTypes::scheduled) else if (commsType == UPstream::commsTypes::scheduled)
{ {
const lduSchedule& patchSchedule = this->patchSchedule(); const lduSchedule& patchSchedule = this->patchSchedule();
@ -237,7 +241,7 @@ void Foam::lduMatrix::updateMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::commsTypes::scheduled commsType
); );
} }
else else
@ -251,7 +255,7 @@ void Foam::lduMatrix::updateMatrixInterfaces
psiif, psiif,
coupleCoeffs[interfacei], coupleCoeffs[interfacei],
cmpt, cmpt,
Pstream::commsTypes::scheduled commsType
); );
} }
} }
@ -286,7 +290,7 @@ void Foam::lduMatrix::updateMatrixInterfaces
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Unsupported communications type " << "Unsupported communications type "
<< Pstream::commsTypeNames[Pstream::defaultCommsType] << UPstream::commsTypeNames[commsType]
<< exit(FatalError); << exit(FatalError);
} }
} }

View File

@ -115,7 +115,7 @@ void Foam::GaussSeidelSmoother::smooth
{ {
bPrime = source; bPrime = source;
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
matrix_.initMatrixInterfaces matrix_.initMatrixInterfaces
( (

View File

@ -142,7 +142,7 @@ void Foam::nonBlockingGaussSeidelSmoother::smooth
{ {
bPrime = source; bPrime = source;
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
matrix_.initMatrixInterfaces matrix_.initMatrixInterfaces
( (

View File

@ -115,7 +115,7 @@ void Foam::symGaussSeidelSmoother::smooth
{ {
bPrime = source; bPrime = source;
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
matrix_.initMatrixInterfaces matrix_.initMatrixInterfaces
( (

View File

@ -272,7 +272,7 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
patchFaceRestrictAddressing_[fineLevelIndex]; patchFaceRestrictAddressing_[fineLevelIndex];
const label nReq = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
// Initialise transfer of restrict addressing on the interface // Initialise transfer of restrict addressing on the interface
// The finest mesh uses patchAddr from the original lduAdressing. // The finest mesh uses patchAddr from the original lduAdressing.
@ -301,10 +301,7 @@ void Foam::GAMGAgglomeration::agglomerateLduAddressing
} }
} }
if (Pstream::parRun()) UPstream::waitRequests(startOfRequests);
{
Pstream::waitRequests(nReq);
}
// Add the coarse level // Add the coarse level

View File

@ -147,7 +147,7 @@ Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells
// Get the interface cells // Get the interface cells
PtrList<labelList> nbrGlobalCells(interfaces.size()); PtrList<labelList> nbrGlobalCells(interfaces.size());
{ {
const label nReq = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
// Initialise transfer of restrict addressing on the interface // Initialise transfer of restrict addressing on the interface
forAll(interfaces, inti) forAll(interfaces, inti)
@ -162,10 +162,7 @@ Foam::labelListList Foam::GAMGProcAgglomeration::globalCellCells
} }
} }
if (UPstream::parRun()) UPstream::waitRequests(startOfRequests);
{
UPstream::waitRequests(nReq);
}
forAll(interfaces, inti) forAll(interfaces, inti)
{ {

View File

@ -52,7 +52,7 @@ void Foam::GAMGSolver::interpolate
Apsi = 0; Apsi = 0;
solveScalar* __restrict__ ApsiPtr = Apsi.begin(); solveScalar* __restrict__ ApsiPtr = Apsi.begin();
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
m.initMatrixInterfaces m.initMatrixInterfaces
( (

View File

@ -169,7 +169,7 @@ void Foam::processorGAMGInterfaceField::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);

View File

@ -170,9 +170,9 @@ Foam::solverPerformance Foam::PPCG::scalarSolveCG
) )
{ {
// Make sure gamma,delta are available // Make sure gamma,delta are available
if (Pstream::parRun() && outstandingRequest != -1) if (outstandingRequest != -1)
{ {
Pstream::waitRequest(outstandingRequest); UPstream::waitRequest(outstandingRequest);
outstandingRequest = -1; outstandingRequest = -1;
} }
@ -249,9 +249,9 @@ Foam::solverPerformance Foam::PPCG::scalarSolveCG
} }
// Cleanup any outstanding requests // Cleanup any outstanding requests
if (Pstream::parRun() && outstandingRequest != -1) if (outstandingRequest != -1)
{ {
Pstream::waitRequest(outstandingRequest); UPstream::waitRequest(outstandingRequest);
} }
return solverPerf; return solverPerf;

View File

@ -129,10 +129,8 @@ Foam::labelListList Foam::lduPrimitiveMesh::globalCellCells
} }
} }
if (Pstream::parRun()) // Wait for all
{ UPstream::waitRequests();
Pstream::waitRequests();
}
forAll(interfaces, inti) forAll(interfaces, inti)
{ {

View File

@ -186,8 +186,8 @@ void Foam::mapDistributeBase::exchangeMasks
} }
} }
// Wait for all to finish // Wait for outstanding requests
Pstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
// Receiving myself is just a copy // Receiving myself is just a copy

View File

@ -584,8 +584,7 @@ void Foam::mapDistributeBase::distribute
} }
// Wait for all to finish // Wait for outstanding requests
Pstream::waitRequests(nOutstanding); Pstream::waitRequests(nOutstanding);
@ -1044,8 +1043,7 @@ void Foam::mapDistributeBase::distribute
} }
// Wait for all to finish // Wait for outstanding requests
Pstream::waitRequests(nOutstanding); Pstream::waitRequests(nOutstanding);

View File

@ -142,7 +142,7 @@ void Foam::globalIndex::gatherValues
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Wait for all to finish // Wait for outstanding requests
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
} }
@ -242,7 +242,7 @@ void Foam::globalIndex::gather
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Wait for all to finish // Wait for outstanding requests
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
} }
@ -338,7 +338,7 @@ void Foam::globalIndex::gather
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Wait for all to finish // Wait for outstanding requests
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
} }
@ -945,7 +945,7 @@ void Foam::globalIndex::scatter
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Wait for all to finish // Wait for outstanding requests
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
} }

View File

@ -87,13 +87,13 @@ void Foam::UPstream::freePstreamCommunicator(const label)
{} {}
Foam::label Foam::UPstream::nRequests() Foam::label Foam::UPstream::nRequests() noexcept
{ {
return 0; return 0;
} }
void Foam::UPstream::resetRequests(const label i) void Foam::UPstream::resetRequests(const label n)
{} {}
@ -107,8 +107,7 @@ void Foam::UPstream::waitRequest(const label i)
bool Foam::UPstream::finishedRequest(const label i) bool Foam::UPstream::finishedRequest(const label i)
{ {
NotImplemented; return true;
return false;
} }

View File

@ -609,23 +609,28 @@ void Foam::UPstream::freePstreamCommunicator(const label communicator)
} }
Foam::label Foam::UPstream::nRequests() Foam::label Foam::UPstream::nRequests() noexcept
{ {
return PstreamGlobals::outstandingRequests_.size(); return PstreamGlobals::outstandingRequests_.size();
} }
void Foam::UPstream::resetRequests(const label i) void Foam::UPstream::resetRequests(const label n)
{ {
if (i < PstreamGlobals::outstandingRequests_.size()) if (n >= 0 && n < PstreamGlobals::outstandingRequests_.size())
{ {
PstreamGlobals::outstandingRequests_.setSize(i); PstreamGlobals::outstandingRequests_.resize(n);
} }
} }
void Foam::UPstream::waitRequests(const label start) void Foam::UPstream::waitRequests(const label start)
{ {
if (!UPstream::parRun())
{
return; // No-op for non-parallel
}
if (UPstream::debug) if (UPstream::debug)
{ {
Pout<< "UPstream::waitRequests : starting wait for " Pout<< "UPstream::waitRequests : starting wait for "
@ -672,6 +677,11 @@ void Foam::UPstream::waitRequests(const label start)
void Foam::UPstream::waitRequest(const label i) void Foam::UPstream::waitRequest(const label i)
{ {
if (!UPstream::parRun())
{
return; // No-op for non-parallel
}
if (debug) if (debug)
{ {
Pout<< "UPstream::waitRequest : starting wait for request:" << i Pout<< "UPstream::waitRequest : starting wait for request:" << i
@ -717,13 +727,18 @@ void Foam::UPstream::waitRequest(const label i)
bool Foam::UPstream::finishedRequest(const label i) bool Foam::UPstream::finishedRequest(const label i)
{ {
if (!UPstream::parRun())
{
return true; // No-op for non-parallel
}
if (debug) if (debug)
{ {
Pout<< "UPstream::finishedRequest : checking request:" << i Pout<< "UPstream::finishedRequest : checking request:" << i
<< endl; << endl;
} }
if (i >= PstreamGlobals::outstandingRequests_.size()) if (i < 0 || i >= PstreamGlobals::outstandingRequests_.size())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "There are " << PstreamGlobals::outstandingRequests_.size() << "There are " << PstreamGlobals::outstandingRequests_.size()

View File

@ -305,7 +305,7 @@ Foam::faMeshDistributor::distribute
// Processor-processor connections // Processor-processor connections
if (Pstream::parRun()) if (Pstream::parRun())
{ {
const label startOfRequests = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
const faBoundaryMesh& oldBndMesh = oldMesh.boundary(); const faBoundaryMesh& oldBndMesh = oldMesh.boundary();
@ -339,8 +339,9 @@ Foam::faMeshDistributor::distribute
} }
} }
// Wait for all to finish // Wait for outstanding requests
Pstream::waitRequests(startOfRequests); // (commsType == UPstream::commsTypes::nonBlocking)
UPstream::waitRequests(startOfRequests);
// Receive values // Receive values
for (const faPatch& fap : oldBndMesh) for (const faPatch& fap : oldBndMesh)

View File

@ -111,7 +111,7 @@ Foam::SolverPerformance<Type> Foam::faMatrix<Type>::solve
PrecisionAdaptor<solveScalar, scalar> sourceCmpt_ss(sourceCmpt); PrecisionAdaptor<solveScalar, scalar> sourceCmpt_ss(sourceCmpt);
ConstPrecisionAdaptor<solveScalar, scalar> psiCmpt_ss(psiCmpt); ConstPrecisionAdaptor<solveScalar, scalar> psiCmpt_ss(psiCmpt);
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
initMatrixInterfaces initMatrixInterfaces
( (

View File

@ -92,7 +92,7 @@ bool Foam::calculatedProcessorFvPatchField<Type>::ready() const
if if
( (
this->outstandingSendRequest_ >= 0 this->outstandingSendRequest_ >= 0
&& this->outstandingSendRequest_ < Pstream::nRequests() && this->outstandingSendRequest_ < UPstream::nRequests()
) )
{ {
if (!UPstream::finishedRequest(this->outstandingSendRequest_)) if (!UPstream::finishedRequest(this->outstandingSendRequest_))
@ -105,7 +105,7 @@ bool Foam::calculatedProcessorFvPatchField<Type>::ready() const
if if
( (
this->outstandingRecvRequest_ >= 0 this->outstandingRecvRequest_ >= 0
&& this->outstandingRecvRequest_ < Pstream::nRequests() && this->outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
if (!UPstream::finishedRequest(this->outstandingRecvRequest_)) if (!UPstream::finishedRequest(this->outstandingRecvRequest_))
@ -201,7 +201,7 @@ void Foam::calculatedProcessorFvPatchField<Type>::evaluate
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);
@ -327,7 +327,7 @@ void Foam::calculatedProcessorFvPatchField<Type>::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);

View File

@ -283,7 +283,7 @@ void Foam::processorFvPatchField<Type>::evaluate
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);
@ -416,7 +416,7 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);
@ -565,7 +565,7 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);
@ -606,11 +606,10 @@ bool Foam::processorFvPatchField<Type>::ready() const
if if
( (
outstandingSendRequest_ >= 0 outstandingSendRequest_ >= 0
&& outstandingSendRequest_ < Pstream::nRequests() && outstandingSendRequest_ < UPstream::nRequests()
) )
{ {
bool finished = UPstream::finishedRequest(outstandingSendRequest_); if (!UPstream::finishedRequest(outstandingSendRequest_))
if (!finished)
{ {
return false; return false;
} }
@ -620,11 +619,10 @@ bool Foam::processorFvPatchField<Type>::ready() const
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
bool finished = UPstream::finishedRequest(outstandingRecvRequest_); if (!UPstream::finishedRequest(outstandingRecvRequest_))
if (!finished)
{ {
return false; return false;
} }

View File

@ -190,7 +190,7 @@ Foam::SolverPerformance<Type> Foam::fvMatrix<Type>::solveSegregated
PrecisionAdaptor<solveScalar, scalar> sourceCmpt_ss(sourceCmpt); PrecisionAdaptor<solveScalar, scalar> sourceCmpt_ss(sourceCmpt);
ConstPrecisionAdaptor<solveScalar, scalar> psiCmpt_ss(psiCmpt); ConstPrecisionAdaptor<solveScalar, scalar> psiCmpt_ss(psiCmpt);
const label startRequest = Pstream::nRequests(); const label startRequest = UPstream::nRequests();
initMatrixInterfaces initMatrixInterfaces
( (

View File

@ -108,6 +108,7 @@ void Foam::volPointInterpolation::addSeparated
} }
// Wait for outstanding requests // Wait for outstanding requests
// (commsType == UPstream::commsTypes::nonBlocking)
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
forAll(pfbf, patchi) forAll(pfbf, patchi)

View File

@ -38,7 +38,8 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
{ {
auto& fldBf = fld.boundaryFieldRef(); auto& fldBf = fld.boundaryFieldRef();
const UPstream::commsTypes commsType(UPstream::defaultCommsType); const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests();
if if
( (
@ -46,8 +47,6 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
|| commsType == UPstream::commsTypes::nonBlocking || commsType == UPstream::commsTypes::nonBlocking
) )
{ {
const label startOfRequests = UPstream::nRequests();
forAll(fldBf, patchi) forAll(fldBf, patchi)
{ {
fvPatchField<Type>& tgtField = fldBf[patchi]; fvPatchField<Type>& tgtField = fldBf[patchi];
@ -63,11 +62,7 @@ void Foam::functionObjects::mapFields::evaluateConstraintTypes
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == UPstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& commsType == UPstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }

View File

@ -55,7 +55,7 @@ void Foam::MGridGenGAMGAgglomeration::swap
PtrList<labelList>& nbrValues PtrList<labelList>& nbrValues
) const ) const
{ {
const label nReq = Pstream::nRequests(); const label startOfRequests = UPstream::nRequests();
// Initialise transfer of restrict addressing on the interface // Initialise transfer of restrict addressing on the interface
forAll(interfaces, inti) forAll(interfaces, inti)
@ -70,10 +70,10 @@ void Foam::MGridGenGAMGAgglomeration::swap
} }
} }
if (Pstream::parRun()) // Wait for outstanding requests
{ // (commsType == UPstream::commsTypes::nonBlocking)
Pstream::waitRequests(nReq); UPstream::waitRequests(startOfRequests);
}
// Get the interface agglomeration // Get the interface agglomeration
nbrValues.setSize(interfaces.size()); nbrValues.setSize(interfaces.size());

View File

@ -119,22 +119,19 @@ void Foam::dynamicOversetFvMesh::correctBoundaryConditions
const bool typeOnly const bool typeOnly
) )
{ {
const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests(); const label startOfRequests = UPstream::nRequests();
forAll(bfld, patchi) forAll(bfld, patchi)
{ {
if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr)) if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr))
{ {
bfld[patchi].initEvaluate(UPstream::defaultCommsType); bfld[patchi].initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == UPstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& UPstream::defaultCommsType == UPstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
@ -143,7 +140,7 @@ void Foam::dynamicOversetFvMesh::correctBoundaryConditions
{ {
if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr)) if (typeOnly == (isA<PatchType>(bfld[patchi]) != nullptr))
{ {
bfld[patchi].evaluate(UPstream::defaultCommsType); bfld[patchi].evaluate(commsType);
} }
} }
} }
@ -903,6 +900,7 @@ void Foam::dynamicOversetFvMesh::correctCoupledBoundaryConditions(GeoField& fld)
{ {
typename GeoField::Boundary& bfld = fld.boundaryFieldRef(); typename GeoField::Boundary& bfld = fld.boundaryFieldRef();
const UPstream::commsTypes commsType = UPstream::defaultCommsType;
const label startOfRequests = UPstream::nRequests(); const label startOfRequests = UPstream::nRequests();
forAll(bfld, patchi) forAll(bfld, patchi)
@ -910,16 +908,12 @@ void Foam::dynamicOversetFvMesh::correctCoupledBoundaryConditions(GeoField& fld)
if (bfld[patchi].coupled()) if (bfld[patchi].coupled())
{ {
//Pout<< "initEval of " << bfld[patchi].patch().name() << endl; //Pout<< "initEval of " << bfld[patchi].patch().name() << endl;
bfld[patchi].initEvaluate(Pstream::defaultCommsType); bfld[patchi].initEvaluate(commsType);
} }
} }
// Wait for outstanding requests // Wait for outstanding requests
if if (commsType == UPstream::commsTypes::nonBlocking)
(
UPstream::parRun()
&& UPstream::defaultCommsType == UPstream::commsTypes::nonBlocking
)
{ {
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }
@ -929,7 +923,7 @@ void Foam::dynamicOversetFvMesh::correctCoupledBoundaryConditions(GeoField& fld)
if (bfld[patchi].coupled()) if (bfld[patchi].coupled())
{ {
//Pout<< "eval of " << bfld[patchi].patch().name() << endl; //Pout<< "eval of " << bfld[patchi].patch().name() << endl;
bfld[patchi].evaluate(Pstream::defaultCommsType); bfld[patchi].evaluate(commsType);
} }
} }
} }

View File

@ -171,7 +171,7 @@ void Foam::calculatedProcessorGAMGInterfaceField::updateInterfaceMatrix
if if
( (
outstandingRecvRequest_ >= 0 outstandingRecvRequest_ >= 0
&& outstandingRecvRequest_ < Pstream::nRequests() && outstandingRecvRequest_ < UPstream::nRequests()
) )
{ {
UPstream::waitRequest(outstandingRecvRequest_); UPstream::waitRequest(outstandingRecvRequest_);

View File

@ -130,9 +130,9 @@ Foam::label Foam::metisLikeDecomp::decomposeGeneral
} }
} }
// Wait for outstanding requests
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Wait for all to finish
UPstream::waitRequests(startOfRequests); UPstream::waitRequests(startOfRequests);
} }