Next: Low Level SPMD Programming
Up: The HPJava Language
Previous: More Distribution Formats
Contents
Array Sections
HPJava supports subarrays modeled on the array
sections of Fortran 90. The syntax of an array section is similar to
a multiarray element reference, but uses double brackets. Whereas an
element reference is a variable, an array section is an expression
that represents a new multiarray object. The new multiarray object
doesn't contain new elements. It contains a subset of the elements of
the parent array.
The options for subscripts in array sections are more flexible than
those in multiarrays. Most importantly, subscripts of an array
section may be triplets
as in Fortran 90. An array section
expression has an array dimension for each triplet subscript. So
the rank of an array section expression is equal to the number of
triplet subscripts. If an array section has some scalar subscripts
similar to those in element references, the rank of the array section
is lower than the parent array.
The following HPJava code contains the example of array section
expressions.
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 3.16). In an array section
expression, unlike in an array element reference, a scalar
subscript is always allowed to be an integer
expression
. The second array section
expression appears as an argument to the method foo. It
represents a two-dimensional,
, subset of the elements
of a, visualized in Figure 3.17.
Figure 3.16:
A one-dimensional section of a
two-dimensional array (shaded area).
|
|
Figure 3.17:
A two-dimensional section of a
two-dimensional array (shaded area).
|
|
What are the ranges of b from the above example? That is, what
does the rng() inquiry of b return? The ranges of an
array section are called subranges, as a matter of fact. These
are different from ranges considered so far. For the
completeness, the language has a special syntax for writing subranges
directly. Ranges identical to those of the argument of foo from
the above could be generated by
which look quite natural and similar to the subscripts for
location expressions. But, the subscript is a triplet. The global
indices related with the subrange v are in the range
. A subrange inherits locations from its parent range,
but it specifically does not inherit global indices from the parent range.
As triplet section subscripts motivated us to define subranges as a new
kind range, scalar section subscripts will drive us to define a new
kind of group. A restricted group is the subset of processes in
some parent group to which a specific location is mapped. From the
above example, the distribution group of b is the subset of
processes in p to which the location x[0] is mapped. In
order to represent the restricted group, the division operator is
overloaded. Thus, the distribution group of b is equal to
q as follws;
In a sense the definition of a restricted group is tacit in the
definition of an abstract location. In Figure 3.6
section the set of processes with coordinates
,
and
, to which location x[1] is mapped, can now be written
as
and the set with coordinates
and
, to which y[4]
is mapped, can be written as
The intersection of these two--the group containing the single
process with coordinates
--can be written as
or as
We didn't restrict that the subscripts in an array section expression
must include some triplets (or ranges). It is legitimate for
all the subscripts to be ``scalar''. In this case the resulting
``array'' has rank 0.
There is nothing pathological about rank-0 arrays. They logically
maintain a single element, bundled with the distribution group over
which this element is replicated. Because they are logically
multiarrays they can be passed as arguments to Adlib functions
such as remap. If a and b are
multiarrays, we cannot usually write a statement like
since the elements involved are generally held on different processors.
As we have seen, HPJava imposes constraints that forbid this kind of
direct assignment between array element references. However, if it is
really needed, we can usually achieve the same effect by writing
The arguments are rank-0 sections holding just the destination and
source elements.
The type signature for a rank-0 array with element of type
is
written 
[[]]
.
Rank-0 multiarrays, which we will also call simply ``scalars'',
can be created as follows:
This example illustrates one way to broadcast an element of a
multiarray: remap it to a scalar replicated over the active
process group. The element of the scalar is extracted through a
multiarray element reference with an empty subscript list.
(Like any other multiarray, scalar constructors can have
on clauses, specifying a non-default distribution group.)
Next: Low Level SPMD Programming
Up: The HPJava Language
Previous: More Distribution Formats
Contents
Bryan Carpenter
2004-06-09