next up previous contents index
Next: Local arrays Up: Low level SPMD programming Previous: Local blocks of subranges   Contents   Index

Reduction to Java arrays

Dimension splitting allows one to access the local blocks of distributed arrays as sequential HPJava arrays. In many cases this may be all one needs to do low level SPMD programming. But the translation scheme for HPJava actually assumes that ultimately all Fortran-like arrays are implemented in terms of the standard arrays of Java. HPJava does not attempt to conceal such things. Hence the underlying Java arrays should be available if they are needed.

The inquiry dat() can be applied to any HPJava multiarray or distributed array. It returns a reference to a Java array with the same type of elements as the target array. This is the actual array in which the local elements are stored.

This gives us yet another way to optimize the original data-parallel N-body example of Figure 7.1. We can express the compute loop in the MPI style of Figure 7.4. The code is given in Figure 7.13. This particular implementation assumes that the process grid p coincides with the MPI group associated with the COMM_WORLD communicator.

Figure 7.13: Version of the N-body force computation using reduction to Java arrays

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}Proc...
....FLOAT,
right, 0, left, 0) ;
}
}\end{verbatim}\end{minipage}\end{displaymath}

Again this simple example hides the complexities that arise if we have to deal with a general distributed array. As we saw in the previous section, the local elements of a general distributed array are effectively stored in a sequential multiarray. The detailed embedding is defined by the localBlock() inquiry on the distributed array ranges.

The mapping of the local sequential multiarray into the Java array is defined in turn by new inquiries bas() and str() on an HPJava multiarray. These integer-valued methods define a base offset, and a stride for each dimension7.4. If an element of a sequential HPJava array, a, has integer subscripts $i_0, \ldots, i_{R-1}$ it is stored in element

\begin{displaymath}
\mbox{\tt a.dat() [a.bas()} + i_0 \times \mbox{\tt a.str(0)} + \ldots +
i_{R - 1} \times \mbox{\tt a.str(}R - 1\mbox{\tt )]}
\end{displaymath}

of the local Java array.

This formula can be extended to a formula for finding the local elements of distributed arrays. First we note that through dimension splitting any distributed array can be reduced to an array that has a mix of only sequential dimensions and level 0 ranges. The level 0 ranges contribute nothing to the total offset of the element in the local Java array. So if the subscript list is $i_0, \ldots, i_{R-1}$--a mix of integers and level 0 distributed index symbols--the local element is

\begin{displaymath}
\mbox{\tt a.dat() [a.bas()} \quad +
\sum_{\begin{array}{c}...
...r} \end{array}}
i_r \times \mbox{\tt a.str($r$)}
\mbox{\tt ]}
\end{displaymath}

To complete the story, we need to know how the values of the str() and bas() members are defined on a dimension split array. If as is a section defined by splitting dimension $r$ of an array a, to yield dimensions $r'$ and $r'+1$ of as, then We can use these formulae to further simplify the recursive translation given earlier. The new translation is given in Figure 7.14. This is quite similar to the scheme actually used by the HPJava translator.

Figure 7.14: Reduction of subscripting in simple overall construct to local Java array accesses.
SOURCE:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}floa...
...(i = x for :)
a [i] = (float) i\lq  ;\end{verbatim}\end{minipage}\end{displaymath}

TRANSLATION:

\begin{displaymath}
\begin{minipage}[t]{\linewidth}\small\begin{verbatim}floa...
...loat) (b.glb_bas + b.glb_stp * l) ;\end{verbatim}\end{minipage}\end{displaymath}


next up previous contents index
Next: Local arrays Up: Low level SPMD programming Previous: Local blocks of subranges   Contents   Index
Bryan Carpenter 2003-04-15