next up previous contents
Next: A Complete Example Up: Processes and Arrays Previous: Parallel Programming   Contents


Locations

An HPJava range object can be thought of as a set of abstract locations. In our earlier example,

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

    ...
  }
the range x, for example, contains N locations. In an overall construct such as
    overall(i = x for 1 : N - 2) {
      ...
    }
the symbol i stands for a location, not simply an integer value. A location that is named by an overall construct is called a bound location.

With a few exceptions that will be discussed later, the subscript of a distributed array must be a bound location, and the location must be an element of the range associated with the array dimension. This is why we introduced the temporary arrays for neighbours in the stencil update example of the previous section. Arbitrary expressions are not usually legal subscripts for a distributed array. If we want to combine elements of arrays that are not precisely aligned, we first have to use a library function such as shift to align them2.6.

Figure 2.6 is an attempt to visualize the mapping of locations from x and y. We will write the locations of x as x[0], x[1], ..., x[N - 1]. Each location is mapped to a particular group of processes. Location x[1] is mapped to the three processes with coordinates $(0,0)$, $(0,1)$ and $(0,2)$. Location y[4] is mapped to the two processes with coordinates $(0,1)$ and $(1,1)$.

Figure 2.6: Mapping of x and y locations to the grid p.
\begin{figure*}\centerline{\psfig{figure=locations.eps,width=4in}}\end{figure*}

Besides overall, there is another control construct in HPJava that defines a bound location--the simpler at construct. Suppose we want to update or access a single element of a distributed array (rather than accessing a whole set of of elements in parallel). We cannot simply write something like

    float [[,]] a = new float [[x, y]] ;
    ...
    a [1, 4] = 73 ;
because 1 and 4 are not bound locations, and therefore not legal subscripts. We can write:
    float [[,]] a = new float [[x, y]] ;
    ...
    at(i = x [1])
      at(j = y [4])
        a [i, j] = 73 ;
Again the symbols i and j, scoped within the construct bodies, are bound locations.

The operational meaning of the at construct should be fairly clear. It is similar to the on construct. It restricts control to processes in the set that hold the specified location. Referring again to Figure 2.6, the outer

    at(i = x [1])
construct limits execution of its body to processes with coordinates $(0,0)$, $(0,1)$ and $(0,2)$. The inner
    at(j = y [4])
restricts execution further to just process $(0,1)$. This is exactly the process that owns element a[1,4]. The odd restriction that subscripts must be bound locations helps ensure that processes only manipulate array elements stored locally. If a process has to access non-local data, some explicit library call is needed to fetch it.

An operational definition of overall can be given in terms of the simpler at construct. The construct

    overall(i = x for l : u : s) {
      ...
    }
is equivalent in behaviour to
    for(int n = l; n <= u ; n += s)
      at(i = x [n]) {
        ...
      }
The body of the at construct is skipped for values of n that don't correspond to locally held elements. In practise an HPJava compiler can translate the overall construct much more efficiently than this definition suggests.

The at construct completes the contingent of new control constructs in HPJava. We sometimes refer to the three constructs on, at and overall as distributed control constructs, and sometimes, more grandiosely, as structured SPMD control constructs.

The backquote symbol, `, can be used as a postfix operator on a bound location, thus:

    i`
This expression evaluates to the integer global index value. In the operational definition of the overall given above, this is the value called n.

We now know enough about HPJava to write some complete examples.


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