HPJava process groups

<h1>Process groups</h1>

The syntax extensions of HPJava depend on a two base classes that have
a special status in the language - the <tt>Group</tt> and
<tt>Range</tt> classes.  This section is concerned with groups.

<p>

A <i>group</i>, or <i>process group</i>, defines some subset of the
processes executing the SPMD program.  Groups have two important roles
in HPJava.  First are used to describe how program variables such as
arrays are distributed or replicated across the process pool.  Secondly
they are used to specify which subset of processes execute a particular
code fragment.

<p>

In HPJava groups are represented by objects of class <tt>Group</tt>.
There are several ways to create group objects.  The most common is to
use the constructor for one of the subclasses representing a <i>process
grid</i>.  The class hierarchy of groups and process grids is shown
below

<p>
<img src="procs.gif">
<p>

<tt>Procs1</tt> is a one-dimensional ``grid'' of processes,
<tt>Procs2</tt> is a two-dimensional grid, and so on.  As a special
case, <tt>Procs0</tt> is a group containing a single process.  The
constructors for these classes generally take a list of extents specifying
the shape of the grid.  In all cases, the constructor selects the
processes of the grid from the set of processes that collectively call
the constructor; if specified size of the grid is larger than this set
of processes, an exception occurs.

<p>

A straightforward use of grids was illustrated in a previous
section, where the elements of various arrays were distributed over
the processes in a grid.  Grids and groups have another important
role.  The language incorporates a formal idea of an <i>active process
group</i>.  At a typical point of execution in a program some group of
processes is sharing the current ``thread of control''.  This group is
engaged in ``loosely synchronous'' collective behaviour.  The
cooperating group is called the ``Active Process Group'' (APG).
There may be points of program execution where all processes are
performing quite independent tasks.  HPJava regards this as a
special case where all processes belong to active groups of one -
themselves.

<p>

The <tt>on</tt> construct seen in a previous section is an obvious
example of a program construct that affects the active process group.
Inside the construct <tt>on(p)</tt> (which can only appear when
<tt>p</tt> is a subset of the active process group) the APG is reduced
to <tt>p</tt>.  More subtly, the <tt>overall</tt> distributed loop
construct also affects the APG, breaking it into smaller, independently
operating groups.  This point will be discussed more in detail later.

<p>

We have seen how ranges and hence arrays can be divided over the
dimensions of a grid (``process dimensions'').  Groups and the APG have
another role in describing program variables.  They appear in the idea
of <i>coherence</i>.  An explicit example of coherence was given in the
matrix multiplication example.  It was mentioned that arrays like
<tt>a</tt> and <tt>b</tt> declared with replicated storage should be
initialized with identical values in each copy of the array.  The
elements of <tt>a</tt> and <tt>b</tt> are then <i>coherent
variables</i>.

<p>

Coherence is relevant to other variables besides array elements.  In
the matrix multiplication example, scalar expressions like <tt>P</tt>
and <tt>N</tt> should take the same value in every active process,
otherwise very odd behaviour can be expected.  Again this is an example
of coherence.  Without some idea of coherence it is difficult to write
a sensible SPMD program.

<p>

Coherence is sufficiently important that one might expect an SPMD
language to somehow enforce it.  HPJava does not attempt this
for a couple of reasons.  For one thing, there are various practical examples
where deliberate use of incoherent variables can be convenient.
For another, it may be difficult for the compiler to check
globally that variables are updated in a coherent way (unless some
very strict restrictions are placed on variable usage).  

<p>

Applied sufficiently rigorously, the following advisory rule will ensure
variables remain coherent: define the <i>home group</i> of a variable
(other than an array element) as the APG that was in effect when the
variable was created.  The general rule is that <em>a variable should only
be updated when the APG is equal to the home group of that variable</em>.
The home group of an array element will be defined later.

<p>

In principle coherence is a fragile thing.  Once any variable in the
program loses coherence, this lack of coherence can creep into other
variables.  In practice this is less of a problem than it sounds in
theory.  In a canonically written HPJava program the majority of
variables are likely to be coherent.

<p>

<b>Next:</b>
<a href="ranges.html">Ranges</a>

