RangeChunk¶
Usage
use RangeChunk;
or
import RangeChunk;
Utility routines for splitting a range into multiple chunks.
The RangeChunk
module assists with dividing a bounded range
of any idxType
and stride into numChunks
. Chunks are 0-based, with the 0
index chunk including
range.lowBound
and the numChunks - 1
index chunk including range.highBound
.
Chunks are accessible in several ways:
as a range, through an iterator
as a range, through a query
as a tuple of 0-based orders into the range, through an iterator
as a tuple of 0-based orders into the range, through a query
Given that it will be uncommon for the length of a given range
to be divisible by
numChunks
, there are three different remainder policies available, expressed
by the enum RemElems
.
- enum RemElems { Thru, Pack, Mod }¶
RemElems
specifies the distribution of remainder elements.- enum constant Thru¶
Default policy; remainder elements will be distributed throughout
numChunks
chunks
- enum constant Pack¶
Chunks at the front will receive
ceil(range.size / numChunks)
elements, then one chunk will receive what is left over; the actual number of chunks may be less thannumChunks
- enum constant Mod¶
In
numChunks
chunks, every chunk that has an index less thanrange.size % numChunks
will receive a remainder element
- iter chunks(r: range(?), numChunks: integral, remPol: RemElems = Thru)¶
Iterates through chunks
0
tonumChunks - 1
of ranger
, emitting each as a range. The remainders will be distributed according toremPol
.
- proc chunk(r: range(?), numChunks: integral, idx: integral, remPol: RemElems = Thru)¶
Returns the
idx
chunk of ranger
as a range. The remainders will be distributed according toremPol
.
- iter blockCyclicChunks(r: range(?), blockSize: integral, tid: integral, nTasks: integral)¶
- iter chunksOrder(r: range(?RT, boundKind.both, ?), numChunks: integral, remPol: RemElems = Thru) : 2*(RT)¶
Iterates through chunks
0
tonumChunks - 1
of ranger
, emitting each as a 0-based order tuple. The remainders will be distributed according toremPol
.
- proc chunkOrder(r: range(?RT, boundKind.both, ?), numChunks: integral, idx: integral, remPol: RemElems = Thru) : 2*(RT)¶
Returns the
idx
chunk of ranger
as a 0-based order tuple. The remainders will be distributed according toremPol
.