next up previous contents
Next: Processes Up: The HPJava Language Previous: The HPJava Language   Contents


Multiarrays

As mentioned before, Java is an attractive programming language for various reasons. But it needs to be improved for solving large computational tasks. One of the critical Java and JVM issues is the lack of true multidimensional arrays[*] like those in Fortran, which are arguably the most important data structures for scientific and engineering computing. Java does not directly provide arrays with rank greater than $ 1$. Instead, Java represents multidimensional arrays as ``array of arrays.'' The disadvantages of Java multidimensional arrays result from the time consumption for out-of-bounds checking, the ability to alias rows of an array, and the cost of accessing an element. In contrast, accessing an element in Fortran 90 is straightforward and efficient. Moreover, an array section can be implemented efficiently. HPJava supports a true multidimensional array, called a multiarray, which is a modest extension to the standard Java language. The new arrays allow regular section subscripting, similar to Fortran 90 arrays. The syntax for the HPJava multiarray is a subset of the syntax introduced later for distributed arrays. The type signature and constructor of the multiarray has double brackets to tell them from ordinary Java arrays.

$\displaystyle \begin{minipage}[t]{\linewidth}\small\begin{verbatim}
int [[*,*]]...
...c = new int [[100]] ;
int [] d = new int [100] ;\end{verbatim}\end{minipage}
$

a, b, c are respectively a 2-dimensional integer array, 3-dimensional double array, and 1-dimensional int array. The rank is determined by the number of asterisks in the type signature. The shape of a multiarray is rectangular. Moreover, c is similar in structure to the standard array d. But, c and d are not identical. For instance, c allows section subscripting, but d does not. The value d would not be assignable to c, or vice versa. Access to individual elements of a multiarray is represented by a subscripting operation involving single brackets, for example,

$\displaystyle \begin{minipage}[t]{\linewidth}\small\begin{verbatim}
for(int i = 0 ; i < 4 ; i++)
a [i, i + 1] = i + c [i] ;\end{verbatim}\end{minipage}
$

In the current sequential context, apart from the fact that a single pair of brackets might include several comma-separated subscripts, this kind of subscripting works just like ordinary Java array subscripting. Subscripts always start at zero, in the ordinary Java or C style (there is no Fortran-like lower bound). Our HPJava imports a Fortran-90-like idea of array regular sections. The syntax for section subscripting is different to the syntax for local subscripting. Double brackets are used. These brackets can include scalar subscripts or subscript triplets. A section is an object in its own right--its type is that of a suitable multi-dimensional array. It describes some subset of the elements of the parent array. For example, in

$\displaystyle \begin{minipage}[t]{\linewidth}\small\begin{verbatim}
int [[]] e = a [[2, :]] ;
foo(b [[ : , 0, 1 : 10 : 2]]) ;\end{verbatim}\end{minipage}
$

e becomes an alias for the 3rd row of elements of a. The procedure foo should expect a two-dimensional array as argument. It can read or write to the set of elements of b selected by the section. The shorthand : selects the whole of the index range, as in Fortran 90.
next up previous contents
Next: Processes Up: The HPJava Language Previous: The HPJava Language   Contents
Bryan Carpenter 2004-06-09