next up previous contents
Next: Applications Up: HPJava: Work in progress. Previous: Limitations of the prototype   Contents

Parallel arrays and data parallel computation

After some preliminary investigation of possible interfaces for parallel container classes in Java, we have a rather cautious view about the opportunities offered by this approach.

The standard Java library provides a few container classes (Vector, Dictionary, Hashtable...). Because Java doesn't provide templates, these are implemented as containers for the Object base class. This involves forsaking the safety of compile-time checking, and incurring the inefficiency of run-time checking of type-casts.

In the majority of HP applications the arrays required will have elements of primitive types (int, float, double,...). So these will have to wrapped up as objects. This introduces the further inefficiency and inconvenience of allocating the wrapper objects for all array elements, and accessing the data through methods on the wrappers.

Of course it is not possible to provide iterator classes in the STL sense for Java container classes, due to the lack of pointers and operator overloading.

For these reasons, in the present state of development of Java, it may not be productive to devote effort to designing parallel container classes [maybe eventually Java will evolve into C++, and this will become a better option...]. The interface is likely to be so clumsy and inefficient that it would be unattractive to application programmers, or as a target for compilation.

Presently we are focussing on providing a set of lower level ``helper'' classes, to facilitate writing data parallel programs. Ultimately these classes could be incorporated as part of the implementation of container classes, if somebody comes up with a more viable framework for implementing those.

The kind of helper classes we have in mind describe, for example, process grids and distributed index ranges.

Our interface is in its early stages, but we will illustrate the general approach by an example. Consider the HPF program

 !HPF$ PROCESSORS p(4, 4)
       REAL a(0 : 99, 0 : 99)
 !HPF$ DISTRIBUTE a(BLOCK, BLOCK) ONTO p


       FORALL(i = 0 : 99, j = 0 : 99)
         a(i, j) = i + j
A possible Java rendition is
  Procs p = new Procs(4, 4) ;

  Range x = new Range(100, BLOCK, p, 1) ;
  Range y = new Range(100, BLOCK, p, 2) ;

  float [] [] a = new float [x.seg()] [y.seg()] ;

  for(x.forall() ; x.next() ; x.test())
    for(y.forall() ; y.next() ; y.test())
      a [x.sub()] [y.sub()] = x.idx() + y.idx() ;
Here Procs is a class describing a process grid, and Range is a class for describing an index range distributed over a particular grid dimension. The Range members are
  int seg() ;
which returns the size of a local array segment (25 in this example),
  void forall() ;
  boolean test() ;
  void next() ;
which enumerate the local segment of the index range,
  int sub() ;
which returns the local subscript for the current iteration and
  int idx() ;
which returns the global index for the current iteration.

This example is for illustration only. The concrete interface to the classes is bound to be changed and extended.

Once the general scheme for representing and accessing distributed arrays is in place, we can define the interfaces to high level collective communications (shift, transpose, broadcast, reduce, ...). These could, for example, be implemented on top of the channels interface described in the previous section.


next up previous contents
Next: Applications Up: HPJava: Work in progress. Previous: Limitations of the prototype   Contents
Bryan Carpenter 2002-07-12