next up previous
Next: Compiling usage checks Up: Semantic Checking in HPJava Previous: Array sections

Variable usage rules

A basic principle of the HPspmd model is that a program can only directly reference locally held variables. Therefore we want to define the conditions under which it is legal to access a particular variable (most especially, a particular array element) at a particular point in a program.

In a distributed array element reference, as explained in section 2, a subscript in a distributed dimension of an array must be a bound location, and this location must be a location in the appropriate range of the array4. Hence

Rule 1   Subscripts in distributed array element references must be bound locations (unless the relevant dimension is sequential).


Rule 2   If a location appears as a subscript, it must be a location in the relevant range of the array.

The rules just stated go a long way towards ensuring that only local elements are accessed, but they don't cover all cases. Consider the example of Figure 6. The subscripts on the element reference c[j] are legal--j is a location in c.rng(0) (which is equal to y). But, referring to Figure 5, the section c is localized to p/x[0]--the top row of processes in the figure--whereas the on construct specifies that the element assignments are performed in the group p/x[7]--the bottom row of processes.

Figure 6: Erroneous access to non-local elements of a section
\begin{figure*}\small\begin{verbatim}Procs2 p = new Procs2(P, P) ;Range x ...
...erall(j = y for :)
c [j] = j\lq  ; // error!\end{verbatim}\normalsize\end{figure*}

Before we can give a general rule about accesses to elements of distributed arrays we need to refine the concept of the active process group. Suppose the set of processes currently executing the program text is represented by the group $q$, and the construct

    on($p$) $S$
appears. For the body, $S$, the active process group is changed to $p$. The group $p$ must represent a subset of the processes in $q$. Similarly, suppose the current active process group is $q$, and the construct

    overall($i$ = $x$ for $l$ : $u$ : $s$) $S$
appears. For $S$ the active process group is changed to $q / i$. Unless $x$ is a collapsed range, the process dimension over which it is distributed must be a dimension of $q$.

Applied recursively these rules define the active process group at any point in a legal HPJava program.

Next we will define the home group of a program variable. The home group of an ordinary variable (not a distributed array element) is the group that was active at the point of declaration of the variable. For a distributed array element the rule is similar to the definition of distribution groups of section: suppose the subscripts in the reference

    $a$ [$e_0$, $e_1$, ...]
include locations $i, j, \ldots$, then the home group of the array element is5

    $a$.grp() / $i$ / $j$ / ...
(if the array has a replicated distribution this group may contain several processes; otherwise it contains a single process).

An HPspmd rule for accessing a variable can be stated as follows:

Rule 3   A variable can only be accessed when the active process group is contained in the home group of the variable.

This is essentially a statement that all processes executing the current text must hold a copy of any variable accessed. Strictly speaking it is slightly stronger than the requirement that the local process holds a copy of any element it accesses. The version given here is convenient for formal discussion of programs.

next up previous
Next: Compiling usage checks Up: Semantic Checking in HPJava Previous: Array sections
Bryan Carpenter 2002-07-11