From a91cb63d8863539918e06a470b41237e3a259d54 Mon Sep 17 00:00:00 2001 From: Hrvoje Jasak Date: Tue, 29 Nov 2016 12:44:48 +0000 Subject: [PATCH] Bugfix: processor polling in non-blocking comms --- .../constraint/processor/processorFvPatchField.C | 36 +++++++ .../constraint/processor/processorFvPatchField.H | 3 + ...ScalarField.H => processorFvPatchScalarField.C} | 105 ++++++++++++--------- .../processor/processorFvPatchScalarField.H | 38 +------- src/foam/db/IOstreams/Pstreams/Pstream.C | 2 - 5 files changed, 102 insertions(+), 82 deletions(-) copy src/finiteVolume/fields/fvPatchFields/constraint/processor/{processorFvPatchScalarField.H => processorFvPatchScalarField.C} (57%) diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C index ddbbaa98d..85fabfec5 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.C @@ -600,4 +600,40 @@ void Foam::processorFvPatchField::updateInterfaceMatrix } +template +bool Foam::processorFvPatchField::ready() const +{ + if + ( + outstandingSendRequest_ >= 0 + && outstandingSendRequest_ < Pstream::nRequests() + ) + { + bool finished = Pstream::finishedRequest(outstandingSendRequest_); + if (!finished) + { + return false; + } + } + outstandingSendRequest_ = -1; + + if + ( + outstandingRecvRequest_ >= 0 + && outstandingRecvRequest_ < Pstream::nRequests() + ) + { + bool finished = Pstream::finishedRequest(outstandingRecvRequest_); + + if (!finished) + { + return false; + } + } + outstandingRecvRequest_ = -1; + + return true; +} + + // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H index 6f9ed9f96..05972d2ae 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchField.H @@ -285,6 +285,9 @@ public: // Communication support + //- Is all data available + virtual bool ready() const; + //- Return communicator used for parallel communication virtual int comm() const { diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C similarity index 57% copy from src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H copy to src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C index 4c8e21a54..acce48d51 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.C @@ -23,11 +23,7 @@ License \*---------------------------------------------------------------------------*/ -#ifndef processorFvPatchScalarField_H -#define processorFvPatchScalarField_H - -#include "processorFvPatchField.H" -#include "scalarCoeffField.H" +#include "processorFvPatchScalarField.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -37,19 +33,6 @@ namespace Foam // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // template<> -void processorFvPatchField::initInterfaceMatrixUpdate -( - const scalarField&, - scalarField&, - const lduMatrix&, - const scalarField&, - const direction, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; - - -template<> void processorFvPatchField::updateInterfaceMatrix ( const scalarField&, @@ -59,39 +42,67 @@ void processorFvPatchField::updateInterfaceMatrix const direction, const Pstream::commsTypes commsType, const bool switchToLhs -) const; - - -template<> -void processorFvPatchField::initInterfaceMatrixUpdate -( - const scalarField& psiInternal, - scalarField&, - const BlockLduMatrix&, - const CoeffField&, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; +) const +{ + if (this->updatedMatrix()) + { + return; + } + + if (commsType == Pstream::nonBlocking) + { + // Fast path. + if + ( + outstandingRecvRequest_ >= 0 + && outstandingRecvRequest_ < Pstream::nRequests() + ) + { + Pstream::waitRequest(outstandingRecvRequest_); + } + + // Recv finished so assume sending finished as well. + outstandingSendRequest_ = -1; + outstandingRecvRequest_ = -1; + } + else + { + // Check size + scalarReceiveBuf_.setSize(this->size()); + + procPatch_.receive(commsType, scalarReceiveBuf_); + } + + // The data is now in scalarReceiveBuf_ for both cases + + // Transform according to the transformation tensor + // No transform for scalar. HJ, 29/Nov/2016 + + // Multiply the field by coefficients and add into the result + + const unallocLabelList& faceCells = this->patch().faceCells(); + + if (switchToLhs) + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] += coeffs[elemI]*scalarReceiveBuf_[elemI]; + } + } + else + { + forAll(faceCells, elemI) + { + result[faceCells[elemI]] -= coeffs[elemI]*scalarReceiveBuf_[elemI]; + } + } + + const_cast&>(*this).updatedMatrix() = true; +} -template<> -void processorFvPatchField::updateInterfaceMatrix -( - const scalarField&, - scalarField& result, - const BlockLduMatrix&, - const CoeffField& coeffs, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; - // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // } // End namespace Foam - -// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // - -#endif - // ************************************************************************* // diff --git a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H index 4c8e21a54..1c9d84b79 100644 --- a/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H +++ b/src/finiteVolume/fields/fvPatchFields/constraint/processor/processorFvPatchScalarField.H @@ -36,18 +36,8 @@ namespace Foam // * * * * * * * * * * * * * * * Member Functions * * * * * * * * * * * * * // -template<> -void processorFvPatchField::initInterfaceMatrixUpdate -( - const scalarField&, - scalarField&, - const lduMatrix&, - const scalarField&, - const direction, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; - +// Removed unnecessary specialisation for initInterfaceMatrixUpdate +// HJ, 29/Nov/2016 template<> void processorFvPatchField::updateInterfaceMatrix @@ -62,28 +52,10 @@ void processorFvPatchField::updateInterfaceMatrix ) const; -template<> -void processorFvPatchField::initInterfaceMatrixUpdate -( - const scalarField& psiInternal, - scalarField&, - const BlockLduMatrix&, - const CoeffField&, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; - +// Removed unnecessary specialisation for initInterfaceMatrixUpdate +// and updateInterfaceMatrix for block matrices +// HJ, 29/Nov/2016 -template<> -void processorFvPatchField::updateInterfaceMatrix -( - const scalarField&, - scalarField& result, - const BlockLduMatrix&, - const CoeffField& coeffs, - const Pstream::commsTypes commsType, - const bool switchToLhs -) const; // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // diff --git a/src/foam/db/IOstreams/Pstreams/Pstream.C b/src/foam/db/IOstreams/Pstreams/Pstream.C index cb78615d0..a7e6dc63c 100644 --- a/src/foam/db/IOstreams/Pstreams/Pstream.C +++ b/src/foam/db/IOstreams/Pstreams/Pstream.C @@ -922,8 +922,6 @@ Foam::Pstream::defaultCommsType ( "commsType", "nonBlocking", -// "scheduled", -// "blocking", "blocking, nonBlocking, scheduled" ); -- 2.11.4.GIT