是`[<var>在 <distributed variable>]` 等价于 `forall`? [英] Is `[<var> in <distributed variable>]` equivalent to `forall`?

查看:29
本文介绍了是`[<var>在 <distributed variable>]` 等价于 `forall`?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在给定的一段代码中注意到了一些东西:

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;

[a in A] 是否等同于 forall a in A a = a.locale.id?

推荐答案

在大多数情况下,是的.在 Chapel 中,[a in A] expr 可以被认为是 forall a in A do expr 的简写.但是,有一点不同,如果 A 不支持并行迭代,forall 形式会产生编译时错误,而 [a in A] 表单将回退到串行迭代.

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.

关于此问题的标题,请注意此行为与 A 是否已分发无关.例如,您也可以编写 [i in 1..n] 而不是 forall i in 1..n do 即使范围像 1..n 永远不会在 Chapel 中分发.

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.

Chapel 中的数组类型,如 [D] real 可以类似地读作对于 D 中的所有索引,分配一个 real 类型的元素代码>."

Array types in Chapel, like [D] real can similarly be read as "for all indices in D, allocate an element of type real."

这篇关于是`[<var>在 <distributed variable>]` 等价于 `forall`?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