Next: Two-dimensional Fourier transform Up: Parallel Programming in HPJava Previous: Collapsed and Replicated Distributions   Contents

# Array Sections

HPJava has a mechanism for representing subarrays. This mechanism is modelled on the array sections of Fortran 90. In HPJava an array section expression has a similar syntax to a distributed array element reference but uses double brackets. Whereas an element reference is a variable, an array section is an expression that represents a new distributed array object. The new array contains a subset of the elements of the parent array. Those elements can subsequently be referenced--read or updated--either through the parent array or through the array section4.1.

We have seen that the subscripts in a distributed array element reference are either locations or (restrictedly) integer expressions. Options for subscripts in array section expressions are wider. Most importantly, as in Fortran 90, a section subscript is allowed be a triplet. Triplets were introduced in section 2.3 in the context of the overall construct. For each triplet subscript a section expression has an array dimension. In the commonest kinds of array section expression the rank of the result is equal to the number of triplet subscripts. The section may also have some scalar subscripts, similar to those appearing in element references. In this case the rank of the result will be lower than the rank of the parent array.

This fragment includes two examples of array section expressions:

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

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

float [[]] b = a [[0, :]]

foo(a [[0 : N / 2 - 1, : : 2]]) ;
}

The first array section expression appears on the right hand side of the definition of b. It specifies b as an alias for the first row of a (Figure 4.1). Note that a scalar subscript in an array section expression is allowed to be an integer expression, even if the array dimension is distributed. This contrasts with element references, where they must be bound locations. The second array section expression appears as an argument to the method foo. It represents a two-dimensional, by , subset of the elements of a, visualized in Figure 4.2. The lower and upper bounds are omitted in the second triplet subscript of this expression: as usual, they default 0 and .

Array sections allow us to implement a number of interesting applications. They are often passed as arguments to library functions like remap, implementing various interesting patterns of communication and arithmetic on subarrays.

Subsections

Next: Two-dimensional Fourier transform Up: Parallel Programming in HPJava Previous: Collapsed and Replicated Distributions   Contents
Bryan Carpenter 2002-07-12