next up previous
Next: Programming in the adJava Up: Translation scheme Previous: Translation scheme


Java packages for HPspmd programming

The current runtime interface for HPJava is called adJava. It consists of two Java packages. The first is the HPspmd runtime proper. It includes the classes needed to translate language constructs. The second package provides communication and some simple I/O functions. These two packages will be outlined in this section.

The classes in the first package include an environment class, distributed array ``container classes'', and related classes describing process groups and index ranges. The environment class SpmdEnv provides functions to initialize and finalize the underlying communication library (currently MPI). Constructors call native functions to prepare the lower level communication package. An important field, apg, defines the group of processes that is cooperating in ``loose synchrony'' at the current point of execution.

The other classes in this package correspond directly to HPJava built-in classes. The first hierarchy is based on Group. A group, or process group, defines some subset of the processes executing the SPMD program. Groups have two important roles in HPJava. First they are used to describe how program variables such as arrays are distributed or replicated across the process pool. Secondly they are used to specify which subset of processes execute a particular code fragment. Important members of adJava Group class include the pair on(), no() used to translate the on construct.

Figure 1: The HPJava Group hierarchy
\begin{figure}\begin{center}
\leavevmode
\psfig{figure=procs.eps,width=2.2in} \end{center}\end{figure}
The most common way to create a group object is through the constructor for one of the subclasses representing a process grid. The subclass Procs represents a grid of processes and carries information on process dimensions: in particular an inquiry function dim(r) returns a range object describing the $r$-th process dimension. Procs is further subclassed by Procs0, Procs1, Procs2, ...which provide simpler constructors for fixed dimensionality process grids. The class hierarchy of groups and process grids is shown in figure 1.

The second hierarchy in the package is based on Range. A range is a map from the integer interval $0,\ldots,n-1$ into some process dimension (ie, some dimension of a process grid). Ranges are used to parametrize distributed arrays and the overall distributed loop.

Figure 2: The HPJava Range hierarchy
\begin{figure}\begin{center}
\leavevmode
\psfig{figure=ranges.eps,height=1.9in} \end{center}\end{figure}
The most common way to create a range object is to use the constructor for one of the subclasses representing ranges with specific distribution formats. The current class hierarchy is given in figure 2. Simple block distribution format is implemented by BlockRange, while CyclicRange and BlockCyclicRange represent other standard distribution formats of HPF. The subclass CollapsedRange represents a sequential (undistributed range). Finally, DimRange represents the range of coordinates of a process dimension itself--just one element is mapped to each process.

The related adJava class Location represents an individual location in a particular distributed range. Important members of the adJava Range class include the function location(i) which returns the $i$th location in a range and its inverse, idx(l), which returns the global subscript associated with a given location. Important members of the Location class include at() and ta(), used in the implementation of the HPJava that at construct.

Finally in this package we have the rather complex hierarchy of classes representing distributed arrays. HPJava global arrays declared using [[ ]] are represented by Java objects belonging to classes such as:

   Array1dI, Array1cI,
   Array2ddI, Array2dcI, Array2cdI, Array2ccI,
   ...
   Array1dF, Array1cF,
   Array2ddF, Array2dcF, Array2cdF, Array2ccF,
   ...
Generally speaking the class Arrayndc...T represents $n$-dimensional distributed array with elements of type T, currently one of I, F, ..., meaning int, float, ...[*]. The penultimate part of the class name is a string of $n$ ``c''s and ``d''s specifying whether each dimension is collapsed or distributed. These correlate with presence or absence of an asterisk in slots of the HPJava type signature. The concrete Array... classes implement a series of abstract interfaces. These follow a similar naming convention, but the root of their names is Section rather than Array (so Array2dcI, for example, implements Section2dcI). The hierarchy of Section interfaces is illustrated in figure 3.
Figure 3: The adJava Section hierarchy
\begin{figure}\begin{center}
\leavevmode
\psfig{figure=arrays.eps,height=2.8in} \end{center}\end{figure}
The need to introduce the Section interfaces should be evident from the hierarchy diagram. The type hierarchy of HPJava involves a kind of multiple inheritance. The array type int [[*, *]], for example, is a specialization of both the types int [[*, ]] and int [[, *]]. Java allows ``multiple inheritance'' only from interfaces, not classes.

We will illustrate constructors of the Array classes in later examples. Here we mention some important members of the Section interfaces. The inquiry dat() returns an ordinary one dimensional Java array used to store the locally held elements of the distributed array. The member pos(i, ...), which takes $n$ arguments, returns the local offset of the element specified by its list of arguments. Each argument is either a location (if the corresponding dimension is distributed) or an integer (if it is collapsed). The inquiry grp() returns the group over which elements of the array are distributed. The inquiry rng(d) returns the $d$th range of the array.

The second package in adJava is the communication library. The adJava communication package includes classes corresponding to the various collective communication schedules provided in the NPAC PCRC kernel. Most of them provide of a constructor to establish a schedule, and an execute method, which carries out the data movement specified by the schedule. The communication schedules provided in this package are based on the NPAC runtime library. Different communication models may eventually be added through further packages.

The collective communication schedules can be used directly by the programmer or invoked through certain wrapper functions. A class named Adlib is defined with static members that create and execute communication schedules and perform simple I/O functions. This class includes, for example, the following methods, each implemented by constructing the appropriate schedule and then executing it.

  static public void remap(Section dst, Section src)
  static public void shift(Section dst, Section src,
                           int shift, int dim, int mode)
  static public void copy(Section dst, Section src)
  static public void writeHalo(Section src,
                               int[] wlo, int[] whi, int[] mode)
Use of these functions will be illustrated in later examples. Polymorphism is achieved by using arguments of class Section.


next up previous
Next: Programming in the adJava Up: Translation scheme Previous: Translation scheme
Bryan Carpenter 2002-07-11