barrymoo
barrymoo

Reputation: 140

Can one create an object to store multiple domains?

I have some code which I think should look like:

on Locales[0] {
  var slice: domain(1) = {0..#widthOfLocaleMatrix};
  on Locales[1] {
    slice(0) = A.localSubdomain();
  }
  var localSlice: [slice(0)] int = A[slice(0)];
}

Basically, I am trying to fetch multiple slices of data from the other numLocales - 1 locales. Can I create an object to store the localSubdomain's from all other locales? I think I can work around this, but I was curious.

Upvotes: 1

Views: 150

Answers (1)

Brad
Brad

Reputation: 4053

To store multiple domains, you'll want to create an array of domains (or some other collection of domains). Specifically, the main problem with the code above is that it is seemingly trying to index into a domain ( slice(0) ) -- keep in mind that domains are merely index sets, not arrays/maps from indices to values.

The following sample program creates a distributed array ( A ) whose distribution we want to interrogate and an array of domains ( slicePerLocale ) that we'll use to keep track of who owns what. It populates slicePerLocale via the localSubdomain() query to determine the subdomain that each locale owns and stores that in the respective element of slicePerLocale. Finally, it prints out what it has learned:

use BlockDist;

config const n = 10;
var D = {1..n, 1..n} dmapped Block({1..n, 1..n});
var A: [D] real;

var slicePerLocale: [LocaleSpace] domain(2);

coforall loc    in Locales do
  on loc do
slicePerLocale[loc.id] = A.localSubdomain();

for (loc, slice) in zip(LocaleSpace, slicePerLocale) do
  writeln("locale ", loc, " owns: ", slice);

Running this on four locales with the default problem size of 10 results in:

locale 0 owns: {1..5, 1..5}
locale 1 owns: {1..5, 6..10}
locale 2 owns: {6..10, 1..5}
locale 3 owns: {6..10, 6..10}

Upvotes: 2

Related Questions