ENH: relax processorField waiting requirements

- for interface polling previously required that both send and recv
  requests were completed before evaluating (values or matrix update).
  However, only the recv needs to be complete, which helps disentangle
  the inter-rank waiting.

  NB: this change is possible following (1f5cf3958b) that replaced
      UPstream::resetRequests() call in favour of UPstream::waitRequests()
This commit is contained in:
Mark Olesen
2023-05-04 17:45:58 +02:00
parent 52b225b6d5
commit 98c42479f6
11 changed files with 402 additions and 352 deletions

View File

@ -58,12 +58,25 @@ Foam::lduCalculatedProcessorField<Type>::lduCalculatedProcessorField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
bool Foam::lduCalculatedProcessorField<Type>::ready() const bool Foam::lduCalculatedProcessorField<Type>::all_ready() const
{ {
return UPstream::finishedRequestPair(recvRequest_, sendRequest_); return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
} }
template<class Type>
bool Foam::lduCalculatedProcessorField<Type>::ready() const
{
const bool ok = UPstream::finishedRequest(recvRequest_);
if (ok)
{
recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
}
return ok;
}
template<class Type> template<class Type>
void Foam::lduCalculatedProcessorField<Type>::initInterfaceMatrixUpdate void Foam::lduCalculatedProcessorField<Type>::initInterfaceMatrixUpdate
( (
@ -77,10 +90,11 @@ void Foam::lduCalculatedProcessorField<Type>::initInterfaceMatrixUpdate
const Pstream::commsTypes commsType const Pstream::commsTypes commsType
) const ) const
{ {
if (!this->ready()) if (!this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "Outstanding request." << "Outstanding request(s) on interface "
//<< procInterface_.name()
<< abort(FatalError); << abort(FatalError);
} }
@ -167,12 +181,12 @@ void Foam::lduCalculatedProcessorField<Type>::updateInterfaceMatrix
return; return;
} }
// Require receive data. Update the send request state. {
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Require receive data.
// Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
}
// Consume straight from receive buffer. Note use of our own // Consume straight from receive buffer. Note use of our own
// helper to avoid using fvPatch addressing // helper to avoid using fvPatch addressing

View File

@ -103,6 +103,9 @@ protected:
const solveScalarField& vals const solveScalarField& vals
) const; ) const;
//- Receive and send requests have both completed
virtual bool all_ready() const;
public: public:
@ -112,14 +115,13 @@ public:
// Constructors // Constructors
//- Construct from patch and internal field //- Construct from ldu interface
lduCalculatedProcessorField explicit lduCalculatedProcessorField
( (
const lduInterface& interface const lduInterface& interface
//const Field<Type>&
); );
//- Construct as copy //- Copy construct
lduCalculatedProcessorField lduCalculatedProcessorField
( (
const lduCalculatedProcessorField<Type>& const lduCalculatedProcessorField<Type>&
@ -132,48 +134,9 @@ public:
// Member Functions // Member Functions
// Access
//- Return communicator used for comms
virtual label comm() const
{
return procInterface_.comm();
}
//- Return processor number
virtual int myProcNo() const
{
return procInterface_.myProcNo();
}
//- Return neighbour processor number
virtual int neighbProcNo() const
{
return procInterface_.myProcNo();
}
//- Is the transform required
virtual bool doTransform() const
{
return false;
}
//- Return face transformation tensor
virtual const tensorField& forwardT() const
{
return procInterface_.forwardT();
}
//- Return rank of component for transform
virtual int rank() const
{
return pTraits<Type>::rank;
}
// Evaluation // Evaluation
//- Is all data available //- Are all (receive) data available?
virtual bool ready() const; virtual bool ready() const;
//- Initialise neighbour matrix update //- Initialise neighbour matrix update
@ -231,6 +194,45 @@ public:
{ {
NotImplemented; NotImplemented;
} }
// Processor coupled interface functions
//- Return communicator used for communication
virtual label comm() const
{
return procInterface_.comm();
}
//- Return processor number
virtual int myProcNo() const
{
return procInterface_.myProcNo();
}
//- Return neighbour processor number
virtual int neighbProcNo() const
{
return procInterface_.myProcNo();
}
//- Is the transform required
virtual bool doTransform() const
{
return false;
}
//- Return face transformation tensor
virtual const tensorField& forwardT() const
{
return procInterface_.forwardT();
}
//- Return rank of component for transform
virtual int rank() const
{
return pTraits<Type>::rank;
}
}; };

