Is `[ in ]` equivalent to `forall`?

后端 未结 1 1459
时光取名叫无心
时光取名叫无心 2021-01-19 09:40

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;


        
相关标签:
1条回答
  • 2021-01-19 10:07

    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."

    0 讨论(0)
提交回复
热议问题