next up previous contents index
Next: Process Grids Up: Processes and Distributed Arrays Previous: Processes and Distributed Arrays   Contents   Index

HPspmd Classes

Not every HPJava program is a parallel program. In Chapter 1 we saw some examples of sequential HPJava codes. In fact any standard Java class can be used by an HPJava program, and typically the methods of standard Java classes aren't parallel programs.

For various reasons, some of which should become apparent as we go along, the HPJava system needs an unambiguous way to tell whether a given piece of code is supposed to be executed in a parallel way--distributed across multiple processes. In HPJava this is flagged by implementing a marker interface. Marker interfaces are a familiar mechanism in Java. Well known examples are the java.io.Serializable interface, which marks the instances of a particular class as being serializable, and the java.rmi.Remote interface, which marks the methods of a class as being remotely callable.

HPJava defines a marker interface hpjava.lang.HPspmd. Any class that implements this interface is referred to as an HPspmd class. The methods and constructors of HPspmd classes are supposed to be executed in a parallel context--they are meant to be invoked concurrently by a group of cooperating processes.

Consider these two examples:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}publ...
...ut.println(''Hello world'') ;
}
}\end{verbatim}\end{minipage}\end{displaymath}

and

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}publ...
...ut.println(''Hello world'') ;
}
}\end{verbatim}\end{minipage}\end{displaymath}

The only significant difference is that the second class implements the HPspmd interface (we don't need an explicit import declaration for the hpjava.lang package; it is imported implicitly into all HPJava programs).

Suppose we save these fragments in source files EgSeqHello.hpj and EgParHello.hpj respectively, and compile them using the hpjavac command as described in section 1.1.2. We assume that the class path is set up as described there, so that we are running under the multithreaded model.

If we start either class without specifying the hpjava.numprocs property, the result is the same

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}$ ja...
...rld
$ java EgParHello
Hello world\end{verbatim}\end{minipage}\end{displaymath}

In the latter case it happens this way because the default value of the hpjava.numprocs property is 1. If now we give a non-default value to the hpjava.numprocs property, the behavior is different:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}$ ja...
...llo world
Hello world
Hello world\end{verbatim}\end{minipage}\end{displaymath}

Because EgParHello is an HPspmd class, it is run concurrently in 4 different threads. Meanwhile, the hpjava.numprocs property is ignored when starting up a non-HPspmd class.


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