An HPJava program is started concurrently in some set of processes 2.1. In an HPJava program individual processes are distinguished by reference to special objects representing groups of processes. The processes in a group are typically organized as multidimensional arrays, or grids. For example, an HPJava program that is currently executing on 6 or more processes can define a 2 by 3 process grid as follows
Procs2 p = new Procs2(2, 3) ;Procs2 is a class describing 2-dimensional grids of processes. The Procs2 constructor is a collective operation. It should be invoked concurrently by all active processes. The process grid established as p is visualized in Figure 2.1. Here we imagine that the program started executing in 7 processes. The constructor singles out 6 of these processes and incorporates them in the grid. The labelling of the axes will be discussed below.
Procs2 is a subclass of the special base class Group, which represents a general group of processes. The Group class has a special status in the language. An object which inherits this class can be used to parametrize the first special syntactic construct of HPJava--the on construct. After creating p we will typically want to perform some operations within the processes of the grid. An on construct restricts control to processes in its parameter group. For example in
Procs2 p = new Procs2(2, 3) ; on(p) { ... }the code represented by the ellipsis is only executed by processes belonging to p. The lonely 7th processor of Figure 2.1 skips this block of code. The on construct establishes p as the active process group for its body. We will see later that the active process group is singled out as a default argument for various operations that depend on groups.
An auxilliary class called Dimension is associated with process grids. Objects of this class describe a particular dimension or axis of a particular process grid. They will be referred to as process dimensions. The process dimensions for a grid are obtained through the inquiry member dim. The Dimension class in turn has a member crd, which returns the local process coordinate associated with the dimension, ie, the position of the local process within the dimension. If we executed the following HPJava program
Procs2 p = new Procs2(2, 3) ; on(p) { Dimension d = p.dim(0), e = p.dim(1) ; System.out.println("My coordinates are (" + d.crd() + ", " + e.crd() + ")") ; }we might see the output
My coordinates are (0, 2) My coordinates are (1, 2) My coordinates are (0, 0) My coordinates are (1, 0) My coordinates are (1, 1) My coordinates are (0, 1)Because the 6 processes are running concurrently there is no way to predict the order in which the messages appear (and if we were unlucky they might even be interleaved). If we had the bad judgement to apply crd() to d or e in a process outside p (such as our 7th processes) we could expect an exception.
Before ending this section we should reassure the reader that there is nothing special about 2-dimensional grids. The full Group hierachy of HPJava includes the classes of Figure 2.2. Not surprisingly, Procs1 is a one-dimensional process ``grid''. Less obviously, Procs0 is a group containing exactly one process. Higher dimensional grids are also allowed.