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`
This commit is contained in:
Mark Olesen
2022-02-21 14:49:32 +01:00
committed by Andrew Heather
parent 8478595a15
commit d37cb64efe
2 changed files with 32 additions and 2 deletions

View File

@ -45,6 +45,9 @@ SourceFiles
#include "UPstream.H"
#include "DynamicList.H"
// Legacy
// #define Foam_Pstream_scatter_nobroadcast
// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace Foam

View File

@ -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<T>::value)
{
UPstream::broadcast
(
reinterpret_cast<char*>(&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
}