From 048166c3d8126903a404a5cdbb36fc259d07f56f Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 29 Oct 2021 14:17:56 +0200 Subject: [PATCH] ENH: reduces buffer use / blocking in Ensight output - reuse single component buffer within an Ensight output method. Use direct UPstream read/write to avoid Pstream char buffers - replace blocking transfer with scheduled for Ensight cloud output --- .../ensight/output/ensightOutput.H | 17 +- .../ensight/output/ensightOutputTemplates.C | 185 +++++++++--------- .../conversion/ensight/ensightOutputCloud.C | 142 ++++++++------ .../conversion/ensight/ensightOutputCloud.H | 36 +++- .../ensight/ensightOutputCloudTemplates.C | 138 ++++++++----- 5 files changed, 302 insertions(+), 216 deletions(-) diff --git a/src/fileFormats/ensight/output/ensightOutput.H b/src/fileFormats/ensight/output/ensightOutput.H index fefe06a535..eeb34f3aca 100644 --- a/src/fileFormats/ensight/output/ensightOutput.H +++ b/src/fileFormats/ensight/output/ensightOutput.H @@ -50,6 +50,7 @@ SourceFiles #include "ListOps.H" #include "ListListOps.H" #include "IndirectList.H" +#include "DynamicList.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // @@ -260,17 +261,27 @@ labelList getPolysNFaces(const polyMesh& mesh, const labelUList& addr); labelList getPolysNPointsPerFace(const polyMesh& mesh, const labelUList& addr); -//- Copy specified field component into a scalarField -// works for various lists types +//- Copy specified field component into a scalar buffer +//- works for various lists types. Must be adequately sized before calling template class FieldContainer, class Type> void copyComponent ( - scalarField& res, + List& cmptBuffer, const FieldContainer& input, const direction cmpt ); +//- Write field content (component-wise) +template class FieldContainer, class Type> +void writeFieldContent +( + ensightFile& os, + const FieldContainer& fld, + bool parallel //!< Collective write? +); + + //- Write coordinates (component-wise) for the given part template class FieldContainer> bool writeCoordinates diff --git a/src/fileFormats/ensight/output/ensightOutputTemplates.C b/src/fileFormats/ensight/output/ensightOutputTemplates.C index 3c408d6fc2..0dd52790c8 100644 --- a/src/fileFormats/ensight/output/ensightOutputTemplates.C +++ b/src/fileFormats/ensight/output/ensightOutputTemplates.C @@ -27,20 +27,27 @@ License #include "ensightOutput.H" #include "ensightPTraits.H" +#include "globalIndex.H" // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // template class FieldContainer, class Type> void Foam::ensightOutput::Detail::copyComponent ( - scalarField& res, + List& cmptBuffer, const FieldContainer& input, const direction cmpt ) { - res.resize(input.size()); + if (cmptBuffer.size() < input.size()) + { + FatalErrorInFunction + << "Component buffer too small: " + << cmptBuffer.size() << " < " << input.size() << nl + << exit(FatalError); + } - auto iter = res.begin(); + auto iter = cmptBuffer.begin(); for (const Type& val : input) { @@ -50,6 +57,80 @@ void Foam::ensightOutput::Detail::copyComponent } +template class FieldContainer, class Type> +void Foam::ensightOutput::Detail::writeFieldContent +( + ensightFile& os, + const FieldContainer& fld, + bool parallel +) +{ + // already checked prior to calling, but extra safety + parallel = parallel && Pstream::parRun(); + + // Size information (offsets are irrelevant) + globalIndex procAddr; + if (parallel) + { + procAddr.reset(UPstream::listGatherValues