我想知道是否有一种简单的方法可以在每个语言环境中复制一个全局变量,以便以后每个语言环境可以直接访问其本地副本而不是访问存储在locale0中的原始变量?
谢谢
答案 0 :(得分:3)
您可以使用ReplicatedDist
发行版获取每个区域设置的变量副本。有一个模块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);