我想知道是否有一种简单的方法可以在每个区域设置上制作全局变量的副本,以便以后每个区域设置都可以直接访问其本地副本,而不是访问存储在 locale0 中的原始变量?
谢谢
最佳答案
您可以使用 ReplicatedDist
distribution 以获取每个语言环境的变量副本。有一个模块 UtilReplicatedVar
以简化其使用。
use UtilReplicatedVar;
var regularInt = 42;
// rcDomain is declared in UtilReplicatedVar. It maps
// one int value to each locale
var repInt: [rcDomain] int;
// Other types can be replicated as well. Here a
// heterogeneous tuple containing an integer,
// real, and complex is replicated
var repTuple: [rcDomain] (int, real, complex);
// Assign 42 to the replicated int on all locales
rcReplicate(repVar, regularInt);
// Access the local copy of the replicated var.
// The first form must use 1 as the index.
repVar[1] = 0;
writeln(rcLocal(repVar));
// Access the local complex component of the tuple
writeln(repTuple[1](3));
// Access a remote copy.
rcRemote(repVar, remoteLocale);
关于replication - 如何在 Chapel 的多个语言环境中复制变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45575091/