38 if (listOffsets.
size() > 1)
40 offsets_ = listOffsets;
50 offsets_(
std::move(listOffsets))
52 if (offsets_.
size() == 1)
61 const globalIndex::gatherNone,
71 const label localSize,
76 reset(localSize, comm, parallel);
83 const label localSize,
90 offsets_[1] = localSize;
97 const label localSize,
109 const label localSize,
129 const label len = (offsets_.size() - 1);
130 return (len < 1) || (*(offsets_.cdata() + len) == 0);
136 return (offsets_.size() == 2);
142 const label len = (offsets_.size() - 1);
143 return (len < 1) ? 0 : len;
149 return (end_value() - begin_value());
155 return (offsets_.empty() ? 0 : *(offsets_.cdata()));
161 const label len = (offsets_.size() - 1);
162 return (len < 1) ? 0 : *(offsets_.cdata() + len);
168 return (begin_value() <= i) && (i < end_value());
199 const label len = (offsets_.size() - 1);
207 const label len = (offsets_.size() - 2);
232 const label len = (offsets_.size() - 1);
242 return offsets_[proci];
254 return offsets_[proci+1];
266 return offsets_[proci+1] - offsets_[proci];
279 return maxNonLocalSize(-1);
291 return labelRange(offsets_[proci], offsets_[proci+1] - offsets_[proci]);
304 return (offsets_[proci] <= i) && (i < offsets_[proci+1]);
320 return i + offsets_[proci];
342 inplaceToGlobal(proci, result);
363 const label off = offsets_[proci];
365 for (label& val : labels)
387 if (i < offsets_[proci] || i >= offsets_[proci+1])
390 <<
"Global id:" << i <<
" does not belong on processor " 392 <<
" Offsets:" << offsets_
395 return (i - offsets_[proci]);
415 || (proci+1 > offsets_.size())
416 || (i < offsets_.front())
417 || (i >= offsets_.back())
427 if (isLocal(proci, i))
432 if (i < offsets_[proci])
440 return findLower(offsets_, i+1, proci+1);
454 || (proci+1 >= offsets_.size())
455 || (i < offsets_[proci+1])
456 || (i >= offsets_.back())
463 return findLower(offsets_, i+1, (proci+1));
476 || (proci >= offsets_.size())
477 || (i >= offsets_[proci])
497 label foundProc = findProc(proci, i);
502 <<
"Global id:" << i <<
" does not belong on any processor." <<
nl 503 <<
"Offsets:" << offsets_
523 const label localSize,
527 offsets_.resize_nocopy(2);
529 offsets_[1] = localSize;
536 const label localSize,
548 const label localSize,
570 this->offsets_ = rhs.offsets_;
598 return (*parent_).localStart(index_);
605 return (*parent_).localSize(index_);
612 return (*parent_).range(index_);
619 return this->
range();
662 Foam::globalIndex::const_iterator::
668 return (index_ == iter.index_);
673 Foam::globalIndex::const_iterator::
679 return (index_ != iter.index_);
716 const label len = this->length();
label toLocal(const label proci, const label i) const
From global to local on proci.
const_iterator(const globalIndex *globalIdx, const label i=0) noexcept
Construct from globalIndex list at given index.
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...
error FatalError
Error stream (stdout output on all processes), with additional 'FOAM FATAL ERROR' header text and sta...
#define FatalErrorInFunction
Report an error message using Foam::FatalError.
A range or interval of labels defined by a start and a size.
constexpr char nl
The newline '\n' character (0x0a)
label whichProcID(const label proci, const label i) const
Which processor does global id come from? Checks proci first (assumed to occur reasonably frequently)...
static List< T > listGatherValues(const T &localValue, const label communicator=worldComm)
Gather individual values into list locations.
Dispatch tag: Construct 'one-sided' from local sizes, using gather but no broadcast.
bool contains(const label i) const noexcept
True if contained within the offsets range.
label end_value() const noexcept
The value corresponding to the last offset (end offset), which is 1 beyond the end of the range...
label begin_value() const noexcept
The value corresponding to the first offset.
label span() const noexcept
The span size covered by the offsets, zero if empty.
SubList< label > subList
Declare type of subList.
static int myProcNo(const label communicator=worldComm)
Rank of this process in the communicator (starting from masterNo()). Can be negative if the process i...
static label worldComm
Communicator for all ranks. May differ from commGlobal() if local worlds are in use.
void inplaceToGlobal(const label proci, labelUList &labels) const
From local to global index on proci (inplace)
UList< label > labelUList
A UList of labels.
labelRange range() const
Return start/size range of local (myProcNo) data.
label findProcAbove(const label proci, const label i) const
Find processor above proci with specified global id - binary search.
label nProcs() const noexcept
The number of processors covered by the offsets, same as the primary length()
Various functions to operate on Lists.
globalIndex() noexcept=default
Default construct (empty)
const labelList & offsets() const noexcept
Const-access to the offsets.
bool single() const noexcept
True if local-only content (ie, nProcs == 1). Such content is often created with gatherNone.
Calculates a unique integer (label so might not have enough room - 2G max) for processor + local inde...
A List obtained as a section of another List.
label totalSize() const noexcept
The total addressed size, which corresponds to the end offset and also the sum of all localSizes...
Dispatch tag: Construct with a single (local size) entry, no communication.
Forward input iterator with const access that is used to iterate across the globalIndex offsets() tab...
const_iterator cbegin() const noexcept
A const_iterator set to the beginning.
const_iterator begin() const noexcept
A const_iterator set to the beginning.
void clear()
Clear the list, i.e. set size to zero.
label length() const noexcept
The number of items covered by the offsets.
label size() const
Global sum of localSizes. Same as totalSize()
labelRange range() const
The local range.
labelRange operator*() const
The local range.
bool isLocal(const label proci, const label i) const
Is on processor proci.
errorManip< error > abort(error &err)
label size() const
The local size.
labelList sizes() const
The local sizes. Same as localSizes()
label findProc(const label proci, const label i) const
Find processor with specified global id. Check proci first, followed by binary search.
constexpr auto cbegin(const C &c) -> decltype(c.begin())
Return const_iterator to the beginning of the container c.
const const_iterator end() const noexcept
A const_iterator set to beyond the end.
labelRange subProcs() const noexcept
Range of process indices for addressed sub-offsets (processes)
labelRange allProcs() const noexcept
Range of process indices for all addressed offsets (processes)
const_iterator & operator++()
label toGlobal(const label proci, const label i) const
From local to global on proci.
label findProcBelow(const label proci, const label i) const
Find processor below proci with specified global id - binary search.
label index() const noexcept
The index into the arrays.
static bool master(const label communicator=worldComm)
True if process corresponds to the master rank in the communicator.
static const UList< label > & null() noexcept
Return a null UList (reference to a nullObject). Behaves like an empty UList.
bool empty() const noexcept
Check for default constructed or total-size == 0.
label localStart() const
Local start on myProcNo()
const const_iterator cend() const noexcept
A const_iterator set to beyond the end.
List< label > labelList
A List of labels.
label start() const
The local start.
const_iterator & operator--()
label maxSize() const
Global max of localSizes.
void clear()
Reset to be empty (no offsets)
label localEnd() const
Local end on myProcNo()
Dispatch tag: Construct 'one-sided' from the non-master local sizes using gather but no broadcast...
label maxNonLocalSize() const
The max of localSizes, excluding current (myProcNo) rank.
label localSize() const
Local size on myProcNo()
const labelUList localStarts() const
The local starts.