34Foam::globalIndex::range_impl(label proci)
const noexcept
38 const auto len = (offsets_.size() - 1);
39 (len > 0 && proci >= 0 && proci < len)
42 const auto* off = offsets_.cdata();
43 return { off[proci], (off[proci+1] - off[proci]) };
53Foam::globalIndex::slice_impl(label proci)
const noexcept
57 const auto len = (offsets_.size() - 1);
58 (len > 0 && proci >= 0 && proci < len)
61 const auto* off = offsets_.cdata();
62 return { off[proci], (off[proci+1] - off[proci]), off[len] };
73inline void Foam::globalIndex::checkOverflowAndExit
76 const label prevOffset,
80 if (prevOffset >= 0 && count >= 0)
82 if (label next = (prevOffset + count); next < prevOffset)
84 reportOverflowAndExit(idx, prevOffset, count);
97 if (listOffsets.size() > 1)
99 offsets_ = listOffsets;
109 offsets_(std::move(listOffsets))
111 if (offsets_.size() == 1)
182 const label len = (offsets_.size() - 1);
183 return (len < 1) || (*(offsets_.cdata() + len) == 0);
189 return (offsets_.size() == 2);
195 const label len = (offsets_.size() - 1);
196 return (len < 1) ? 0 : len;
208 return (offsets_.empty() ? 0 : *(offsets_.cdata()));
214 const label len = (offsets_.size() - 1);
215 return (len < 1) ? 0 : *(offsets_.cdata() + len);
246 const label len = (offsets_.size() - 1);
254 const label len = (offsets_.size() - 2);
279 if (
const label len = (offsets_.size() - 1); len > 0)
292 return offsets_[proci];
304 return offsets_[proci+1];
316 return offsets_[proci+1] - offsets_[proci];
341 return range_impl(proci);
354 return slice_impl(proci);
368 return (offsets_[proci] <= i) && (i < offsets_[proci+1]);
384 return i + offsets_[proci];
427 if (
const auto beg = offsets_[proci]; beg)
429 for (
auto& val : labels)
447 if (i < offsets_[proci] || i >= offsets_[proci+1])
450 <<
"Global id:" << i <<
" does not belong on processor "
452 <<
" Offsets:" << offsets_
455 return (i - offsets_[proci]);
475 || (proci+1 > offsets_.size())
476 || (i < offsets_.front())
477 || (i >= offsets_.back())
487 if (isLocal(proci, i))
492 if (i < offsets_[proci])
500 return findLower(offsets_, i+1, proci+1);
514 || (proci+1 >= offsets_.size())
515 || (i < offsets_[proci+1])
516 || (i >= offsets_.back())
523 return findLower(offsets_, i+1, (proci+1));
536 || (proci >= offsets_.size())
537 || (i >= offsets_[proci])
557 label foundProc = findProc(proci, i);
562 <<
"Global id:" << i <<
" does not belong on any processor." <<
nl
563 <<
"Offsets:" << offsets_
587 offsets_.resize_nocopy(2);
624 this->offsets_ =
rhs.offsets_;
652 return (*parent_).localStart(index_);
659 return (*parent_).localSize(index_);
666 return (*parent_).range(index_);
673 return this->
range();
716Foam::globalIndex::const_iterator::
722 return (index_ == iter.index_);
727Foam::globalIndex::const_iterator::
733 return (index_ != iter.index_);
770 const label len = this->
length();
778 return this->cbegin(i);
Various functions to operate on Lists.
A tuple of integers comprising start, size, total.
static const UList< label > & null() noexcept
void size(const label n)
Older name for setAddressableSize.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Negative if the process is not a...
static List< T > listGatherValues(const T &localValue, const int communicator=UPstream::worldComm)
Gather individual values into list locations.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
Forward input iterator with const access that is used to iterate across the globalIndex offsets() tab...
const_iterator & operator--()
const_iterator & operator++()
labelRange operator*() const
The local range.
labelRange range() const
The local range.
label size() const
The local size.
label index() const noexcept
The index into the arrays.
const_iterator(const globalIndex *globalIdx, const label i=0) noexcept
Construct from globalIndex list at given index.
label start() const
The local start.
Calculates a non-overlapping list of offsets based on an input size (eg, number of cells) from differ...
globalIndex() noexcept=default
Default construct (empty).
bool single() const noexcept
True if local-only content (ie, nProcs == 1). Such content is often created with gatherNone.
label localEnd(const label proci) const
End of proci data.
const const_iterator end() const noexcept
A const_iterator set to beyond the end.
label maxSize() const
Global max of localSizes.
label totalSize() const noexcept
The total addressed size, which corresponds to the end offset and also the sum of all localSizes.
label localSize() const
Local size on myProcNo().
const_iterator cbegin() const noexcept
A const_iterator set to the beginning.
const const_iterator cend() const noexcept
A const_iterator set to beyond the end.
bool empty() const noexcept
Check for default constructed or total-size == 0.
labelRange range() const
Return start/size range of local (myProcNo) data.
label findProcBelow(const label proci, const label i) const
Find processor below proci with specified global id - binary search.
label toLocal(const label proci, const label i) const
From global to local on proci.
label maxNonLocalSize(const label proci) const
The max of localSizes, excluding the specified processor.
OffsetRange< label > slice(label proci) const noexcept
Return start/size/total slab addressing for proci data.
label span() const noexcept
The span size covered by the offsets, zero if empty.
label localStart() const
Local start on myProcNo().
label findProc(const label proci, const label i) const
Find processor with specified global id. Check proci first, followed by binary search.
label nProcs() const noexcept
The number of processors covered by the offsets, same as the primary length().
void inplaceToGlobal(const label proci, labelUList &labels) const
From local to global index on proci (inplace).
labelList localSizes() const
The local sizes.
const labelUList localStarts() const
The local starts.
label end_value() const noexcept
The value corresponding to the last offset (end offset), which is 1 beyond the end of the range.
label length() const noexcept
The number of items covered by the offsets.
labelRange subProcs() const noexcept
Range of process indices for addressed sub-offsets (processes).
label maxNonLocalSize() const
The max of localSizes, excluding current (myProcNo) rank.
label whichProcID(const label proci, const label i) const
Which processor does global id come from? Checks proci first (assumed to occur reasonably frequently)...
OffsetRange< label > slice() const
Return start/size/total slab addressing for local (myProcNo) data.
bool isLocal(const label proci, const label i) const
Is on processor proci.
bool contains(const label i) const noexcept
True if contained within the offsets range.
labelList sizes() const
The local sizes. Same as localSizes().
label toGlobal(const label proci, const label i) const
From local to global on proci.
label localStart(const label proci) const
Start of proci data.
labelRange allProcs() const noexcept
Range of process indices for all addressed offsets (processes).
void clear()
Reset to be empty (no offsets).
label localEnd() const
Local end on myProcNo().
const_iterator begin() const noexcept
A const_iterator set to the beginning.
void reset(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.
label localSize(const label proci) const
Size of proci data.
label begin_value() const noexcept
The value corresponding to the first offset.
const labelList & offsets() const noexcept
Const-access to the offsets.
label findProcAbove(const label proci, const label i) const
Find processor above proci with specified global id - binary search.
A range or interval of labels defined by a start and a size.
limits reset(1/(limits.max()+VSMALL), 1/(limits.min()+VSMALL))
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
List< label > labelList
A List of labels.
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.
errorManip< error > abort(error &err)
void rhs(fvMatrix< typename Expr::value_type > &m, const Expr &expression)
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
UList< label > labelUList
A UList of labels.
constexpr char nl
The newline '\n' character (0x0a).
Dispatch tag: Construct 'one-sided' from the non-master local sizes using gather but no broadcast.
Dispatch tag: Construct with a single (local size) entry, no communication.
Dispatch tag: Construct 'one-sided' from local sizes, using gather but no broadcast.