next up previous contents
Next: Parallel Programming Up: Processes and Arrays Previous: Processes and Process Grids   Contents

Distributed Arrays

The biggest new feature HPJava adds to Java is the distributed array. Like the process grid objects introduced in the last section, a distributed array is logically an object shared by a number of processes. Like an ordinary array, a distributed array has some index space and stores a collection of elements of fixed type. Unlike an ordinary array, the index space and associated elements are scattered across the processes that share the array.

There are some superficial similarities between the way HPJava distributed arrays are used and the way ordinary Java arrays are used. There are also many differences. Apart from the fact that their elements are distributed in the manner just mentioned, the new HPJava arrays are true multi-dimensional arrays like those of Fortran (or, for that matter, C). As in Fortran, it is possible to form a regular section of an array. These characteristics of Fortran arrays have evolved to support scientific and parallel algorithms, and we consider them to be very desirable.

With these semantic distinctions in mind it is not particularly attractive to try and force the new HPJava arrays into a syntax closely reminiscent of ordinary Java arrays. Instead, HPJava distributed arrays look and feel quite different from standard arrays2.2. Of course HPJava includes Java as a subset, and ordinary Java arrays can and should be used freely in an HPJava program. But they have no very close relationship to the new distributed arrays. The distributed array types can be regarded as a series of specialized container classes, dressed up in a special syntax.

The type signatures and constructors of distributed arrays use double brackets to distinguish them from ordinary Java arrays. The distribution of the index space is parametrized by objects belonging to the second special class of HPJava: the Range class. In the following example we create a two-dimensional, N by N, array of floating point numbers, with elements distributed over the grid p.

  Procs2 p = new Procs2(2, 3) ;
  on(p) {
    Range x = new BlockRange(N, p.dim(0)) ;
    Range y = new BlockRange(N, p.dim(1)) ;

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

The decomposition of this array for the case N = 8 is illustrated in Figure 2.3. The choice of subclass BlockRange for the index ranges of the array mean that the index space of each array dimension is broken down into consecutive blocks. Other possible distribution formats will be discussed later. Notice how process dimensions are passed as arguments to the range constructors, specifying which dimensions the range is to be distributed over. Ranges of a single array must be distributed over different dimensions of the same process grid2.3.

Figure 2.3: A two-dimensional array distributed over p.

next up previous contents
Next: Parallel Programming Up: Processes and Arrays Previous: Processes and Process Grids   Contents
Bryan Carpenter 2002-07-12