View File

@ -136,4 +136,5 @@ Foam::lduPrimitiveProcessorInterface::internalFieldTransfer
return processorLduInterface::receive<label>(commsType, faceCells_.size()); return processorLduInterface::receive<label>(commsType, faceCells_.size());
} }
// ************************************************************************* // // ************************************************************************* //

View File

@ -58,6 +58,7 @@ class lduPrimitiveProcessorInterface
{ {
// Private Data // Private Data
//- Addressing
const labelList faceCells_; const labelList faceCells_;
//- My processor rank in communicator //- My processor rank in communicator
@ -76,19 +77,18 @@ class lduPrimitiveProcessorInterface
const label comm_; const label comm_;
// Private Member Functions
//- No copy assignment
void operator=(const lduPrimitiveProcessorInterface&) = delete;
public: public:
//- Runtime type information //- Runtime type information
TypeNameNoDebug("processorInterface"); TypeNameNoDebug("processorInterface");
// Generated Methods
//- No copy assignment
void operator=(const lduPrimitiveProcessorInterface&) = delete;
// Constructors // Constructors
//- Construct from components //- Construct from components
@ -164,46 +164,46 @@ public:
) const; ) const;
// Processor interface functions // Processor interface functions
//- Return communicator used for sending //- Return communicator used for sending
virtual label comm() const virtual label comm() const
{ {
return comm_; return comm_;
} }
//- Return processor number (rank in communicator) //- Return processor number (rank in communicator)
virtual int myProcNo() const virtual int myProcNo() const
{ {
return myProcNo_; return myProcNo_;
} }
//- Return neighbour processor number (rank in communicator) //- Return neighbour processor number (rank in communicator)
virtual int neighbProcNo() const virtual int neighbProcNo() const
{ {
return neighbProcNo_; return neighbProcNo_;
} }
//- Return face transformation tensor //- Return face transformation tensor
virtual const tensorField& forwardT() const virtual const tensorField& forwardT() const
{ {
return forwardT_; return forwardT_;
} }
//- Return message tag used for sending //- Return message tag used for sending
virtual int tag() const virtual int tag() const
{ {
return tag_; return tag_;
} }
// Edit // Edit
//- Return message tag used for sending //- Message tag used for sending (modifiable)
int& tag() int& tag()
{ {
return tag_; return tag_;
} }
}; };

View File

@ -40,9 +40,9 @@ SourceFiles
#define Foam_lduInterfaceField_H #define Foam_lduInterfaceField_H
#include "lduInterface.H" #include "lduInterface.H"
#include "lduAddressing.H"
#include "primitiveFieldsFwd.H" #include "primitiveFieldsFwd.H"
#include "Pstream.H" #include "Pstream.H"
#include "lduAddressing.H"
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
@ -100,43 +100,44 @@ public:
// Member Functions // Member Functions
// Access //- Return the interface
const lduInterface& interface() const noexcept
{
return interface_;
}
//- Return the interface //- Return the interface type
const lduInterface& interface() const noexcept virtual const word& interfaceFieldType() const
{ {
return interface_; return type();
} }
//- Return the interface type
virtual const word& interfaceFieldType() const // Coupled Interface
{
return type(); //- Are all (receive) data available?
} virtual bool ready() const
{
return true;
}
//- Whether matrix has been updated
bool updatedMatrix() const noexcept
{
return updatedMatrix_;
}
//- Set matrix as update-to-date, return the previous value
bool updatedMatrix(bool flag) const noexcept
{
bool old(updatedMatrix_);
updatedMatrix_ = flag;
return old;
}
// Coupled interface matrix update // Coupled interface matrix update
//- Whether matrix has been updated
bool updatedMatrix() const noexcept
{
return updatedMatrix_;
}
//- Set matrix as update-to-date, return the previous value
bool updatedMatrix(bool flag) const noexcept
{
bool old(updatedMatrix_);
updatedMatrix_ = flag;
return old;
}
//- Is all data available
virtual bool ready() const
{
return true;
}
//- Initialise neighbour matrix update. //- Initialise neighbour matrix update.
//- Add/subtract coupled contributions to matrix //- Add/subtract coupled contributions to matrix
virtual void initInterfaceMatrixUpdate virtual void initInterfaceMatrixUpdate

