51 { commsTypes::blocking,
"blocking" },
52 { commsTypes::scheduled,
"scheduled" },
53 { commsTypes::nonBlocking,
"nonBlocking" },
59 void Foam::UPstream::setParRun(
const label nProcs,
const bool haveThreads)
81 <<
"problem : comm:" << comm
92 <<
"problem : comm:" << comm
115 <<
"problem : comm:" << comm
129 <<
"problem : comm:" << comm
137 Pout<<
"UPstream::setParRun :" 147 const label parentIndex,
153 if (!freeComms_.empty())
156 index = freeComms_.back();
157 freeComms_.pop_back();
162 index = parentComm_.size();
164 myProcNo_.append(-1);
165 procIDs_.append(List<int>());
166 parentComm_.append(-1);
167 linearCommunication_.append(List<commsStruct>());
168 treeCommunication_.append(List<commsStruct>());
173 Pout<<
"Communicators : Allocating communicator " << index <<
endl 174 <<
" parent : " << parentIndex <<
endl 175 <<
" procs : " << subRanks <<
endl 180 myProcNo_[index] = 0;
186 auto& procIds = procIDs_[index];
187 procIds.resize_nocopy(subRanks.size());
189 label numSubRanks = 0;
190 bool monotonicOrder =
true;
191 for (
const label subRanki : subRanks)
197 if (monotonicOrder && numSubRanks)
199 monotonicOrder = (procIds[numSubRanks-1] < subRanki);
202 procIds[numSubRanks] = subRanki;
208 auto last = procIds.begin() + numSubRanks;
210 last = std::unique(procIds.begin(), last);
211 numSubRanks = label(last - procIds.begin());
214 procIds.resize(numSubRanks);
216 parentComm_[index] = parentIndex;
219 linearCommunication_[index] = List<commsStruct>(numSubRanks);
220 treeCommunication_[index] = List<commsStruct>(numSubRanks);
222 if (doPstream && parRun())
224 allocatePstreamCommunicator(parentIndex, index);
247 const label communicator,
252 if (communicator < 0)
259 Pout<<
"Communicators : Freeing communicator " << communicator
260 <<
" parent: " << parentComm_[communicator]
261 <<
" myProcNo: " << myProcNo_[communicator]
265 if (doPstream && parRun())
267 freePstreamCommunicator(communicator);
270 myProcNo_[communicator] = -1;
272 parentComm_[communicator] = -1;
273 linearCommunication_[communicator].clear();
283 forAll(myProcNo_, communicator)
285 if (myProcNo_[communicator] >= 0)
295 while (parent(comm) >= 0 && procID >= 0)
298 procID = parentRanks[procID];
308 const auto& parentRanks = procID(comm);
309 label parentComm = parent(comm);
311 int procID = baseProcID;
315 procID = procNo(parentComm, baseProcID);
318 return parentRanks.find(procID);
325 const label currentComm,
326 const int currentProcID
330 return procNo(comm, physProcID);
355 for (label procI = 1; procI < size(); procI++)
357 below[procI-1] = procI;
397 for (label step = 1; step < size(); step = mod)
403 above = procID - (procID % mod);
410 label j = procID + step;
411 j < size() && j < procID + mod;
419 label j = procID + step;
420 j < size() && j < procID + mod;
429 t = UPstream::commsStruct(size(), procID, above, below, allBelow);
439 return const_cast<UList<UPstream::commsStruct>&
>(*this).operator[](procID);
445 bool Foam::UPstream::parRun_(
false);
447 bool Foam::UPstream::haveThreads_(
false);
449 int Foam::UPstream::msgType_(1);
464 Foam::UPstream::linearCommunication_(10);
467 Foam::UPstream::treeCommunication_(10);
559 "nPollProcInterfaces",
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.
addcommsTypeToOpt addcommsTypeToOpt_("commsType")
static const Enum< commsTypes > commsTypeNames
Enumerated names for the communication types.
errorManipArg< error, int > exit(error &err, const int errNo=1)
commsTypes
Types of communications.
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.
void append(const T &val)
Append an element at the end of the list.
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
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 int myProcNo(const label communicator=worldComm)
Number of this process (starting from masterNo() = 0)
static label worldComm
Default world communicator (all processors). May differ from globalComm if local worlds are in use...
static label allocateCommunicator(const label parent, const labelUList &subRanks, const bool doPstream=true)
Allocate a new communicator with subRanks of parent communicator.
UList< label > labelUList
A UList of labels.
#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...
T & operator[](const label i)
Return element of UList.
static void freeCommunicators(const bool doPstream)
Free all communicators.
static constexpr label globalComm
Communicator for all processors, irrespective of any local worlds.
virtual ~addcommsTypeToOpt()=default
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator) is 1 for serial run.
void setSize(const label n)
Alias for resize()
static int nPollProcInterfaces
Number of polling cycles in processor updates.
word name(const expressions::valueTypeCode typeCode)
A word representation of a valueTypeCode. Empty for INVALID.
virtual void writeData(Foam::Ostream &os) const
Write.
labelList identity(const label len, label start=0)
Return an identity map of the given length with (map[i] == i)
void sort(UList< T > &list)
Sort the list.
virtual void readData(Foam::Istream &is)
Read.
const string & prefix() const noexcept
Return the stream prefix.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
Structure for communicating between processors.
const labelList & allBelow() const noexcept
The procIDs of all processors below (so not just directly below)
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)
defineTypeNameAndDebug(combustionModel, 0)
Wrapper class for allocating/freeing communicators.
Registered reader for UPstream::defaultCommsType.
const Foam::label nPredefinedComm
const labelList & allNotBelow() const noexcept
The procIDs of all processors that are above. The inverse set of allBelow without myProcNo...
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)
Process IDs within a given communicator.
static label nComms() noexcept
Number of currently defined communicators.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict(s).
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.
addcommsTypeToOpt(const char *name)
prefixOSstream Pout
OSstream wrapped stdout (std::cout) with parallel prefix.
static constexpr label selfComm
A communicator within the current rank only.
static int baseProcNo(label comm, int procID)
Return physical processor number (i.e. processor number in worldComm) given communicator and processo...
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
A class representing the concept of 1 (one) that can be used to avoid manipulating objects known to b...