52 a(iter.key()) |= iter.val();
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;
99Foam::edge Foam::multiWorldConnections::worldPair(
const label otherWorld)
103 Perr<<
"ignore: no world or non-parallel" <<
endl;
108 Perr<<
"ignore: invalid world: " << otherWorld <<
endl;
119Foam::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
143Foam::label Foam::multiWorldConnections::createCommunicator(
const edge& worlds)
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";
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
372 const word& otherWorld
379 edge worlds(worldPair(otherWorld));
386 const auto iter = table_.cfind(worlds);
391 <<
"No connection registered for worlds " << worlds
424 if (iter.val() == -1)
437 list[i] = iter.val();
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects.
Map from edge (expressed as its endpoints) to value. Hashing (and ==) on an edge is symmetric.
Foam::List< Key > sortedToc(const Compare &comp) const
const T & lookup(const Key &key, const T &deflt) const
Return hashed entry if it exists, or return the given default.
bool insert(const Key &key, const T &obj)
Copy insert a new entry, not overwriting existing entries.
void resize(const label len)
Adjust allocated size of list.
static FOAM_NO_DANGLING_REFERENCE const multiWorldConnections & New(const Time &mesh, Args &&... args)
virtual void indent() override
Add indentation characters.
An Ostream is an abstract base class for all output systems (streams, files, token lists,...
virtual Ostream & endBlock()
Write end block group.
virtual Ostream & beginBlock(const keyType &kw)
Write begin block group with the given name.
const T & first() const noexcept
Access the first element.
static void combineReduce(T &value, CombineOp cop, const int tag=UPstream::msgType(), const int communicator=UPstream::worldComm)
Reduce inplace (cf. MPI Allreduce) applying cop to inplace combine value from different processors.
Class to control time during OpenFOAM simulations that is also the top-level objectRegistry.
bool empty() const noexcept
True if List is empty (ie, size() is zero).
label find(const T &val) const
Find index of the first occurrence of the value.
static label commWorld() noexcept
Communicator for all ranks (respecting any local worlds).
static bool parRun(const bool on) noexcept
Set as parallel run on/off.
static const labelList & worldIDs() noexcept
The indices into allWorlds for all processes.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
static label myWorldID()
My worldID.
static label commWarn(const label communicator) noexcept
Alter communicator debugging setting. Warns for use of any communicator differing from specified....
static const wordList & allWorlds() noexcept
All worlds.
static constexpr int commGlobal() noexcept
Communicator for all ranks, irrespective of any local worlds.
static label newCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Create new communicator with sub-ranks on the parent communicator.
static bool & parRun() noexcept
Test if this a parallel run.
static const word & myWorld()
My world.
An edge is a list of two vertex labels. This can correspond to a directed graph edge or an edge on a ...
bool good() const noexcept
True if the vertices are unique and non-negative.
static edge sorted(label from, label to)
Create (in ascending order) from two vertex labels.
Centralized handling of multi-world MPI connections.
label getCommByName(const word &otherWorld) const
Get communicator for myWorld to other world connection by NAME.
bool empty() const noexcept
True if no world-to-world connections are defined.
bool addConnectionByName(const word &otherWorld)
Define a connection from myWorld to other world by NAME.
label getCommById(const label otherWorld) const
Get communicator for myWorld to other world connection by ID.
label size() const noexcept
Number of world-to-world connections defined.
void createComms()
Create all communicators. Low-level, not normally called directly.
labelList comms() const
Get communicators used for myWorld to other worlds in sorted order.
bool addConnectionById(const label otherWorld)
Define a connection from myWorld to other world by ID.
multiWorldConnections(const Time &runTime)
Construct.
static const multiWorldConnections & New(const Time &runTime)
Access mesh object.
A class for handling words, derived from Foam::string.
#define defineTypeNameAndDebug(Type, DebugSwitch)
Define the typeName and debug information.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
OBJstream os(runTime.globalPath()/outputName)
Namespace for handling debugging switches.
List< label > labelList
A List of labels.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
messageStream Info
Information stream (stdout output on master, null elsewhere).
static void printDOT(Ostream &os, const EdgeMap< unsigned > &connections)
Ostream & endl(Ostream &os)
Add newline and flush stream.
FlatOutput::OutputAdaptor< Container, Delimiters > flatOutput(const Container &obj, Delimiters delim)
Global flatOutput() function with specified output delimiters.
void sort(UList< T > &list)
Sort the list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
errorManipArg< error, int > exit(error &err, const int errNo=1)
constexpr char nl
The newline '\n' character (0x0a).
#define forAll(list, i)
Loop across all elements in list.
#define forAllConstIters(container, iter)
Iterate across all elements of the container object with const access.
void operator()(EdgeMap< unsigned > &a, const EdgeMap< unsigned > &b) const