next up previous contents index
Next: Communication library functions Up: Java language Binding Previous: Global variables

Program execution control

 

HPJava has all the conventional Java statements for execution control within a single process. It introduces three new control constructs, on, at and overall for execution control across processes. A new concept, the active process group, is introduced. It is the set of processes sharing the current thread of control.

In a traditional SPMD program, switching the active process group is effectively implemented by if statements such as:

  if(myid >= 0 && myid < 4) {
    ...
  }

Inside the braces, only processes numbered 0 to 3 share the control thread. In HPJava, this effect is expressed using a Group. When a HPJava program starts, the active process group has a system-defined value. During the execution, the active process group can be changed explicitly through an on construct in the program.

In a shared memory program, accessing the value of a variable is straightforward. In a message passing system, only the process which holds data can read and write the data. We sometimes call this SPMD constraint SPMD constraint. A traditional SPMD program respects this constraint by using an idiom like

  if(myid == 1) 
    my_data = 3 ;

The if statement makes sure that only my_data on process 1 is assigned to.

In the language we present here similar constraints must be respected. Besides on construct introduced earlier, there is a convenient way to change the active process group to access a required array element, namely the at construct. Suppose array a is defined as in the previous section, then:

  on(q) {
    a [1] = 3 ;    // error

    at(j = x [1])
      a [j] = 3 ;  // correct
  }

The assignment statement guarded by an at construct is correct; the one without is likely to imply access to an element not held locally. Formally it is illegal because, in a simple subscripting operation, an integer expression cannot be used to subscript a distributed dimension. The at construct introduces a new variable j, a named location, with scope only inside the block controlled by the at. Named locations are the only legal element subscripts in distributed dimensions.

A more powerful construct called overall combines restriction of the active process group with a loop:

  on(q)
    overall(i = x [0 : 3])
      a [i] = 3 ;

is essentially equivalent togif

  on(q) 
    for(int n = 0 ; n < 4 ; n++)
      at(i = x [n])
        a [i] = 3;

In each iteration, the active process group is changed to q / i. In section gif, we will illustrate with further programs how at and overall constructs conveniently allow one to keep the active process group equal to the data owner group for the assigned data.


next up previous contents index
Next: Communication library functions Up: Java language Binding Previous: Global variables

Guansong Zhang
Mon Feb 8 16:41:16 EST 1999