53 void Foam::UPstream::setParRun(
const label nProcs,
const bool haveThreads)
58 haveThreads_ = haveThreads;
65 <<
"problem : comm:" << comm
76 haveThreads_ = haveThreads;
81 label comm = allocateCommunicator(-1,
identity(nProcs),
true);
85 <<
"problem : comm:" << comm
110 linearCommunication[0] = commsStruct
120 for (
label procID = 1; procID < nProcs; procID++)
122 linearCommunication[procID] = commsStruct
131 return linearCommunication;
135 void Foam::UPstream::collectReceives
146 forAll(myChildren, childI)
148 allReceives.
append(myChildren[childI]);
149 collectReceives(myChildren[childI], receives, allReceives);
187 while ((1 << nLevels) < nProcs)
198 label childOffset = offset/2;
200 for (
label level = 0; level < nLevels; level++)
203 while (receiveID < nProcs)
206 label sendID = receiveID + childOffset;
210 receives[receiveID].
append(sendID);
211 sends[sendID] = receiveID;
224 for (
label procID = 0; procID < nProcs; procID++)
226 collectReceives(procID, receives, allReceives[procID]);
232 for (
label procID = 0; procID < nProcs; procID++)
234 treeCommunication[procID] = commsStruct
239 receives[procID].shrink(),
240 allReceives[procID].shrink()
243 return treeCommunication;
249 const label parentIndex,
255 if (!freeComms_.empty())
257 index = freeComms_.pop();
262 index = parentCommunicator_.size();
264 myProcNo_.append(-1);
266 parentCommunicator_.append(-1);
273 Pout<<
"Communicators : Allocating communicator " << index <<
endl 274 <<
" parent : " << parentIndex <<
endl 275 <<
" procs : " << subRanks <<
endl 280 myProcNo_[index] = 0;
283 procIDs_[index].setSize(subRanks.
size());
284 forAll(procIDs_[index], i)
286 procIDs_[index][i] = subRanks[i];
289 if (i >= 1 && subRanks[i] <= subRanks[i-1])
292 <<
"subranks not sorted : " << subRanks
293 <<
" when allocating subcommunicator from parent " 298 parentCommunicator_[index] = parentIndex;
300 linearCommunication_[index] = calcLinearComm(procIDs_[index].size());
301 treeCommunication_[index] = calcTreeComm(procIDs_[index].size());
304 if (doPstream && parRun())
306 allocatePstreamCommunicator(parentIndex, index);
315 const label communicator,
321 Pout<<
"Communicators : Freeing communicator " << communicator <<
endl 322 <<
" parent : " << parentCommunicator_[communicator] <<
endl 323 <<
" myProcNo : " << myProcNo_[communicator] <<
endl 327 if (doPstream && parRun())
329 freePstreamCommunicator(communicator);
331 myProcNo_[communicator] = -1;
333 parentCommunicator_[communicator] = -1;
334 linearCommunication_[communicator].clear();
335 treeCommunication_[communicator].clear();
337 freeComms_.push(communicator);
343 forAll(myProcNo_, communicator)
345 if (myProcNo_[communicator] != -1)
347 freeCommunicator(communicator, doPstream);
355 int procID = myProcID;
358 while (parent(comm) != -1)
361 procID = parentRanks[procID];
371 const List<int>& parentRanks = procID(myComm);
372 label parentComm = parent(myComm);
374 if (parentComm == -1)
376 return findIndex(parentRanks, baseProcID);
380 label parentRank = procNo(parentComm, baseProcID);
381 return findIndex(parentRanks, parentRank);
389 const label currentComm,
390 const int currentProcID
394 return procNo(myComm, physProcID);
400 bool Foam::UPstream::parRun_(
false);
402 bool Foam::UPstream::haveThreads_(
false);
412 int Foam::UPstream::msgType_(1);
416 Foam::UPstream::linearCommunication_(10);
419 Foam::UPstream::treeCommunication_(10);
A LIFO stack based on a singly-linked list.
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
#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.
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...
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)
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.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
errorManip< error > abort(error &err)
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 namedEnumOptimisationSwitch(const char *name, const NamedEnum< Enum, nEnum > &enumNames, const Enum defaultValue)
Lookup optimisation switch or add default value.
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
#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.