I noticed something in a snippet of code I was given:
var D: domain(2) dmapped Block(boundingBox=Space) = Space;
var A: [D] int;
[a in A] a = a.locale.id;
For the most part, yes. In Chapel, [a in A] expr
can be thought of as a shorthand for forall a in A do expr
. However, there is a slight difference in that if A
does not support parallel iteration, the forall
form will generate a compile-time error whereas the [a in A]
form will fall back to serial iteration.
With respect to the title of this question, note that this behavior is independent of whether or not A
is distributed. For example, you could also write [i in 1..n]
rather than forall i in 1..n do
even though ranges like 1..n
are never distributed in Chapel.
Array types in Chapel, like [D] real
can similarly be read as "for all indices in D
, allocate an element of type real
."