From be30598e3d80babbda8462f3e6d022e7ae52060c Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Mon, 3 Mar 2025 11:13:07 +0100 Subject: [PATCH] ENH: add UPstream::localNode_parentProcs() method - returns the (start/size) range of the commLocalNode ranks in terms of the (const) world communicator processors. This allows mapping back into lists defined in terms of the world ranks. --- .../test/nodeTopology/Test-nodeTopology.cxx | 7 ++++ src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C | 32 +++++++++++++++++++ src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H | 7 ++-- 3 files changed, 44 insertions(+), 2 deletions(-) diff --git a/applications/test/nodeTopology/Test-nodeTopology.cxx b/applications/test/nodeTopology/Test-nodeTopology.cxx index 9909d51d4f..58b3d56cde 100644 --- a/applications/test/nodeTopology/Test-nodeTopology.cxx +++ b/applications/test/nodeTopology/Test-nodeTopology.cxx @@ -115,6 +115,13 @@ int main(int argc, char *argv[]) ); + if (UPstream::parRun()) + { + const auto& procs = UPstream::localNode_parentProcs(); + Perr<< "local processors: [" << procs.min() + << ".." << procs.max() << ']' << endl; + } + // Generate the graph if (UPstream::master(UPstream::worldComm)) { diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C index 4ba0e1f4ab..d3b8e489e3 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.C @@ -791,6 +791,38 @@ const Foam::List& Foam::UPstream::interNode_offsets() } +const Foam::UPstream::rangeType& Foam::UPstream::localNode_parentProcs() +{ + static UPstream::rangeType singleton; + + if (singleton.empty()) + { + // The inter-node offsets [in const world comm] also include a + // startup guard + const auto& offsets = UPstream::interNode_offsets(); + + const auto nodei = + Foam::findLower + ( + offsets, + // My place within const world comm + UPstream::myProcNo(constWorldComm_)+1 + ); + + if (nodei >= 0) + { + singleton.reset + ( + offsets[nodei], + offsets[nodei+1] - offsets[nodei] + ); + } + } + + return singleton; +} + + // * * * * * * * * * * * * * * Static Data Members * * * * * * * * * * * * * // bool Foam::UPstream::parRun_(false); diff --git a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H index d0e23c298c..a18d46128e 100644 --- a/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H +++ b/src/OpenFOAM/db/IOstreams/Pstreams/UPstream.H @@ -1232,6 +1232,9 @@ public: //- Processor offsets corresponding to the inter-node communicator static const List& interNode_offsets(); + //- The range (start/size) of the commLocalNode ranks in terms of the + //- (const) world communicator processors. + static const rangeType& localNode_parentProcs(); //- Linear communication schedule (special case) for given communicator static const commsStructList& linearCommunication(int communicator); @@ -1240,8 +1243,8 @@ public: static const commsStructList& treeCommunication(int communicator); //- Communication schedule for all-to-master (proc 0) as - //- linear/tree/none with switching based on UPstream::nProcsSimpleSum - //- and the is_parallel() state and the optional \c linear parameter. + //- linear/tree/none with switching based on UPstream::nProcsSimpleSum, + //- the is_parallel() state and the optional \c linear parameter. static const commsStructList& whichCommunication ( const int communicator,