I didn't find how the domain map maps the indices in the multi-dimensional domains to the multi-dimensional target locales.
1.) How the target locales (one dimension) is arranged in multi-dimension fashion which equals the distribution dimension to map the indexes?
2.) In documentation it states that for multi-dimension case, the computation should be done in every dimension. For the domain {1..8, 1..8}
==> dom
assume dom
is block-distributed over 6 target locales.
Steps in mapping
1 for 1st dimension (1..8) do the computation
if idx
is low<=idx<=high
then locid
is
floor (idx-low)*N / (high-low+1)
gives me an index say i
.
Repeat the same for 2nd dimension which gives me an index say j
.
Now I have a tuple ( i, j )
how this is mapped to the target locales array of dimension 2?
What the domain map do for changing the 1D target locales array to distribution dimension?
Is something like reshape function ?
Please let me know if this lacks sufficient information.
The specific details about how a domain's indices are mapped to a program's locales are not defined by the Chapel language itself, but rather by the implementation of the domain map used to declare the domain. In the comments under your question, you mention that you're referring to the
Block
distribution, so I'll focus on that in my answer (documented here), but note that any other domain map could take a different approach.The
Block
distribution takes an optionaltargetLocales
argument which permits you to specify the set of locales to be targeted, as well as their virtual topology. For instance, if I declare and populate a few arrays of locales:I can then pass them in as the
targetLocales
arguments to a few instances of aBlock
-distributed domain:Each domain will distribute its
n
rows to the first dimension of itstargetLocales
grid and itsn
columns to the second dimension. We can see the results of this distribution by declaring arrays of integers over these domains and assigning them in parallel to make each element store its owning locale's ID, as follows:When running on six or more locales (
./a.out -nl 6
), the output is as follows, revealing the underlying grid structure:For a 1-dimensional
targetLocales
array, the documentation says:For example, if we distribute to a 1-dimensional 4-element array of locales:
we can see that the target locales form a square, as expected:
The documentation is intentionally vague about how a 1D
targetLocales
argument will be reshaped if it's not a perfect square, but we can find out what's done in practice by using thetargetLocales()
query on the domain. Also, note that if notargetLocales
array is supplied, the entireLocales
array (which is 1D) is used by default. As an illustration of both these things, if the following code is run on six locales:we get:
illustrating that the current heuristic matches our explicit
grid1
declaration above.