From d37cb64efececa82f1ca636fce6f1871ca0acfad Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 21 Feb 2022 14:49:32 +0100 Subject: [PATCH] ENH: broadcast for Foam::scatter() instead of manual tree communication - use MPI_Bcast intrinsic instead of manual tree to reduce the overall number of messages. Old behaviour can be re-enabled with `#define Foam_Pstream_scatter_nobroadcast` --- src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H | 3 ++ .../db/IOstreams/Pstreams/gatherScatter.C | 31 +++++++++++++++++-- 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H index e811fce1b0..375d7b790a 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/Pstream.H @@ -45,6 +45,9 @@ SourceFiles #include "UPstream.H" #include "DynamicList.H" +// Legacy +// #define Foam_Pstream_scatter_nobroadcast + // * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * // namespace Foam diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatter.C b/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatter.C index 6eea209698..834ae781de 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatter.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/gatherScatter.C @@ -32,9 +32,7 @@ Description \*---------------------------------------------------------------------------*/ -#include "UOPstream.H" #include "OPstream.H" -#include "UIPstream.H" #include "IPstream.H" #include "contiguous.H" @@ -147,6 +145,34 @@ void Pstream::scatter const label comm ) { + #ifndef Foam_Pstream_scatter_nobroadcast + if (UPstream::parRun() && UPstream::nProcs(comm) > 1) + { + if (is_contiguous::value) + { + UPstream::broadcast + ( + reinterpret_cast(&Value), + sizeof(T), + comm, + UPstream::masterNo() + ); + } + else + { + if (UPstream::master(comm)) + { + OPBstream toAll(UPstream::masterNo(), comm); + toAll << Value; + } + else + { + IPBstream fromMaster(UPstream::masterNo(), comm); + fromMaster >> Value; + } + } + } + #else if (UPstream::parRun() && UPstream::nProcs(comm) > 1) { // Get my communication order @@ -212,6 +238,7 @@ void Pstream::scatter } } } + #endif }