BlockDist¶
-
class
Block¶ This Block distribution partitions indices into blocks according to a
boundingBoxdomain and maps each entire block onto a locale from atargetLocalesarray.The indices inside the bounding box are partitioned "evenly" across the target locales. An index outside the bounding box is mapped to the same locale as the nearest index inside the bounding box.
Formally, an index
idxis mapped totargetLocales[locIdx], wherelocIdxis computed as follows.In the 1-dimensional case, for a Block distribution with:
boundingBox{low..high}targetLocales[0..N-1] localewe have:
if idxis ...locIdxis ...low<=idx<=highfloor( (idx-low)*N / (high-low+1) )idx < low0idx > highN-1In the multidimensional case,
idxandlocIdxare tuples of indices;boundingBoxandtargetLocalesare multi-dimensional; the above computation is applied in each dimension.Example
The following code declares a domain
Ddistributed over a Block distribution with a bounding box equal to the domainSpace, and declares an arrayAover that domain. The forall loop sets each array element to the ID of the locale to which it is mapped.use BlockDist; const Space = {1..8, 1..8}; const D: domain(2) dmapped Block(boundingBox=Space) = Space; var A: [D] int; forall a in A do a = a.locale.id; writeln(A);
When run on 6 locales, the output is:
0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 1 1 1 1 2 2 2 2 3 3 3 3 2 2 2 2 3 3 3 3 2 2 2 2 3 3 3 3 4 4 4 4 5 5 5 5 4 4 4 4 5 5 5 5
Constructor Arguments
The
Blockclass constructor is defined as follows:proc Block( boundingBox: domain, targetLocales: [] locale = Locales, dataParTasksPerLocale = // value of dataParTasksPerLocale config const, dataParIgnoreRunningTasks = // value of dataParIgnoreRunningTasks config const, dataParMinGranularity = // value of dataParMinGranularity config const, param rank = boundingBox.rank, type idxType = boundingBox.idxType)
The arguments
boundingBox(a domain) andtargetLocales(an array) define the mapping of any index ofidxTypetype to a locale as described above.The rank of
targetLocalesmust match the rank of the distribution, or be1. If the rank oftargetLocalesis1, a greedy heuristic is used to reshape the array of target locales so that it matches the rank of the distribution and each dimension contains an approximately equal number of indices.The arguments
dataParTasksPerLocale,dataParIgnoreRunningTasks, anddataParMinGranularityset the knobs that are used to control intra-locale data parallelism for Block-distributed domains and arrays in the same way that the like-named config constants control data parallelism for ranges and default-distributed domains and arrays.The
rankandidxTypearguments are inferred from theboundingBoxargument unless explicitly set. They must match the rank and index type of the domains "dmapped" using that Block instance.Data-Parallel Iteration
A forall loop over a Block-distributed domain or array executes each iteration on the locale where that iteration's index is mapped to.
Parallelism within each locale is guided by the values of
dataParTasksPerLocale,dataParIgnoreRunningTasks, anddataParMinGranularityof the respective Block instance. Updates to these values, if any, take effect only on the locale where the updates are made.