From a56a70b74497b9a5dfc2b587d64e51a14844f3c8 Mon Sep 17 00:00:00 2001 From: Mark Olesen Date: Fri, 29 Sep 2017 19:35:08 +0200 Subject: [PATCH] ENH: adjust infoSwitch to report host subscription (related to #531) - this compact form shows the subscription per host in the unsorted mpi order nProcs : 18 Hosts : ( (node1 6) (node2 8) (node3 4) ) This provides a succinct overview of which hosts have been subscribed or oversubscribed. - The longer list of "slave.pid" ... remains available on the InfoSwitch 'writeHosts' --- etc/controlDict | 13 +++--- src/OpenFOAM/global/argList/argList.C | 62 ++++++++++++++++++++++++++- 2 files changed, 68 insertions(+), 7 deletions(-) diff --git a/etc/controlDict b/etc/controlDict index 77a630c3fb..37ebba2b46 100644 --- a/etc/controlDict +++ b/etc/controlDict @@ -38,21 +38,24 @@ InfoSwitches // The default ASCII write precision writePrecision 6; - // Enable job info - writeJobInfo 0; - writeDictionaries 0; writeOptionalEntries 0; // Write lagrangian "positions" file in v1706 format (at earlier) writeLagrangianPositions 0; - // Report list of slaves/pids used (parallel) - writeSlaves 1; + // Report hosts used (parallel) + // - 0 = none + // - 1 = per-host-count, but unsorted + // - 2 = long output of "slave.pid" ... + writeHosts 1; // Report list of roots used (parallel) writeRoots 1; + // Enable job info + writeJobInfo 0; + // Allow profiling allowProfiling 1; diff --git a/src/OpenFOAM/global/argList/argList.C b/src/OpenFOAM/global/argList/argList.C index 20d4bffbc7..d832a6d7f2 100644 --- a/src/OpenFOAM/global/argList/argList.C +++ b/src/OpenFOAM/global/argList/argList.C @@ -102,6 +102,53 @@ Foam::argList::initValidTables::initValidTables() Foam::argList::initValidTables dummyInitValidTables; +// * * * * * * * * * * * * * * * Local Functions * * * * * * * * * * * * * * // + +namespace Foam +{ + +// Counted per machine name +// Does not include any sorting since we wish to know the ordering according to +// mpi rank. +// +// Always include the master too. +// This provides a better overview of the subscription +static void printHostsSubscription(const UList& slaveProcs) +{ + Info<< "Hosts :" << nl << "(" << nl; + + std::string prev = hostName(); + int count = 1; + + for (const auto& str : slaveProcs) + { + const auto dot = str.rfind('.'); + const std::string curr(std::move(str.substr(0, dot))); + + if (prev != curr) + { + if (count) + { + // Finish previous + Info<<" (" << prev.c_str() << " " << count << ")" << nl; + count = 0; + } + + prev = std::move(curr); + } + ++count; + } + + if (count) + { + // Finished last one + Info<<" (" << prev.c_str() << " " << count << ")" << nl; + } + + Info<< ")" << nl; +} + +} // * * * * * * * * * * * * * Static Member Functions * * * * * * * * * * * * // @@ -931,6 +978,7 @@ void Foam::argList::parse } stringList slaveProcs; + const int writeHostsSwitch = debug::infoSwitch("writeHosts", 1); // Collect slave machine/pid, and check that the build is identical if (parRunControl_.parRun()) @@ -981,8 +1029,9 @@ void Foam::argList::parse // Keep or discard slave and root information for reporting: if (Pstream::master() && parRunControl_.parRun()) { - if (!debug::infoSwitch("writeSlaves", 1)) + if (!writeHostsSwitch) { + // Clear here to ensures it doesn't show in the jobInfo slaveProcs.clear(); } if (!debug::infoSwitch("writeRoots", 1)) @@ -1000,7 +1049,16 @@ void Foam::argList::parse { if (slaveProcs.size()) { - Info<< "Slaves : " << slaveProcs << nl; + if (writeHostsSwitch == 1) + { + // Compact output (see etc/controlDict) + printHostsSubscription(slaveProcs); + } + else + { + // Full output of "slave.pid" + Info<< "Slaves : " << slaveProcs << nl; + } } if (roots.size()) {