next up previous contents index
Next: Distributed Arrays Up: Processes and Distributed Arrays Previous: HPspmd Classes   Contents   Index


Process Grids

So a parallel HPJava program starts concurrently in all members of some process set. From inside the HPJava program, the processes are organized and labelled through special objects representing process groups. In general the processes in an HPJava group are organized into multidimensional grids2.1.

Suppose a program is running concurrently on 6 or more processes. It may then define a 2 by 3 process grid as follows

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Procs2 p = new Procs2(2, 3) ;\end{verbatim}\end{minipage}\end{displaymath}

An instance of the class hpjava.lang.Procs2 describes a 2-dimensional grid of processes. The grid p is visualized in Figure 2.1. This figure assumes that the program was executed in 11 processes, e.g. by setting the hpjava.numprocs property to 11. The call to the Procs2 constructor selects 6 of the available processes and incorporates them into a grid. One could think of this, loosely, as an act of ``federation''. But actually members are selected from the available pool of processes by a simple-minded, deterministic procedure--the details don't matter here. A single program can introduce several grids, and a single process can belong to more than one grid.

Figure 2.1: The process grid represented by p. Circles represent processes. The white circles are the processes inside p.
\includegraphics[width=3in]{procs2.eps}

If a Procs2 constructor is invoked and the requested number of processes is greater than the number of processes the program is running on2.2, an hpjava.lang.ProcsArrayTooLargeException is thrown.

The Procs2 constructor is an example of a collective operation. It should be invoked concurrently by all members of the active process group. Perhaps it won't come as too much of a surprise that Procs2 is another example of an HPspmd class. The property of being an HPspmd class has implications beyond just ensuring that a main() method is started in multiple processes. Generally speaking, if a method or constructor is to be invoked in a collective way, it will be defined in a class that implements the HPspmd interface.

Procs2 is also a subclass of the special class hpjava.lang.Group. The Group class has a privileged status in the HPJava language. An object that inherits from this class can be used in a couple of special contexts. For example, it can be used to parametrize an on construct.

After creating p we will probably want to perform some operations within the processes of this particular grid. An on construct restricts control to processes in its parameter group. So in

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Proc...
... {
... body of on construct ...
}\end{verbatim}\end{minipage}\end{displaymath}

the code inside the construct is only executed by processes belonging to p. In Figure 2.1, the five processors outside the grid would skip this block of code.

If we save the following program:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}publ...
...Hello from an insider'') ;
}
}
}\end{verbatim}\end{minipage}\end{displaymath}

to a file EgOutIn.hpj, compile it, and run it by:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}java -Dhpjava.numprocs=11 EgOutIn\end{verbatim}\end{minipage}\end{displaymath}

we might see something like

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Hell...
...an outsider
Hello from an outsider\end{verbatim}\end{minipage}\end{displaymath}

The ``outsider'' message is printed 11 times; the ``insider'' message is printed 6 times. The exact order in which messages appear is non-deterministic, because there are 11 interleaved processes or threads.

The on construct in these examples establishes p as the active process group (or APG) within its body. The idea of an active process group that can change from line to line as the program is executed is an important concept in HPJava. The influence of the active process group will be seen in various places as we describe the language.

There is an auxilliary class hpjava.lang.Dimension associated with process grids. Objects of class Dimension describe a particular dimension or axis of a particular process grid. We will refer to them as process dimensions. The process dimensions of a grid are accessible through the inquiry method $\mbox{\tt dim(}r\mbox{\tt )}$ of the Procs class. The argument $r$ is in the range $0, \ldots,
R - 1$, where in general $R$ is the rank (dimensionality) of the grid.

The Dimension class in turn has a method crd() that returns the local process coordinate associated with the dimension--ie, the position of the local process within the dimension. If compile and execute the following HPJava program

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}publ...
...', '' + e.crd() + '')'') ;
}
}
}\end{verbatim}\end{minipage}\end{displaymath}

we see output something like:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}My c...
...e (1, 1)
My coordinates are (0, 1)\end{verbatim}\end{minipage}\end{displaymath}

Because the 6 processes are running concurrently there is no way to predict the order in which the messages appear. The dimensions of p are crudely illustrated in Figure 2.2. If we applied crd() to d or e in a process outside p (like one of the shaded processes in Figure 2.1) an hpjava.lang.ProcessNotInGroupException would be thrown.

Figure 2.2: The process dimensions and coordinates in p.
\includegraphics[width=2.5in]{procs2dims.eps}

There is nothing special about 2-dimensional grids. The full Group hierarchy of HPJava includes the classes of Figure 2.3. Not surprisingly, Procs1 is a one-dimensional process ``grid''. Less obviously, perhaps, Procs0 is a group containing exactly one process. This class is sometimes used to create a group that singles out a unique controlling process in a program. Higher dimensional grids are also allowed2.3.

Figure 2.3: The Group hierachy of HPJava.
\includegraphics{procs.eps}

Note that so far the only special syntax we have added to the Java language is the on construct. The Group class has special status in HPJava, but syntactically it is just a class. The status of Group in HPJava is comparable with the status of Throwable, say, in standard Java--only a Throwable object can appear in a throw statement, and only a Throwable class can appear in the header of a catch block or a throws clause. Likewise in HPJava, only a Group object can appear in the header of an on construct (or in the on clause of distributed arrays, which will be introduced later).


next up previous contents index
Next: Distributed Arrays Up: Processes and Distributed Arrays Previous: HPspmd Classes   Contents   Index
Bryan Carpenter 2003-04-15