View File

@ -84,10 +84,10 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
<< " in file " << this->internalField().objectPath() << " in file " << this->internalField().objectPath()
<< exit(FatalError); << exit(FatalError);
} }
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -141,10 +141,10 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
scalarSendBuf_(std::move(ptf.scalarSendBuf_)), scalarSendBuf_(std::move(ptf.scalarSendBuf_)),
scalarRecvBuf_(std::move(ptf.scalarRecvBuf_)) scalarRecvBuf_(std::move(ptf.scalarRecvBuf_))
{ {
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -162,10 +162,10 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
sendRequest_(-1), sendRequest_(-1),
recvRequest_(-1) recvRequest_(-1)
{ {
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -174,12 +174,25 @@ Foam::processorFaPatchField<Type>::processorFaPatchField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
bool Foam::processorFaPatchField<Type>::ready() const bool Foam::processorFaPatchField<Type>::all_ready() const
{ {
return UPstream::finishedRequestPair(recvRequest_, sendRequest_); return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
} }
template<class Type>
bool Foam::processorFaPatchField<Type>::ready() const
{
const bool ok = UPstream::finishedRequest(recvRequest_);
if (ok)
{
recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
}
return ok;
}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::processorFaPatchField<Type>::patchNeighbourField() const Foam::processorFaPatchField<Type>::patchNeighbourField() const
@ -187,8 +200,7 @@ Foam::processorFaPatchField<Type>::patchNeighbourField() const
if (debug && !this->ready()) if (debug && !this->ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
return *this; return *this;
@ -259,9 +271,8 @@ void Foam::processorFaPatchField<Type>::evaluate
{ {
// Fast path. Received into *this // Fast path. Received into *this
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }
@ -303,11 +314,10 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Fast path. // Fast path.
if (debug && !this->ready()) if (debug && !this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request(s) on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
@ -368,9 +378,8 @@ void Foam::processorFaPatchField<Type>::updateInterfaceMatrix
{ {
// Fast path: consume straight from receive buffer // Fast path: consume straight from receive buffer
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }
@ -411,11 +420,10 @@ void Foam::processorFaPatchField<Type>::initInterfaceMatrixUpdate
if (commsType == UPstream::commsTypes::nonBlocking) if (commsType == UPstream::commsTypes::nonBlocking)
{ {
// Fast path. // Fast path.
if (debug && !this->ready()) if (debug && !this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request(s) on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
@ -475,9 +483,8 @@ void Foam::processorFaPatchField<Type>::updateInterfaceMatrix
{ {
// Fast path: consume straight from receive buffer // Fast path: consume straight from receive buffer
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }

View File

@ -88,6 +88,12 @@ class processorFaPatchField
mutable solveScalarField scalarRecvBuf_; mutable solveScalarField scalarRecvBuf_;
// Private Member Functions
//- Receive and send requests have both completed
virtual bool all_ready() const;
public: public:
//- Runtime type information //- Runtime type information
@ -164,33 +170,30 @@ public:
~processorFaPatchField() = default; ~processorFaPatchField() = default;
// Member functions // Member Functions
// Access // Coupling
//- Return true if running parallel //- The patch field is coupled if running in parallel
virtual bool coupled() const virtual bool coupled() const { return UPstream::parRun(); }
{
return Pstream::parRun();
}
//- Return neighbour field given internal field //- Are all (receive) data available?
tmp<Field<Type>> patchNeighbourField() const; virtual bool ready() const;
//- Return neighbour field given internal field
tmp<Field<Type>> patchNeighbourField() const;
// Evaluation functions // Evaluation
//- Initialise the evaluation of the patch field //- Initialise the evaluation of the patch field
virtual void initEvaluate(const Pstream::commsTypes commsType); virtual void initEvaluate(const Pstream::commsTypes commsType);
//- Evaluate the patch field //- Evaluate the patch field
virtual void evaluate(const Pstream::commsTypes commsType); virtual void evaluate(const Pstream::commsTypes commsType);
//- Return patch-normal gradient //- Return patch-normal gradient
virtual tmp<Field<Type>> snGrad() const; virtual tmp<Field<Type>> snGrad() const;
//- Is all data available
virtual bool ready() const;
// Coupled interface functionality // Coupled interface functionality
@ -245,43 +248,44 @@ public:
const Pstream::commsTypes commsType const Pstream::commsTypes commsType
) const; ) const;
//- Processor coupled interface functions
//- Return communicator used for comms // Processor coupled interface functions
virtual label comm() const
{
return UPstream::worldComm;
}
//- Return processor number //- Return communicator used for communication
virtual int myProcNo() const virtual label comm() const
{ {
return procPatch_.myProcNo(); return procPatch_.comm();
} }
//- Return neighbour processor number //- Return processor number
virtual int neighbProcNo() const virtual int myProcNo() const
{ {
return procPatch_.neighbProcNo(); return procPatch_.myProcNo();
} }
//- Does the patch field perform the transformation //- Return neighbour processor number
virtual bool doTransform() const virtual int neighbProcNo() const
{ {
return (pTraits<Type>::rank && !procPatch_.parallel()); return procPatch_.neighbProcNo();
} }
//- Return face transformation tensor //- Does the patch field perform the transformation
virtual const tensorField& forwardT() const virtual bool doTransform() const
{ {
return procPatch_.forwardT(); return (pTraits<Type>::rank && !procPatch_.parallel());
} }
//- Return rank of component for transform //- Return face transformation tensor
virtual int rank() const virtual const tensorField& forwardT() const
{ {
return pTraits<Type>::rank; return procPatch_.forwardT();
} }
//- Return rank of component for transform
virtual int rank() const
{
return pTraits<Type>::rank;
}
}; };

View File

@ -74,12 +74,25 @@ Foam::calculatedProcessorFvPatchField<Type>::calculatedProcessorFvPatchField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
bool Foam::calculatedProcessorFvPatchField<Type>::ready() const bool Foam::calculatedProcessorFvPatchField<Type>::all_ready() const
{ {
return UPstream::finishedRequestPair(recvRequest_, sendRequest_); return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
} }
template<class Type>
bool Foam::calculatedProcessorFvPatchField<Type>::ready() const
{
const bool ok = UPstream::finishedRequest(recvRequest_);
if (ok)
{
recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
}
return ok;
}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::calculatedProcessorFvPatchField<Type>::patchNeighbourField() const Foam::calculatedProcessorFvPatchField<Type>::patchNeighbourField() const
@ -87,10 +100,10 @@ Foam::calculatedProcessorFvPatchField<Type>::patchNeighbourField() const
if (!this->ready()) if (!this->ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch of size " << procInterface_.faceCells().size() << "Outstanding request on patch of size "
<< procInterface_.faceCells().size()
<< " between proc " << procInterface_.myProcNo() << " between proc " << procInterface_.myProcNo()
<< " and " << procInterface_.neighbProcNo() << " and " << procInterface_.neighbProcNo()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
return *this; return *this;
@ -160,9 +173,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::evaluate
{ {
if (UPstream::parRun()) if (UPstream::parRun())
{ {
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }
@ -182,11 +194,11 @@ void Foam::calculatedProcessorFvPatchField<Type>::initInterfaceMatrixUpdate
const Pstream::commsTypes commsType const Pstream::commsTypes commsType
) const ) const
{ {
if (!this->ready()) if (!this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " //<< interface_.name() << "Outstanding request(s) on interface "
<< " outstanding request." //<< interface_.name()
<< abort(FatalError); << abort(FatalError);
} }
@ -275,9 +287,8 @@ void Foam::calculatedProcessorFvPatchField<Type>::updateInterfaceMatrix
if (UPstream::parRun()) if (UPstream::parRun())
{ {
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }

View File

@ -68,7 +68,7 @@ class calculatedProcessorFvPatchField
{ {
protected: protected:
// Protected data // Protected Data
//- Local reference cast into the interface //- Local reference cast into the interface
const lduPrimitiveProcessorInterface& procInterface_; const lduPrimitiveProcessorInterface& procInterface_;
@ -106,6 +106,10 @@ protected:
) const; ) const;
//- Receive and send requests have both completed
virtual bool all_ready() const;
public: public:
//- Runtime type information //- Runtime type information
@ -161,73 +165,30 @@ public:
virtual ~calculatedProcessorFvPatchField() = default; virtual ~calculatedProcessorFvPatchField() = default;
// Member functions // Member Functions
// processorLduInterfaceField implementation // Coupling
//- Return communicator used for comms //- The patch field is coupled if running in parallel
virtual label comm() const virtual bool coupled() const { return UPstream::parRun(); }
{
return procInterface_.comm();
}
//- Return processor number //- Are all (receive) data available?
virtual int myProcNo() const virtual bool ready() const;
{
return procInterface_.myProcNo(); //- Return neighbour field of internal field
} virtual tmp<Field<Type>> patchNeighbourField() const;
//- Return neighbour processor number // Evaluation
virtual int neighbProcNo() const
{
return procInterface_.myProcNo();
}
//- Is the transform required //- Initialise the evaluation of the patch field
virtual bool doTransform() const virtual void initEvaluate(const Pstream::commsTypes commsType);
{
return false;
}
//- Return face transformation tensor //- Evaluate the patch field
virtual const tensorField& forwardT() const virtual void evaluate(const Pstream::commsTypes commsType);
{
return procInterface_.forwardT();
}
//- Return rank of component for transform
virtual int rank() const
{
return pTraits<Type>::rank;
}
// Access // Coupled interface functionality
//- Return true if this patch field is coupled.
// Our field supplies coefficients to the fvMatrix so
// should behave as a processorFvPatchField (in
// addBoundarySource it should not add to the source)
virtual bool coupled() const
{
return Pstream::parRun();
}
//- Return neighbour field of internal field
virtual tmp<Field<Type>> patchNeighbourField() const;
// Evaluation functions
//- Is all data available
virtual bool ready() const;
//- Initialise the evaluation of the patch field
virtual void initEvaluate(const Pstream::commsTypes commsType);
//- Evaluate the patch field
virtual void evaluate(const Pstream::commsTypes commsType);
//- Initialise neighbour matrix update //- Initialise neighbour matrix update
virtual void initInterfaceMatrixUpdate virtual void initInterfaceMatrixUpdate
@ -285,8 +246,44 @@ public:
NotImplemented; NotImplemented;
} }
//- Write
// virtual void write(Ostream& os) const; // Processor coupled interface functions
//- Return communicator used for communication
virtual label comm() const
{
return procInterface_.comm();
}
//- Return processor number
virtual int myProcNo() const
{
return procInterface_.myProcNo();
}
//- Return neighbour processor number
virtual int neighbProcNo() const
{
return procInterface_.myProcNo();
}
//- Is the transform required
virtual bool doTransform() const
{
return false;
}
//- Return face transformation tensor
virtual const tensorField& forwardT() const
{
return procInterface_.forwardT();
}
//- Return rank of component for transform
virtual int rank() const
{
return pTraits<Type>::rank;
}
}; };

View File

@ -118,10 +118,10 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
<< " in file " << this->internalField().objectPath() << " in file " << this->internalField().objectPath()
<< exit(FatalError); << exit(FatalError);
} }
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -143,10 +143,10 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
scalarSendBuf_(std::move(ptf.scalarSendBuf_)), scalarSendBuf_(std::move(ptf.scalarSendBuf_)),
scalarRecvBuf_(std::move(ptf.scalarRecvBuf_)) scalarRecvBuf_(std::move(ptf.scalarRecvBuf_))
{ {
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -164,10 +164,10 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
sendRequest_(-1), sendRequest_(-1),
recvRequest_(-1) recvRequest_(-1)
{ {
if (debug && !ptf.ready()) if (debug && !ptf.all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << " outstanding request." << "Outstanding request(s) on patch " << procPatch_.name()
<< abort(FatalError); << abort(FatalError);
} }
} }
@ -176,12 +176,25 @@ Foam::processorFvPatchField<Type>::processorFvPatchField
// * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * //
template<class Type> template<class Type>
bool Foam::processorFvPatchField<Type>::ready() const bool Foam::processorFvPatchField<Type>::all_ready() const
{ {
return UPstream::finishedRequestPair(recvRequest_, sendRequest_); return UPstream::finishedRequestPair(recvRequest_, sendRequest_);
} }
template<class Type>
bool Foam::processorFvPatchField<Type>::ready() const
{
const bool ok = UPstream::finishedRequest(recvRequest_);
if (ok)
{
recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
}
return ok;
}
template<class Type> template<class Type>
Foam::tmp<Foam::Field<Type>> Foam::tmp<Foam::Field<Type>>
Foam::processorFvPatchField<Type>::patchNeighbourField() const Foam::processorFvPatchField<Type>::patchNeighbourField() const
@ -189,8 +202,7 @@ Foam::processorFvPatchField<Type>::patchNeighbourField() const
if (debug && !this->ready()) if (debug && !this->ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
return *this; return *this;
@ -209,7 +221,7 @@ void Foam::processorFvPatchField<Type>::initEvaluate
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& (std::is_integral<Type>::value || !UPstream::floatTransfer) && (std::is_integral<Type>::value || !UPstream::floatTransfer)
) )
{ {
@ -263,15 +275,14 @@ void Foam::processorFvPatchField<Type>::evaluate
{ {
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& (std::is_integral<Type>::value || !UPstream::floatTransfer) && (std::is_integral<Type>::value || !UPstream::floatTransfer)
) )
{ {
// Fast path: received into *this // Fast path: received into *this
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }
@ -324,16 +335,15 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& !UPstream::floatTransfer && !UPstream::floatTransfer
) )
{ {
// Fast path. // Fast path.
if (debug && !this->ready()) if (debug && !this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request(s) on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
@ -392,15 +402,14 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& !UPstream::floatTransfer && !UPstream::floatTransfer
) )
{ {
// Fast path: consume straight from receive buffer // Fast path: consume straight from receive buffer
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }
@ -447,16 +456,15 @@ void Foam::processorFvPatchField<Type>::initInterfaceMatrixUpdate
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& (std::is_integral<Type>::value || !UPstream::floatTransfer) && (std::is_integral<Type>::value || !UPstream::floatTransfer)
) )
{ {
// Fast path. // Fast path.
if (debug && !this->ready()) if (debug && !this->all_ready())
{ {
FatalErrorInFunction FatalErrorInFunction
<< "On patch " << procPatch_.name() << "Outstanding request(s) on patch " << procPatch_.name()
<< " outstanding request."
<< abort(FatalError); << abort(FatalError);
} }
@ -514,15 +522,14 @@ void Foam::processorFvPatchField<Type>::updateInterfaceMatrix
if if
( (
commsType == Pstream::commsTypes::nonBlocking commsType == UPstream::commsTypes::nonBlocking
&& (std::is_integral<Type>::value || !UPstream::floatTransfer) && (std::is_integral<Type>::value || !UPstream::floatTransfer)
) )
{ {
// Fast path: consume straight from receive buffer // Fast path: consume straight from receive buffer
// Require receive data. Update the send request state. // Require receive data.
// OR: UPstream::waitRequestPair(recvRequest_, sendRequest_); // Only update the send request state.
UPstream::waitRequest(recvRequest_); recvRequest_ = -1; UPstream::waitRequest(recvRequest_); recvRequest_ = -1;
if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1; if (UPstream::finishedRequest(sendRequest_)) sendRequest_ = -1;
} }

View File

@ -96,6 +96,12 @@ class processorFvPatchField
mutable solveScalarField scalarRecvBuf_; mutable solveScalarField scalarRecvBuf_;
// Private Member Functions
//- Receive and send requests have both completed
virtual bool all_ready() const;
public: public:
//- Runtime type information //- Runtime type information
@ -174,34 +180,34 @@ public:
// Member Functions // Member Functions
// Access // Coupling
//- Return true if running parallel //- The patch field is coupled if running in parallel
virtual bool coupled() const virtual bool coupled() const { return UPstream::parRun(); }
{
return Pstream::parRun();
}
//- Return neighbour field given internal field //- Are all (receive) data available?
virtual tmp<Field<Type>> patchNeighbourField() const; virtual bool ready() const;
//- Return neighbour field given internal field
virtual tmp<Field<Type>> patchNeighbourField() const;
// Evaluation functions // Evaluation
//- Initialise the evaluation of the patch field //- Initialise the evaluation of the patch field
virtual void initEvaluate(const Pstream::commsTypes commsType); virtual void initEvaluate(const Pstream::commsTypes commsType);
//- Evaluate the patch field //- Evaluate the patch field
virtual void evaluate(const Pstream::commsTypes commsType); virtual void evaluate(const Pstream::commsTypes commsType);
//- Return patch-normal gradient //- Return patch-normal gradient
virtual tmp<Field<Type>> snGrad virtual tmp<Field<Type>> snGrad
( (
const scalarField& deltaCoeffs const scalarField& deltaCoeffs
) const; ) const;
//- Is all data available
virtual bool ready() const; // Coupled interface functionality
//- Initialise neighbour matrix update //- Initialise neighbour matrix update
virtual void initInterfaceMatrixUpdate virtual void initInterfaceMatrixUpdate
@ -254,43 +260,43 @@ public:
) const; ) const;
//- Processor coupled interface functions // Processor coupled interface functions
//- Return communicator used for comms //- Return communicator used for communication
virtual label comm() const virtual label comm() const
{ {
return procPatch_.comm(); return procPatch_.comm();
} }
//- Return processor number //- Return processor number
virtual int myProcNo() const virtual int myProcNo() const
{ {
return procPatch_.myProcNo(); return procPatch_.myProcNo();
} }
//- Return neighbour processor number //- Return neighbour processor number
virtual int neighbProcNo() const virtual int neighbProcNo() const
{ {
return procPatch_.neighbProcNo(); return procPatch_.neighbProcNo();
} }
//- Does the patch field perform the transformation //- Does the patch field perform the transformation
virtual bool doTransform() const virtual bool doTransform() const
{ {
return (pTraits<Type>::rank && !procPatch_.parallel()); return (pTraits<Type>::rank && !procPatch_.parallel());
} }
//- Return face transformation tensor //- Return face transformation tensor
virtual const tensorField& forwardT() const virtual const tensorField& forwardT() const
{ {
return procPatch_.forwardT(); return procPatch_.forwardT();
} }
//- Return rank of component for transform //- Return rank of component for transform
virtual int rank() const virtual int rank() const
{ {
return pTraits<Type>::rank; return pTraits<Type>::rank;
} }
}; };