next up previous contents
Next: JavaParty Up: Related Systems Previous: Co-Array Fortran   Contents


ZPL [45] is an array programming language designed from first principles for fast execution on both sequential and parallel computers for scientific and engineering computation. In scalar languages such as Fortran, C, Pascal, Ada, and so on, $ a + b$ represents the addition of two numbers, i.e. operations apply only to single values. In such languages we need looping and indexing in order to add two arrays:

In HPJava we might use overall constructs. In ZPL operations are generalized to apply to both scalars and arrays. Thus, $ a + b$ expresses the sum of two scalars if a and b were declared as scalars, or arrays if they were declared as arrays. When applied to arrays, the operations act on corresponding elements as illustrated in the loops above. When the ZPL compiler encounters the statement

$\displaystyle \begin{minipage}[t]{\linewidth}\small\begin{verbatim}
A := A + B;\end{verbatim}\end{minipage}

and A and B are two dimensional arrays, it generates code that is effectively the same as the Fortran loops shown above. An array language, therefore, simplifies programming. Of course this is very similar to Fortran 90. ZPL has an idea of performing computations over a region, or set of indices. Within a compound statement prefixed by a region specifier, aligned elements of arrays distributed over the same region can be accessed. This idea has similarities to our overall construct. In ZPL, parallelism and communication are more implicit than in HPJava. The connection between ZPL programming and SPMD programming is not explicit. While there are certainly attractions to the more abstract point of view, HPJava deliberately provides lower-level access to the parallel machine.
Figure 8.1: A simple Jacobi program in ZPL.
/*                     Jacobi                       */
program jacobi;

config var n     : integer = 5;       -- Declarations
           delta : float   = 0.0001;
region     R = [1..n, 1..n];
direction  north = [-1, 0]; south = [ 1, 0];
           east  = [ 0, 1]; west  = [ 0,-1];

procedure jacobi();                   -- Entry point
var A, Temp : [R] float;
    err     :     float;

[R]           A := 0.0;               -- Initialization
[north of R]  A := 0.0;
[east  of R]  A := 0.0;
[west  of R]  A := 0.0;
[south of R]  A := 1.0;

[R]  repeat                           -- Main body
         Temp := (A@north+A@east+A@west+A@south) / 4.0;
         err  := max<< abs(A-Temp);
         A    := Temp;   
     until err < delta;

[R]  writeln(A);                      -- Output result
Figure 8.1 illustrates a ZPL program for Jacobi. Compared to an HPJava program for Jacobi in Figure 3.7, HPJava uses a nested overall loop for this computation, and ZPL uses a loop in the main body because of the generalized array operations.
next up previous contents
Next: JavaParty Up: Related Systems Previous: Co-Array Fortran   Contents
Bryan Carpenter 2004-06-09