next up previous contents index
Next: Multiarrays Up: Getting Started Previous: For Cywin.   Contents   Index

Compiling and Running an HPJava program

We can now compile and run an HPJava program.

As a first example, go to the subdirectory hpjdk/examples/fft2d/ (or the nested folder hpjdk\examples\fft2d\, under Windows). This contains a fairly sophisticated little program that combines a parallel algorithm for 2-dimensional Fourier Transform (discussed in section 4.1) with a simple Java Swing graphical user interface.

The main program is in the file Wolf.hpj. Compile the whole program by issuing the command

\begin{minipage}[t]{\linewidth}\small\begin{verbatim}hpjavac Wolf.hpj\end{verbatim}\end{minipage}\end{displaymath}

The main program depends on a couple of other source files in the same directory (or folder), but you don't need to compile these explicitly. Like javac, the hpjavac command will detect these dependencies and automatically compile the other files that are needed.

You can now run the program by issuing the command

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

Because we are running under the multithreaded model (this was determined by our setting for CLASSPATH) this command will run Wolf as a ``parallel'' program in 4 threads of a single Java Virtual Machine1.1.

A small Swing window should appear. Click to load the input file. A new window containing a picture of a wolf should appear. You can experiment with the image, exploring the effect of deleting different numbers of modes in Fourier space. The windows are illustrated in Figure 1.1.

Figure 1.1: Running the example program.

In general running the hpjavac command generates one or more standard Java class files that can be executed by a standard Java Virtual Machine, or, as we will see later, by more than one JVM. (Section 2.7 describes how to run HPJava code on multiple JVMs, and thus on multiple computers.)

The source files passed as arguments to the hpjavac are normally HPJava programs with file extension ``.hpj'' (they can also be ordinary Java source files with extension ``.java'').

The hpjavac command is actually implemented as a preprocessor. Every HPJava source program is converted to an intermediate Java file. These intermediate files are then fed to the standard javac compiler. If you look in the fft2d/ directory after successfully running the hpjavac command you will find several intermediate Java files. You can study the content of these files if you are interested. They typically contain sections of recognizable Java code from the source file, interspersed with some very long lines produced by translating the extended syntax. The preprocessor works hard to preserve the line numbering of the input file, to make debugging easier. Generally speaking it is a bad idea to manually edit these automatically generated files.

next up previous contents index
Next: Multiarrays Up: Getting Started Previous: For Cywin.   Contents   Index
Bryan Carpenter 2003-04-15