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.
This commit is contained in:
Mark Olesen 2025-03-03 11:13:07 +01:00
parent d64682a7af
commit be30598e3d
3 changed files with 44 additions and 2 deletions

View File

@ -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))
{

View File

@ -791,6 +791,38 @@ const Foam::List<int>& 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);

View File

@ -1232,6 +1232,9 @@ public:
//- Processor offsets corresponding to the inter-node communicator
static const List<int>& 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,