52 a(iter.key()) |= iter.val();
58 static void printDOT(Ostream&
os,
const EdgeMap<unsigned>& connections)
60 os <<
nl <<
"// Multiworld communication graph:" <<
nl;
68 os << worldi <<
" [xlabel=" << worldi
69 <<
",label=\"" << worldName <<
"\"]" <<
nl;
76 for (
const edge& connect : connections.sortedToc())
79 os << connect.first() <<
" -- " << connect.second();
82 if (connections.lookup(connect, 0u) != 3u)
84 os <<
" [style=dashed] // mismatched?";
91 os <<
"// end graph" <<
nl;
99 Foam::edge Foam::multiWorldConnections::worldPair(
const label otherWorld)
103 Perr<<
"ignore: no world or non-parallel" <<
endl;
108 Perr<<
"ignore: invalid world: " << otherWorld <<
endl;
115 return edge(thisWorldID, otherWorld,
true);
119 Foam::edge Foam::multiWorldConnections::worldPair(
const word& otherWorld)
123 Perr<<
"ignore: no world or non-parallel" <<
endl;
130 if (otherWorldID < 0)
133 <<
"Cannot find world " << otherWorld
139 return edge(thisWorldID, otherWorldID,
true);
143 Foam::label Foam::multiWorldConnections::createCommunicator(
const edge& worlds)
155 DynamicList<label> subRanks(worldIDs.size());
158 if (worlds.found(worldIDs[proci]))
160 subRanks.push_back(proci);
169 Pout<<
"multiWorld::communicator :" 172 <<
" sub-ranks: " << subRanks
173 <<
" comm:" << comm <<
endl;
201 return table_.empty();
207 return table_.size();
220 const edge& connect = iter.key();
225 (connect.
first() == thisWorldID ? 1u : 2u)
237 label brokenConnections = 0;
242 if (iter.val() != 3u)
248 if (brokenConnections)
255 <<
"Has " << brokenConnections
256 <<
" broken world-world connections";
267 for (
const edge& connect : allConnections.
sortedToc())
272 auto iter = table_.find(connect);
273 if (iter.good() && iter.val() == -1)
275 iter.val() = createCommunicator(connect);
294 edge worlds(worldPair(otherWorld));
301 const bool added = table_.insert(worlds, -1);
303 Pout<< (added ?
"Add" :
"Existing") <<
" connection from " 313 edge worlds(worldPair(otherWorld));
320 const bool added = table_.insert(worlds, -1);
322 Pout<< (added ?
"Add" :
"Existing") <<
" connection from " 331 const label otherWorldID
338 edge worlds(worldPair(otherWorldID));
345 const auto iter = table_.cfind(worlds);
350 <<
"No connection registered for worlds " << worlds
360 const_cast<multiWorldConnections&
>(*this).createComms();
372 const word& otherWorld
379 edge worlds(worldPair(otherWorld));
386 const auto iter = table_.cfind(worlds);
391 <<
"No connection registered for worlds " << worlds
401 const_cast<multiWorldConnections&
>(*this).createComms();
424 if (iter.val() == -1)
427 const_cast<multiWorldConnections&
>(*this).createComms();
437 list[i] = iter.val();
static const word & myWorld()
My world.
label getCommById(const label otherWorld) const
Get communicator for myWorld to other world connection by ID.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
const T & first() const noexcept
Access the first element.
void operator()(EdgeMap< unsigned > &a, const EdgeMap< unsigned > &b) const
static const labelList & worldIDs() noexcept
The indices into allWorlds for all processes.
static void printDOT(Ostream &os, const EdgeMap< unsigned > &connections)
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Centralized handling of multi-world MPI connections.
constexpr char nl
The newline '\n' character (0x0a)
static const multiWorldConnections & New(const Time &runTime)
Access mesh object.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static bool & parRun() noexcept
Test if this a parallel run.
tmp< DimensionedField< TypeR, GeoMesh > > New(const tmp< DimensionedField< TypeR, GeoMesh >> &tf1, const word &name, const dimensionSet &dimensions, const bool initCopy=false)
Global function forwards to reuseTmpDimensionedField::New.
labelList comms() const
Get communicators used for myWorld to other worlds in sorted order.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
#define forAll(list, i)
Loop across all elements in list.
bool insert(const edge &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
bool empty() const noexcept
True if no world-to-world connections are defined.
static label commWarn(const label communicator) noexcept
Alter communicator debugging setting. Warns for use of any communicator differing from specified...
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
const dimensionedScalar b
Wien displacement law constant: default SI units: [m.K].
A class for handling words, derived from Foam::string.
void sort(UList< T > &list)
Sort the list.
static void combineReduce(T &value, const CombineOp &cop, const int tag=UPstream::msgType(), const label comm=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors...
virtual Ostream & endBlock()
Write end block group.
multiWorldConnections(const Time &runTime)
Construct.
label find(const T &val) const
Find index of the first occurrence of the value.
bool good() const noexcept
True if the vertices are unique and non-negative.
label getCommByName(const word &otherWorld) const
Get communicator for myWorld to other world connection by NAME.
int debug
Static debugging option.
Map from edge (expressed as its endpoints) to value. Hashing (and ==) on an edge is symmetric...
OBJstream os(runTime.globalPath()/outputName)
defineTypeNameAndDebug(combustionModel, 0)
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds)
label size() const noexcept
Number of world-to-world connections defined.
bool addConnectionByName(const word &otherWorld)
Define a connection from myWorld to other world by NAME.
virtual void indent() override
Add indentation characters.
List< edge > sortedToc() const
The table of contents (the keys) in sorted order.
messageStream Info
Information stream (stdout output on master, null elsewhere)
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
void createComms()
Create all communicators. Low-level, not normally called directly.
List< label > labelList
A List of labels.
static const wordList & allWorlds() noexcept
All worlds.
bool addConnectionById(const label otherWorld)
Define a connection from myWorld to other world by ID.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
forAllConstIters(mixture.phases(), phase)
static label myWorldID()
My worldID.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
static constexpr label commGlobal() noexcept
Communicator for all ranks, irrespective of any local worlds.