3

我想知道有没有一种简单的方法可以在每个语言环境上制作一个全局变量的副本,以便以后每个语言环境都可以直接访问其本地副本,而不是访问存储在 locale0 中的原始变量?

谢谢

4

1 回答 1

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);
于 2017-08-08T20:04:01.770 回答