How to copy variables across multiple locales in the Chapel

I'm wondering if there is an easy way to make a copy of a global variable in each locale so that then each locale can directly access its local copy instead of accessing the original variable stored in locale0?



source to share

1 answer

You can use to get a copy of a variable for each locale. To make it easier to use, there is a module . ReplicatedDist


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;

// Access the local complex component of the tuple

// Access a remote copy.
rcRemote(repVar, remoteLocale);




All Articles