58 void Foam::UPstream::setParRun(
const label nProcs,
const bool haveThreads)
63 haveThreads_ = haveThreads;
70 <<
"problem : comm:" << comm
81 haveThreads_ = haveThreads;
86 label comm = allocateCommunicator(-1,
identity(nProcs),
true);
90 <<
"problem : comm:" << comm
115 linearCommunication[0] = commsStruct
125 for (
label procID = 1; procID < nProcs; procID++)
127 linearCommunication[procID] = commsStruct
136 return linearCommunication;
140 void Foam::UPstream::collectReceives
151 forAll(myChildren, childI)
153 allReceives.
append(myChildren[childI]);
154 collectReceives(myChildren[childI], receives, allReceives);
192 while ((1 << nLevels) < nProcs)
203 label childOffset = offset/2;
205 for (
label level = 0; level < nLevels; level++)
208 while (receiveID < nProcs)
211 label sendID = receiveID + childOffset;
215 receives[receiveID].
append(sendID);
216 sends[sendID] = receiveID;
229 for (
label procID = 0; procID < nProcs; procID++)
231 collectReceives(procID, receives, allReceives[procID]);
237 for (
label procID = 0; procID < nProcs; procID++)
239 treeCommunication[procID] = commsStruct
244 receives[procID].shrink(),
245 allReceives[procID].shrink()
248 return treeCommunication;
254 const label parentIndex,
260 if (!freeComms_.empty())
262 index = freeComms_.pop();
267 index = parentCommunicator_.size();
269 myProcNo_.append(-1);
271 parentCommunicator_.append(-1);
278 Pout<<
"Communicators : Allocating communicator " << index <<
endl 279 <<
" parent : " << parentIndex <<
endl 280 <<
" procs : " << subRanks <<
endl 285 myProcNo_[index] = 0;
288 procIDs_[index].setSize(subRanks.
size());
289 forAll(procIDs_[index], i)
291 procIDs_[index][i] = subRanks[i];
294 if (i >= 1 && subRanks[i] <= subRanks[i-1])
297 <<
"subranks not sorted : " << subRanks
298 <<
" when allocating subcommunicator from parent " 303 parentCommunicator_[index] = parentIndex;
305 linearCommunication_[index] = calcLinearComm(procIDs_[index].size());
306 treeCommunication_[index] = calcTreeComm(procIDs_[index].size());
309 if (doPstream && parRun())
311 allocatePstreamCommunicator(parentIndex, index);
320 const label communicator,
326 Pout<<
"Communicators : Freeing communicator " << communicator <<
endl 327 <<
" parent : " << parentCommunicator_[communicator] <<
endl 328 <<
" myProcNo : " << myProcNo_[communicator] <<
endl 332 if (doPstream && parRun())
334 freePstreamCommunicator(communicator);
336 myProcNo_[communicator] = -1;
338 parentCommunicator_[communicator] = -1;
339 linearCommunication_[communicator].clear();
340 treeCommunication_[communicator].clear();
342 freeComms_.push(communicator);
348 forAll(myProcNo_, communicator)
350 if (myProcNo_[communicator] != -1)
352 freeCommunicator(communicator, doPstream);
360 int procID = myProcID;
363 while (parent(comm) != -1)
366 procID = parentRanks[procID];
376 const List<int>& parentRanks = procID(myComm);
377 label parentComm = parent(myComm);
379 if (parentComm == -1)
381 return findIndex(parentRanks, baseProcID);
385 label parentRank = procNo(parentComm, baseProcID);
386 return findIndex(parentRanks, parentRank);
394 const label currentComm,
395 const int currentProcID
399 return procNo(myComm, physProcID);
405 bool Foam::UPstream::parRun_(
false);
407 bool Foam::UPstream::haveThreads_(
false);
417 int Foam::UPstream::msgType_(1);
421 Foam::UPstream::linearCommunication_(10);
424 Foam::UPstream::treeCommunication_(10);
445 Foam::UPstream::floatTransfer
456 Foam::UPstream::nProcsSimpleSum
508 "nPollProcInterfaces",
510 Foam::UPstream::nPollProcInterfaces
A LIFO stack based on a singly-linked list.
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
Abstract base class for registered object with I/O. Used in debug symbol registration.
#define forAll(list, i)
Loop across all elements in list.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
addcommsTypeToOpt addcommsTypeToOpt_("commsType")
errorManipArg< error, int > exit(error &err, const int errNo=1)
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
Foam::UPstream::communicator serialComm(-1, Foam::labelList(1, Foam::label(0)), false)
commsTypes
Types of communications.
A 1D array of objects of type <T>, where the size of the vector is known and used for subscript bound...
An Istream is an abstract base class for all input systems (streams, files, token lists etc)...
void size(const label)
Override size to be inconsistent with allocated storage.
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
Ostream & endl(Ostream &os)
Add newline and flush stream.
int optimisationSwitch(const char *name, const int defaultValue=0)
Lookup optimisation switch or add default value.
static label procNo(const label comm, const int baseProcID)
Return processor number in communicator (given physical processor.
labelList identity(const label len)
Create identity map (map[i] == i) of given length.
static label worldComm
Default communicator (all processors)
Initialise the NamedEnum HashTable from the static list of names.
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
static void freeCommunicators(const bool doPstream)
Free all communicators.
const string & prefix() const
Return the prefix of the stream.
static int nPollProcInterfaces
Number of polling cycles in processor updates.
static label parent(const label communicator)
virtual void writeData(Foam::Ostream &os) const
Write.
virtual void readData(Foam::Istream &is)
Read.
void append(const T &)
Append an element at the end of the list.
DynamicList< T, SizeInc, SizeMult, SizeDiv > & append(const T &)
Append an element at the end of the list.
List< label > labelList
A List of labels.
registerOptSwitch("floatTransfer", bool, Foam::UPstream::floatTransfer)
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
errorManip< error > abort(error &err)
An Ostream is an abstract base class for all output systems (streams, files, token lists...
static int baseProcNo(const label myComm, const int procID)
Return physical processor number (i.e. processor number in.
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Perr(cerr, "Perr")
static const NamedEnum< commsTypes, 3 > commsTypeNames
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
word name(const complex &)
Return a string representation of a complex.
Helper class for allocating/freeing communicators.
static commsTypes defaultCommsType
Default commsType.
prefixOSstream Pout(cout, "Pout")
Enum read(Istream &) const
Read a word from Istream and return the corresponding.
dictionary & optimisationSwitches()
The OptimisationSwitches sub-dictionary in the central controlDict.
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
void addOptimisationObject(const char *name, simpleRegIOobject *obj)
Register optimisation switch read/write object.
addcommsTypeToOpt(const char *name)
virtual ~addcommsTypeToOpt()
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
static List< int > & procID(label communicator)
Process ID of given process index.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
ITstream & lookup(const word &, bool recursive=false, bool patternMatch=true) const
Find and return an entry data stream.