Array of distributed arrays?

I apologize in advance if this question is "basic."

I would like to construct a 1-D collection (array or tuple) A whose elements A[i] are 2-D arrays with different distributed domains, i.e., having different shapes and different distributions.

At a minimum, it seems I need a wrapper record or class for the 2-D arrays, but I am not sure how to declare the type of the “inner” (element) domain so that each element can have a different distributed domain.

That is, here is a sketch of what I suspect I need; how do I fill in the hole?

config param N = 3;

record InnerArray2D {
    var dom: domain(2); /* HOLE: This declaration is close
                           to what I want, but I need `dom`
                           to be distributed. */
    var vals: [dom] real;

var A: [1..N] InnerArray2D;

// ... Construct each `A[i]` accordingly ...

Hello Richard,

If you know at compile time how many elements your collection A has and what their distributions are, then putting them together in a tuple is an easier solution. For example:

var A = (
  makeArray({1..3, 2..4} dmapped Block(...)),
  makeArray({2..5, 3..6} dmapped Cyclic(...)),
  makeArray({4..7, 5..8}), // can have non-distributed arrays, too

proc makeArray(dom) {
  var result: [dom] real;
  return result;

Note that I skipped the wrapper record. You can add it if desired and have makeArray return a new instance of that record. The record needs to be generic, for example:

// if storing the domain
record InnerArray1 {
  var dom: domain;
  var vals: [dom] real;

// if you do not need to store the domain explicitly
record InnerArray2 {
  var vals;

If you need runtime variability in the types of distributions or something else, you can use Arkouda's SymEntry trick, see arkouda/MultiTypeSymEntry.chpl at master · Bears-R-Us/arkouda · GitHub

  • The element type of your array A is a concrete class type that knows nothing about the 2-D arrays, like Arkouda's GenSymEntry.

  • That concrete class has a child class that wraps the 2-D array and (optionally, if desired) its 2-D domain, like Arkouda's SymEntry. This child class is generic over the types of the array and the domain. All methods involving the arrays go in this class.

I can flesh out this approach some more if it is of interest to you.

Please let us know how this works for you!


1 Like

P.S. If you choose the Tuple way, you will need to iterate over A using a param loop. Meaning that it will be fully unrolled in the generated code. This may or may not be an issue in your case.