53 void Foam::UPstream::setParRun(
const label nProcs,
const bool haveThreads)
65 <<
"problem : comm:" << comm
85 <<
"problem : comm:" << comm
101 List<commsStruct> linearCommunication(nProcs);
110 linearCommunication[0] = commsStruct
120 for (
label procID = 1; procID < nProcs; procID++)
122 linearCommunication[procID] = commsStruct
131 return linearCommunication;
135 void Foam::UPstream::collectReceives
138 const List<DynamicList<label>>& receives,
139 DynamicList<label>& allReceives
144 const DynamicList<label>& myChildren = receives[procID];
146 forAll(myChildren, childI)
148 allReceives.append(myChildren[childI]);
149 collectReceives(myChildren[childI], receives, allReceives);
187 while ((1 << nLevels) < nProcs)
192 List<DynamicList<label>> receives(nProcs);
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;
223 List<DynamicList<label>> allReceives(nProcs);
224 for (
label procID = 0; procID < nProcs; procID++)
226 collectReceives(procID, receives, allReceives[procID]);
230 List<commsStruct> treeCommunication(nProcs);
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 procIndices_[index].setSize(subRanks.
size());
284 forAll(procIndices_[index], i)
286 procIndices_[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(procIndices_[index].size());
301 treeCommunication_[index] = calcTreeComm(procIndices_[index].size());
304 if (doPstream && parRun())
306 allocatePstreamCommunicator(parentIndex, index);
327 if (doPstream && parRun())
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);
Useful combination of include files which define Sin, Sout and Serr and the use of IO streams general...
Foam::UPstream::communicator serialComm(-1, Foam::labelList(1, Foam::label(0)), false)
#define forAll(list, i)
Loop across all elements in list.
A LIFO stack based on a singly-linked list.
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.
Initialise the NamedEnum HashTable from the static list of names.
Helper class for allocating/freeing communicators.
Inter-processor communications stream.
static bool haveThreads()
Have support for threads.
commsTypes
Types of communications.
static label warnComm
Debugging: warn for use of any communicator differing from warnComm.
static void freeCommunicators(const bool doPstream)
Free all communicators.
static void freeCommunicator(const label communicator, const bool doPstream=true)
Free a previously allocated communicator.
static bool floatTransfer
Should compact transfer be used in which floats replace doubles.
static List< int > & procID(label communicator)
Process ID of given process index.
static const NamedEnum< commsTypes, 3 > commsTypeNames
static label worldComm
Default communicator (all processors)
static label parent(const label communicator)
static int nProcsSimpleSum
Number of processors at which the sum algorithm changes from linear.
static int nPollProcInterfaces
Number of polling cycles in processor updates.
static label nProcs(const label communicator=0)
Number of processes in parallel run.
static label allocateCommunicator(const label parent, const labelList &subRanks, const bool doPstream=true)
Allocate a new communicator.
static label procNo(const label comm, const int baseProcID)
Return processor number in communicator (given physical processor.
static commsTypes defaultCommsType
Default commsType.
static int myProcNo(const label communicator=0)
Number of this process (starting from masterNo() = 0)
static int baseProcNo(const label myComm, const int procID)
Return physical processor number (i.e. processor number in.
const string & prefix() const
Return the prefix of the stream.
#define FatalErrorIn(functionName)
Report an error message using Foam::FatalError.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
int optimisationSwitch(const char *name, const int defaultValue=0)
Lookup optimisation switch or add default value.
Enum namedEnumOptimisationSwitch(const char *name, const NamedEnum< Enum, nEnum > &enumNames, const Enum defaultValue)
Lookup optimisation switch or add default value.
errorManipArg< error, int > exit(error &err, const int errNo=1)
prefixOSstream Perr(cerr, "Perr")
List< label > labelList
A List of labels.
intWM_LABEL_SIZE_t label
A label is an int32_t or int64_t as specified by the pre-processor macro WM_LABEL_SIZE.
Ostream & endl(Ostream &os)
Add newline and flush stream.
word name(const bool)
Return a word representation of a bool.
errorManip< error > abort(error &err)
defineTypeNameAndDebug(combustionModel, 0)
prefixOSstream Pout(cout, "Pout")
label findIndex(const ListType &, typename ListType::const_reference, const label start=0)
Find first occurrence of given element and return index,.
labelList identityMap(const label len)
Create identity map (map[i] == i) of given length.
void offset(label &lst, const label o)