34 void Foam::globalIndex::reportOverflowAndExit
37 const label prevOffset,
48 <<
"Overflow : sum of sizes exceeds labelMax (" 49 <<
labelMax <<
") after index " << idx;
51 if (prevOffset >= 0 &&
count >= 0)
54 <<
" while trying to add (" <<
count 55 <<
") to offset (" << prevOffset <<
")";
60 <<
"Please recompile with larger datatype for label." <<
nl 68 const label localSize,
70 const bool checkOverflow
86 const label len = counts.size();
90 for (label i = 0; i < len; ++i)
92 const label
count = counts[i];
96 myRange.start() = start;
99 const label prev = start;
104 reportOverflowAndExit(i, prev,
count);
119 for (label i = 0; i < myProci; ++i)
123 myRange.start() = start;
133 const label localSize,
135 const bool checkOverflow
151 const label len = counts.size();
155 for (label i = 0; i < len; ++i)
157 const label
count = counts[i];
163 const label prev = start;
168 reportOverflowAndExit(i, prev,
count);
183 for (label i = 0; i < myProci; ++i)
198 const bool checkOverflow
203 const label len = counts.
size();
210 for (label i = 0; i < len; ++i)
212 const label
count = counts[i];
216 if (checkOverflow && start <
values[i])
232 const bool checkOverflow
237 const label len = counts.
size();
244 for (label i = 0; i < len; ++i)
246 const label
count = counts[i];
253 && (start <
values[i].start())
257 reportOverflowAndExit(i,
values[i].start(),
count);
270 const label communicator,
271 const bool absoluteLocalNodeOffsets
277 interNodeOffsets.clear();
278 localNodeOffsets.clear();
287 interNodeOffsets.clear();
288 localNodeOffsets.clear();
299 interNodeOffsets.clear();
300 localNodeOffsets.clear();
315 allOffsets = offsets_;
328 interNodeOffsets.clear();
329 localNodeOffsets.clear();
334 const label firstProc = procIds[ranki];
335 const label lastProc =
337 (ranki+1 < procIds.size())
343 localNodeOffsets = allOffsets.slice
346 (lastProc - firstProc) + 1
349 if (!absoluteLocalNodeOffsets && !localNodeOffsets.empty())
351 const auto start0 = localNodeOffsets.front();
352 for (
auto& val : localNodeOffsets)
359 interNodeOffsets.resize_nocopy(procIds.size()+1);
363 interNodeOffsets[i] = allOffsets[procIds[i]];
365 interNodeOffsets.back() = allOffsets.back();
383 Foam::globalIndex::bin
388 DynamicList<label>& validBins
394 CompactListList<label> bins;
396 if (!globalIds.empty())
402 binValues = UIndirectList<label>(globalIds, order);
404 const label
id = binValues[0];
407 validBins.push_back(proci);
410 for (label i = 1; i < order.size(); i++)
412 const label
id = binValues[i];
414 if (
id < offsets[proci+1])
421 const label oldProci = proci;
425 for (label j = oldProci+1; j < proci; ++j)
427 binOffsets[j] = binOffsets[oldProci]+binSize;
429 binOffsets[proci] = i;
430 validBins.push_back(proci);
435 for (label j = proci+1; j < binOffsets.size(); ++j)
437 binOffsets[j] = binOffsets[proci]+binSize;
453 offsets_.resize(
n+1, end_value());
460 const label localSize,
482 counts[proci] = localSize;
498 const bool checkOverflow
501 const label len = counts.size();
505 offsets_.resize_nocopy(len+1);
508 for (label i = 0; i < len; ++i)
510 const label
count = counts[i];
514 if (checkOverflow && start < offsets_[i])
516 reportOverflowAndExit(i, offsets_[i],
count);
519 offsets_[len] = start;
530 if (proci >= 0 && proci+1 < offsets_.size() && len >= 0)
532 const label
delta = (len - (offsets_[proci+1] - offsets_[proci]));
537 for (label i = proci+1; i < offsets_.size(); ++i)
550 const label len = (offsets_.size() - 1);
559 for (label proci=0; proci < len; ++proci)
561 values[proci] = offsets_[proci+1] - offsets_[proci];
573 const label len = (offsets_.size() - 1);
582 for (label proci=0; proci < len; ++proci)
587 (offsets_[proci+1] - offsets_[proci])
597 const label len = (offsets_.size() - 1);
606 for (label i=0; i < len; ++i)
610 const label
count = (offsets_[i+1] - offsets_[i]);
623 (offsets_.size() < 2)
634 (offsets_.size() < 2)
640 offsets_[offsets_.size()-2],
641 offsets_[offsets_.size()-1]
658 return os << gi.offsets();
static labelList calcOffsets(const labelUList &counts, const bool checkOverflow=false)
Calculate offsets from a list of local sizes, with optional check for label overflow.
void reset(const label localSize, const label comm=UPstream::worldComm, const bool parallel=UPstream::parRun())
Reset from local size, using gather/broadcast with default/specified communicator if parallel...
void size(const label n)
Older name for setAddressableSize.
label findLower(const ListType &input, const T &val, const label start, const ComparePredicate &comp)
Binary search to find the index of the last element in a sorted list that is less than value...
errorManipArg< error, int > exit(error &err, const int errNo=1)
void resize(const label len)
Adjust allocated size of list.
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
List< labelRange > ranges() const
Return start/size ranges for all data.
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
labelList sortedOrder(const UList< T > &input)
Return the (stable) sort order for the list.
label max(const labelHashSet &set, label maxValue=labelMin)
Find the max value in labelHashSet, optionally limited by second argument.
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 List< labelRange > calcRanges(const labelUList &counts, const bool checkOverflow=false)
Calculate ranges (offset/size) from a list of local sizes, with optional check for label overflow...
static bool & parRun() noexcept
Test if this a parallel run.
static List< T > allGatherValues(const T &localValue, const int communicator=UPstream::worldComm)
Allgather individual values into list locations.
void resize_nocopy(const label len)
Adjust allocated size of list without necessarily.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
labelList localSizes() const
The local sizes.
UList< label > labelUList
A UList of labels.
globalIndex() noexcept=default
Default construct (empty)
#define forAll(list, i)
Loop across all elements in list.
const labelList & offsets() const noexcept
Const-access to the offsets.
List< T > values(const HashTable< T, Key, Hash > &tbl, const bool doSort=false)
List of values from HashTable, optionally sorted.
unsigned int count(const UList< bool > &bools, const bool val=true)
Count number of 'true' entries.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
static label nProcs(const label communicator=worldComm)
Number of ranks in parallel run (for given communicator). It is 1 for serial run. ...
static int commInterNode() noexcept
Communicator between nodes/hosts (respects any local worlds)
static bool is_rank(const label communicator=worldComm)
True if process corresponds to any rank (master or sub-rank) in the given communicator.
Istream & operator>>(Istream &, directionInfo &)
static int commConstWorld() noexcept
Communicator for all ranks (respecting any local worlds).
void setLocalSize(const label proci, const label len)
Alter local size for given processor.
#define FOAM_UNLIKELY(cond)
static bool is_parallel(const label communicator=worldComm)
True if parallel algorithm or exchange is required.
A packed storage of objects of type <T> using an offset table for access.
An Ostream is an abstract base class for all output systems (streams, files, token lists...
OBJstream os(runTime.globalPath()/outputName)
bool splitNodeOffsets(labelList &interNodeOffsets, labelList &localNodeOffsets, const label communicator=UPstream::worldComm, const bool absoluteLocalNodeOffsets=false) const
Split the top-level offsets into inter-node and local-node components suitable to a two-stage hierarc...
Ostream & operator<<(Ostream &, const boundaryPatch &p)
Write boundaryPatch as dictionary entries (without surrounding braces)
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static List< int > & procID(int communicator)
The list of ranks within a given communicator.
A class representing the concept of 0 (zero) that can be used to avoid manipulating objects known to ...
static labelRange calcRange(const label localSize, const label comm=UPstream::worldComm, const bool checkOverflow=false)
Calculate globally-consistent local range (offset/size) based on the local input size(s).
List< label > labelList
A List of labels.
labelRange back() const
The last offset range. It is (0,0) if globalIndex is empty.
static label calcOffset(const label localSize, const label comm=UPstream::worldComm, const bool checkOverflow=false)
Calculate globally-consistent local start offset based on the local input size(s).
static bool broadcast(Type *buffer, std::streamsize count, const int communicator)
Broadcast buffer contents (contiguous types), from rank=0 to all ranks. The sizes must match on all p...
label maxNonLocalSize() const
The max of localSizes, excluding current (myProcNo) rank.
void resize(const label n)
Change the number of entries (nProcs) in the offsets table. Extending will fill with empty local size...
labelRange front() const
The first offset range. It is (0,0) if globalIndex is empty.