HPJava distributed arrays

<h1>Distributed arrays</h1>

The distributed arrays of HPJava are built-in container classes
analogous to, but distinct from, the ordinary arrays of Java.  They are
true multidimensional arrays, they support an idea of <i>array
sections</i> imported from Fortran 90, and their elements can be
distributed over a group of processes.

<p>

In principle the elements of a distributed array can be arbitrary
objects, including arrays or even other distributed arrays.  To
simplify implementation, the initial HPJava compiler restricts the
elements of distributed arrays to be variables of <i>primitive</i>
type.  In any case, distributed arrays can appear as data members of
objects and as elements of ordinary Java arrays.

<p>

The <i>type signature</i> of a distributed array differs from the type
signature of an ordinary array in using double brackets, <tt>[[</tt> and
<tt>]]</tt>.  A double-bracket pair encloses one or more
comma-separated <i>slots</i>.  The number of these slots determines the
<i>rank</i> of the array.  The slots may be empty, or they may include
a single asterisk.  An asterisk indicates that the associated array
dimension is <i>sequential</i>, rather than distributed.

<p>

The syntax for <i>creating</i> a distributed array is modelled on
the corresponding syntax for ordinary arrays, but again it uses double
brackets enclosing comma-separated slots.  This time each slot contains
a range object (if the dimension is distributed) or an integer expression
(if the dimension is sequential).

<p>

Any distributed array is distributed over a specific process group.  By
default this is the current active process group, but this default can
be overridden by appending an <tt>on</tt> clause to the array
constructor, specifying some subset of the APG.  In any case, all
non-collapsed ranges appearing in the constructor brackets must be
distributed over <i>distinct</i> dimensions of the group which the array
as a whole is distributed over.

<p>

Here are some examples of distributed array declarations:
<font color=Blue>
<pre>
  Procs p = new Procs2(P, Q) ;

  Range x = new BlockRange(M, p.dim(0)) ;
  Range y = new CyclicRange(N, p.dim(0)) ;

  float [[,]] a = new float [[x, y]] on p ;

  on(p) {

    float [[,]] b = new float [[x, y]] ;

    double [[,*]] c = new double [[x, N]] ;

    int [[*,*]] d = new int [[M, N]]

    ...
  }
</pre>
</font>
At the point where <tt>a</tt> is declared <tt>p</tt> is not yet the
active process group, so it is necessary to add an explicit <tt>on</tt>
clause to the array constructor.  For the other array declarations the
distribution group is implicitly <tt>p</tt>.  Note that <tt>P</tt>,
<tt>Q</tt>, <tt>M</tt> and <tt>N</tt> should be coherent integer
variables.

<p>

Arrays <tt>a</tt> and <tt>b</tt> have essentially identical structure.
They are block-distributed in their first dimension and cyclically
distributed in their second.  Array <tt>c</tt> is block-distributed in
its first dimension but sequential in its second.  Implicitly
<tt>c</tt> is <i>replicated</i> over the second dimension of
<tt>p</tt>, because it has no range distributed over this process
dimension.  <i>Both</i> dimensions of <tt>d</tt> are sequential, and
the array is replicated over the whole of the active process group.

<p>

Groups, ranges and distributed arrays are objects, and like any
other object they can appear as data members of other objects and be
passed to or returned from member functions.  When an array is passed
to a member furnction, some limited information about the array is
picked up at compile-time from the type signature of the array - the
type of its elements, the rank of the array, and possibly a
specification that some of the dimensions are sequential.  Further
information about the structure of the array can be obtained at
runtime through the inquiries <tt>grp</tt> and <tt>rng</tt>:

<font color=Blue>
<pre>
  public interface Section {
    ...
    public Group grp() ;
    public Range rng(int r) ;
  }
</pre>
</font>

<tt>grp</tt> returns a <tt>Group</tt> object describing the process group
over which the array is distributed and <tt>rng(r)</tt> return a <tt>Range</tt>
object describing the <tt>r</tt>th range of the array.  <tt>r</tt> should
lie in the interval <tt>0,...,R-1</tt> where <tt>R</tt> is the rank
of the array.  Notice that <tt>Section</tt> is an interface that all
array types implement.  Certain polymorphic library functions such as
<tt>Adlib.remap</tt> have arguments of type <tt>Section</tt>.

<p>

<b>Next:</b>
<a href="locations.html">Accessing array elements</a>

