Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

HJ Language Summary

This page summarizes the Habanero-Java (HJ) language constructs used in COMP 322. For a summary of all HJ language constructs, see the HJ web page.  Following standard conventions for defining programming language syntax, square brackets, [...], are used to denote optional clauses. 

async [at (place)] 

Wiki Markup
           \[
phased Wiki Markup

\           [ phased [(ph1<mode1>, ...)] ]   

           [ await (ddf1, ...) ]  

           [ 

Wiki Markup
&nbsp;&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \[
seq (condition) ]  Stmt 

Asynchronously start a new child task to execute Stmt

A destination place can optionally be specified in the at clause to specify where the task should execute

Task may optionally be phased on a specified subset, (ph1<mode1>, ...), of its parent’s phasers or on the entire set (default)

Task may optionally be serialized when the seq condition evaluates to true

finish Stmt

Execute Stmt, but wait until all (transitively) spawned asyncs and futures in Stmt’s scope have terminated

Propagate multiset of all exceptions thrown by spawned asyncs in Stmt’s scope

final future<T> f = async Wiki Markup<T> \ [at (place)] 

Wiki Markup
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \[
phased
Wiki Markup
\[(ph
                      [phased [(ph1<mode1>, ...)] ]                                             
Wiki Markup
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; \[

                      [seq (condition)]  Wiki Markup{ Expr }

Asynchronously start a new child task to evaluate Expr with at/phased/seq options as in statement-level async

f is a reference to object of type future<T> , which is a container for the value to be computed by the future  task

Expr is a statement sequence ending with return

f.get()

  • Wait until future f has completed execution, and propagate its return value  of type T
  • if T = void, then f.get() is evaluated as a statement (like a method call with a void return value)
  • get() also propagates any exception thrown by Expr

 

point

A point is an n-dimensional int tuple 

Wiki MarkupA point variable can hold values of different ranks e.g., point p; p = \ [1\]; p = \ [2,3\];

 

for (point Wiki Markup\[i1, \] : \ [lo1:hi1, \]) Stmt

Execute multiple instances of Stmt sequentially in lexicographic order, one per Wiki Markupiteration in rectangular region \ [lo1:hi1, \]

 

forall (point Wiki Markup\[i1, \] : \ [lo1:hi1, \]) Stmt

Create multiple parallel instances of Stmt as child async tasks, one per forall Wiki Markupiteration in rectangular region \forall iteration in rectangular region [lo1:hi1, \]

Implicit finish at end of forall

Each forall has a pre-allocated phaser

 

foreach (point Wiki Markup\[i1, \] : \ [lo1:hi1, \]) \ [phased Wiki Markup\[(ph1<mode1>, ...)] ] Stmt

Like forall, create multiple instances of Stmt as child async tasks, one per foreach Wiki Markupiteration in rectangular region \ [lo1:hi1, \]

  •   No implicit finish in foreach
  •   As with async, a foreach iteration may optionally be phased on a specified subset, (ph1<mode1>, ...), of its parent’s phasers or on the entire set

 

isolated Stmt

Execute Stmt in isolation (mutual exclusion) relative to all other instances of isolated statements

Stmt must not contain any parallel constructs

Weak atomicity: no guarantee on interactions with non-isolated statements  

new phaser(mode1);

Allocate a phaser with the specified mode, which can be one of SIG, WAIT, SIG_WAIT, SINGLE

Scope of phaser is limited to immediately enclosing finish 

next;

Advance each phaser that this task is registered on to its next phase, in accordance with this task’s registration mode

Wait on each phaser that task is registered on with a wait capability (WAIT, SIG_WAIT, SINGLE) 

next single Stmt

Execute a single instance of Stmt during the phase transition performed by next

All tasks executing the next single statement must be registered with all its phasers in SINGLE mode 

signal

signal each phaser that task is registered on with a signal capability (SIG, SIG_WAIT, SIGNAL)

signal is a non-blocking operation --- computation between signal and next serves as a “split phase barrier”

 

complex32, complex64

HJ includes complex as a primitive type e.g., 

complex32 cf  = (1.0f, 2.0f); complex64 cd = (1.0, 2.0);

The following operations are supported on complex:

+,-,*,/, ==, !=, toString(), exp(), sin(), cos(), sqrt(), pow()

 

array views

  • Wiki Markup
    &nbsp; T\[.\] declares a view on a 1-D Java array e.g.,

Wiki Markup&nbsp; &nbsp; &nbsp; double\[.\] view = new arrayView(baseArray, offset, \[lo1:hi1, …\])

  where

      baseArray = base 1-D Java array

      offset = starting offset in baseArray for view

Wiki Markup
&nbsp; &nbsp; &nbsp; \[lo1:hi1, …\] = rectangular region for view

 

abstract performance metrics

Programmer inserts calls of the form, perf.addLocalOpsdoWork(Nn), in sequential codewithin tasks to denote n units of work

HJ implementation computes total work and critical path length in units of programmer’s local opswork specified by the programmer’s calls to perf.doWork(n)