HPJava adds class libraries and some additional syntax for dealing with distributed arrays. Some or all of the dimensions of a these arrays can be declared as distributed ranges. A distributed range defines a range of integer subscripts, and specifies how they are mapped into a process grid dimension. It is represented by an object of base class Range.
Process grids--equivalent to processor arrangements in HPF--are described by suitable classes. A base class Group describes a general group of processes and has subclasses Procs1, Procs2, ..., representing one-dimensional process grids, two-dimensional process grids, and so on. The inquiry function dim returns an object describing a particular dimension of a grid.
In the example
Procs2 p = new Procs2(3, 2) ; Range x = new BlockRange(100, p.dim(0)) ; Range y = new BlockRange(200, p.dim(1)) ; float [[#,#]] a = new float [[x, y]] on p ;
a is created as a 100 200 array, block-distributed over the 6 processes in p. The Range subclass BlockRange describes a simple block-distributed range of subscripts--analogous BLOCK distribution format in HPF. The arguments of the BlockRange constructor are the extent of the range and an object defining the process grid dimension over which the range is distributed. The fragment above is essentially equivalent to the HPF declarations
!HPF$ PROCESSORS p(3, 2) REAL a(100, 200) !HPF$ DISTRIBUTE a(BLOCK, BLOCK) ONTO p
In HPJava the type-signatures and constructors of distributed arrays use double brackets to distinguish them from ordinary Java arrays. If a particular dimension of an array has a distributed range, the corresponding slot in the type signature of the array should include a # symbol. In general the constructor of the distributed array must be followed by an on clause, specifying the process group over which the array is distributed (it defaults to the APG, see below). Distributed ranges of the array must be distributed over distinct dimensions of this group.
The language provides a library of functions for manipulating its arrays, closely analogous to the array transformational intrinsic functions of Fortran 90:
float [[#,#]] b = new float [[x, y]] on p ; HPJlib.shift(b, a, -1, 0, CYCL) ; float g = HPJlib.sum(b) ;
The shift operation with shift-mode CYCL executes a cyclic shift on the data in its second argument, copying the result to its first argument. The sum operation simply adds all elements of its argument array. In general these functions imply inter-processor communication.