next up previous
Next: Communication library functions Up: Java language Binding Previous: Inquiry fields and functions


Program execution control

HPJava has all the 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. 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 at construct. Suppose array a is defined as in the previous section, then:

on (q) {
  Location i=x[1];
  at(i)
    a[i]=3; //correct

  a[i]=3;   //error
}
The assignment statement guarded by an at construct is correct; the one without it may cause run-time error.

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

on(q)
  overall(i= x|0:3)
    a[i]=3;
is essentially equivalent to3
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 3, 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
Next: Communication library functions Up: Java language Binding Previous: Inquiry fields and functions
Bryan Carpenter 2002-07-11