The HPJava Project


HPJava Home Page
HPspmd lectures
mpiJava
HPJava language

PCRC Home Page

NPAC Home Page



Java Grande Home

Distributed arrays

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 array sections imported from Fortran 90, and their elements can be distributed over a group of processes.

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 primitive type. In any case, distributed arrays can appear as data members of objects and as elements of ordinary Java arrays.

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

The syntax for creating 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).

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 on 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 distinct dimensions of the group which the array as a whole is distributed over.

Here are some examples of distributed array declarations:

  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]]

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

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

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 grp and rng:

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

Next: Accessing array elements


Bryan Carpenter, (dbc@npac.syr.edu). Last updated January 2000.