next up previous contents
Next: Adlib for HPJava Up: The HPJava Language Previous: Array Sections   Contents


Low Level SPMD Programming

Dimension splitting is defined as an extension of the array section. The extra syntax is minimal, but the effect is useful. So far, we have identified a specific element by giving a global subscript in the distributed range. Alternatively, dimension splitting supports for accessing an element using its process coordinate and local subscript[*], by allowing a distributed dimension of an array to be temporarily treated as two dimensions. If a particular dimension of an array section has the symbol <> as a subscript, the dimension of the array section is supposed to be split. Splitting a dimension creates two dimensions, a distributed dimension and a sequential dimension. The range of the distributed dimension is the process dimension over which the original array dimension was distributed. The local block of the original array is embedded in the sequential dimension of the result array. The two new dimensions appear consecutively in the signature of the result array, distributed dimension first.

$\displaystyle \begin{minipage}[t]{\linewidth}\small\begin{verbatim}
Procs2 p = ...
...
double [[-,-,*]] as = a [[:, <>]] on p ;
...
}\end{verbatim}\end{minipage}
$

Figure 3.18 illustrated the dimension splitting for the above example.
Figure 3.18: The dimension splitting in HPJava.
\includegraphics[height=5in]{Figures/split}
Figure 3.19: N-body force computation using dimension splitting in HPJava.
  Procs1    p = new Procs1(P) ;
  Dimension d = p.dim(0) ;
  on(p) {
    Range x = new BlockRange(N, d) ;

    double [[-]] f = new double[[x]] on p ;
    double [[-]] a = new double[[x]] on p ; 
    double [[-]] b = new double[[x]] on p ;

    ... initialize `a' ...

    overall(i = x for :) {
      f [i] = 0.0 ;
      b [i] = a [i] ;
    }

    // split `x' dimensions:
    double [[-,*]] fs = f [[<>]], as = a [[<>]], bs = b [[<>]] ;   

    for(int s = 0 ; s < P ; s++) {
      overall(i = d for :)
        for(int j = 0 ; j < B ; j++)
          for(int k = 0 ; k < B ; k++)
            fs [i, j] += force(as [i, j], bs [i, k]) ;

      // cyclically shift `bs' in `d' dim...

      Adlib.cshift(tmp, bs, 1, 0) ;
      HPutil.copy(bs, tmp) ;
    }
  }
The N-Body problem in Figure 3.19 on the page [*] initially creates the arrays as distributed, one-dimensional arrays, and uses this convenient form to initialize them. It then uses a split representation of the same arrays to compute the force array. Note that, because as and fs are semantically sections of a and f, they share common elements--they provide aliases through which the same element variables can be accessed. So when the computation loop is complete, the vector of forces can be accessed again through the one-dimensional array f. This is likely to be what is needed in this case. In Figure 3.19, $ B$ is the local block size $ N/P$ ($ P$ must exactly divide $ N$ for this example to work correctly).
next up previous contents
Next: Adlib for HPJava Up: The HPJava Language Previous: Array Sections   Contents
Bryan Carpenter 2004-06-09