53 { commsTypes::buffered,
"buffered" },
54 { commsTypes::scheduled,
"scheduled" },
55 { commsTypes::nonBlocking,
"nonBlocking" },
57 { commsTypes::buffered,
"blocking" },
112 hostIDs[proci] = uniqDigests.
find(dig);
114 if (hostIDs[proci] < 0)
117 hostIDs[proci] = -(uniqDigests.
size() + 1);
125 hostIDs.data_bytes(),
126 hostIDs.size_bytes(),
139 void Foam::UPstream::setParRun(
const label nProcs,
const bool haveThreads)
145 labelRange singleProc(1);
166 <<
"problem : comm:" << comm
177 <<
"problem : comm:" << comm
200 <<
"problem : comm:" << comm
213 <<
"problem : comm:" << comm
224 Perr<<
"UPstream::setParRun :" 232 Foam::label Foam::UPstream::getAvailableCommIndex(
const label parentIndex)
235 if (!freeComms_.empty())
238 index = freeComms_.back();
239 freeComms_.pop_back();
242 myProcNo_[index] = -1;
243 parentComm_[index] = parentIndex;
245 procIDs_[index].clear();
246 linearCommunication_[index].clear();
247 treeCommunication_[index].clear();
252 index = parentComm_.size();
254 myProcNo_.push_back(-1);
255 parentComm_.push_back(parentIndex);
257 procIDs_.emplace_back();
258 linearCommunication_.emplace_back();
259 treeCommunication_.emplace_back();
268 const label parentIndex,
269 const labelRange& subRanks,
270 const bool withComponents
273 const label index = getAvailableCommIndex(parentIndex);
277 Perr<<
"Allocating communicator " << index <<
nl 278 <<
" parent : " << parentIndex <<
nl 279 <<
" procs : " << subRanks <<
nl 290 auto& procIds = procIDs_[index];
291 procIds.resize_nocopy(subRanks.size());
293 label numSubRanks = 0;
294 for (
const label subRanki : subRanks)
296 procIds[numSubRanks] = subRanki;
301 linearCommunication_[index].clear();
302 treeCommunication_[index].clear();
304 if (withComponents && parRun())
306 allocateCommunicatorComponents(parentIndex, index);
329 const label parentIndex,
331 const bool withComponents
334 const label index = getAvailableCommIndex(parentIndex);
338 Perr<<
"Allocating communicator " << index <<
nl 339 <<
" parent : " << parentIndex <<
nl 352 auto& procIds = procIDs_[index];
353 procIds.resize_nocopy(subRanks.size());
355 label numSubRanks = 0;
356 bool monotonicOrder =
true;
357 for (
const label subRanki : subRanks)
363 if (monotonicOrder && numSubRanks)
365 monotonicOrder = (procIds[numSubRanks-1] < subRanki);
368 procIds[numSubRanks] = subRanki;
374 auto last = procIds.begin() + numSubRanks;
376 last = std::unique(procIds.begin(), last);
377 numSubRanks = label(last - procIds.begin());
380 procIds.resize(numSubRanks);
383 linearCommunication_[index].clear();
384 treeCommunication_[index].clear();
386 if (withComponents && parRun())
388 allocateCommunicatorComponents(parentIndex, index);
411 const label parentCommunicator
416 DynamicList<label> subRanks(hostIDs.size());
422 if (hostIDs[proci] < 0)
424 subRanks.push_back(proci);
428 return allocateCommunicator(parentCommunicator, subRanks);
434 const label parentCommunicator
439 DynamicList<label> subRanks(hostIDs.size());
443 if (myHostId < 0) myHostId = -(myHostId + 1);
447 int id = hostIDs[proci];
448 if (
id < 0)
id = -(
id + 1);
452 subRanks.push_back(proci);
456 return allocateCommunicator(parentCommunicator, subRanks);
460 bool Foam::UPstream::allocateHostCommunicatorPairs()
463 const label parentCommunicator = worldComm;
471 if (interHostComm_ >= 0 || intraHostComm_ >= 0)
475 <<
"Host communicator(s) already created!" <<
endl 480 interHostComm_ = getAvailableCommIndex(parentCommunicator);
481 intraHostComm_ = getAvailableCommIndex(parentCommunicator);
484 if (intraHostComm_ < interHostComm_)
486 std::swap(intraHostComm_, interHostComm_);
495 Perr<<
"Allocating host communicators " 496 << interHostComm_ <<
", " << intraHostComm_ <<
nl 497 <<
" parent : " << parentCommunicator <<
nl 503 DynamicList<int> subRanks(hostIDs.size());
511 if (hostIDs[proci] < 0)
513 subRanks.push_back(proci);
516 hostIDs[proci] = -(hostIDs[proci] + 1);
520 const label index = interHostComm_;
523 procIDs_[index] = subRanks;
528 allocateCommunicatorComponents(parentCommunicator, index);
532 linearCommunication_[index].clear();
533 treeCommunication_[index].clear();
539 if (myHostId < 0) myHostId = -(myHostId + 1);
544 int id = hostIDs[proci];
545 if (
id < 0)
id = -(
id + 1);
549 subRanks.push_back(proci);
553 const label index = intraHostComm_;
556 procIDs_[index] = subRanks;
561 allocateCommunicatorComponents(parentCommunicator, index);
565 linearCommunication_[index].clear();
566 treeCommunication_[index].clear();
575 const label communicator,
576 const bool withComponents
580 if (communicator < 0)
586 if (interHostComm_ == communicator) interHostComm_ = -1;
587 if (intraHostComm_ == communicator) intraHostComm_ = -1;
591 Perr<<
"Communicators : Freeing communicator " << communicator
592 <<
" parent: " << parentComm_[communicator]
593 <<
" myProcNo: " << myProcNo_[communicator]
597 if (withComponents && parRun())
599 freeCommunicatorComponents(communicator);
602 myProcNo_[communicator] = -1;
603 parentComm_[communicator] = -1;
605 linearCommunication_[communicator].clear();
618 procID = parentRanks[procID];
631 int procID = baseProcID;
638 return parentRanks.find(procID);
645 const label currentComm,
646 const int currentProcID
657 if (linearCommunication_[communicator].empty())
659 linearCommunication_[communicator] =
663 return linearCommunication_[communicator];
670 if (treeCommunication_[communicator].empty())
672 treeCommunication_[communicator] =
676 return treeCommunication_[communicator];
686 commsStruct::printGraph(
Info(), comms);
697 if (intraHostComm_ < 0)
699 allocateHostCommunicatorPairs();
701 return intraHostComm_;
711 if (interHostComm_ < 0)
713 allocateHostCommunicatorPairs();
715 return interHostComm_;
721 return (intraHostComm_ >= 0 || interHostComm_ >= 0);
728 freeCommunicator(intraHostComm_,
true);
729 freeCommunicator(interHostComm_,
true);
735 bool Foam::UPstream::parRun_(
false);
737 bool Foam::UPstream::haveThreads_(
false);
739 int Foam::UPstream::msgType_(1);
753 Foam::UPstream::linearCommunication_(16);
756 Foam::UPstream::treeCommunication_(16);
759 Foam::label Foam::UPstream::intraHostComm_(-1);
760 Foam::label Foam::UPstream::interHostComm_(-1);
831 "nPollProcInterfaces",
851 class addcommsTypeToOpt
857 addcommsTypeToOpt(
const char*
name)
862 virtual ~addcommsTypeToOpt() =
default;
876 addcommsTypeToOpt addcommsTypeToOpt_(
"commsType");
registerOptSwitch("fa:geometryOrder", int, faMesh::geometryOrder_)
static bool floatTransfer
Should compact transfer be used in which floats replace doubles reducing the bandwidth requirement at...
Abstract base class for registered object with I/O. Used in debug symbol registration.
prefixOSstream Perr
OSstream wrapped stderr (std::cerr) with parallel prefix.
EnumType read(Istream &is) const
Read a word from Istream and return the corresponding enumeration.
void size(const label n)
Older name for setAddressableSize.
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
errorManipArg< error, int > exit(error &err, const int errNo=1)
static void clearHostComms()
Remove any existing intra and inter host communicators.
static void writeData(Ostream &os, const Type &val)
void resize(const label len)
Adjust allocated size of list.
commsTypes
Communications types.
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.
static void freeCommunicator(const label communicator, const bool withComponents=true)
Free a previously allocated communicator.
static List< int > getHostGroupIds(const label parentCommunicator)
A range or interval of labels defined by a start and a size.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
constexpr char nl
The newline '\n' character (0x0a)
static int maxCommsSize
Optional maximum message size (bytes)
static int nProcsSimpleSum
Number of processors to change from linear to tree communication.
Ostream & endl(Ostream &os)
Add newline and flush stream.
static label procNo(const label comm, const int baseProcID)
Return processor number in communicator (given physical processor number) (= reverse of baseProcNo) ...
static const List< commsStruct > & whichCommunication(const label communicator=worldComm)
Communication schedule for all-to-master (proc 0) as linear/tree/none with switching based on UPstrea...
static constexpr label commSelf() noexcept
Communicator within the current rank only.
static label commIntraHost()
Demand-driven: Intra-host communicator (respects any local worlds)
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
char * data_bytes() noexcept
Return pointer to the underlying array serving as data storage,.
const char * cdata_bytes() const noexcept
Raw digest char data (20 bytes) - const access. For consistency with other objects, these are not unsigned.
static bool hasHostComms()
Test for presence of any intra or inter host communicators.
static int tuning_NBX_
Tuning parameters for non-blocking exchange (NBX)
UList< label > labelUList
A UList of labels.
static label allocateInterHostCommunicator(const label parentCommunicator=worldComm)
Allocate an inter-host communicator.
#define forAll(list, i)
Loop across all elements in list.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static int nProcsNonblockingExchange
Number of processors to change to nonBlocking consensual exchange (NBX). Ignored for zero or negative...
Functions used by OpenFOAM that are specific to POSIX compliant operating systems and need to be repl...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
static int nPollProcInterfaces
Number of polling cycles in processor updates.
static label parent(const label communicator)
The parent communicator.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for expressions::valueTypeCode::INVALID.
A 1D vector of objects of type <T> that resizes itself as necessary to accept the new objects...
static const List< commsStruct > & treeCommunication(const label communicator=worldComm)
Communication schedule for tree all-to-master (proc 0)
void sort(UList< T > &list)
Sort the list.
static constexpr int masterNo() noexcept
Relative rank for the master process - is always 0.
const string & prefix() const noexcept
Return the stream prefix.
static label allocateIntraHostCommunicator(const label parentCommunicator=worldComm)
Allocate an intra-host communicator.
static void mpiGather(const char *sendData, char *recvData, int count, const label communicator=worldComm)
Receive identically-sized char data from all ranks.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
string hostName()
Return the system's host name, as per hostname(1)
label find(const T &val) const
Find index of the first occurrence of the value.
static label commInterHost()
Demand-driven: Inter-host communicator (respects any local worlds)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
int optimisationSwitch(const char *name, const int deflt=0)
Lookup optimisation switch or add default value.
int debug
Static debugging option.
OBJstream os(runTime.globalPath()/outputName)
static const List< commsStruct > & linearCommunication(const label communicator=worldComm)
Communication schedule for linear all-to-master (proc 0)
defineTypeNameAndDebug(combustionModel, 0)
static void printCommTree(const label communicator)
Debugging: print the communication tree.
void push_back(const T &val)
Copy append an element to the end of this list.
Wrapper class for allocating/freeing communicators. Always invokes allocateCommunicatorComponents() a...
const Foam::label nPredefinedComm
static commsTypes defaultCommsType
Default commsType.
Enum is a wrapper around a list of names/values that represent particular enumeration (or int) values...
static List< int > & procID(const label communicator)
The list of ranks within a given communicator.
static label nComms() noexcept
Number of currently defined communicators.
static bool broadcast(char *buf, const std::streamsize bufSize, const label communicator, const int rootProcNo=masterNo())
Broadcast buffer contents to all processes in given communicator. The sizes must match on all process...
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static constexpr unsigned max_size() noexcept
The dimensioned size of the digest is always 20 bytes.
messageStream Info
Information stream (stdout output on master, null elsewhere)
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
Functions to compute SHA1 message digest according to the NIST specification FIPS-180-1.
static bool haveThreads() noexcept
Have support for threads.
static const int mpiBufferSize
MPI buffer-size (bytes)
void addOptimisationObject(const char *name, simpleRegIOobject *obj)
Register optimisation switch read/write object.
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static int baseProcNo(label comm, int procID)
Return physical processor number (i.e. processor number in worldComm) given communicator and processo...
static label allocateCommunicator(const label parent, const labelRange &subRanks, const bool withComponents=true)
Allocate new communicator with contiguous sub-ranks on the parent communicator.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...
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.