如何在Chapel中的多个语言环境中复制变量

时间:2017-08-08 17:59:44

标签: replication hpc chapel

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

谢谢

1 个答案:

答案 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);