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)]
[ phased [(ph1<mode1>, ...)] ]
[ await (ddf1, ...) ]
[ 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<T> [at (place)]
[phased [(ph1<mode1>, ...)] ]
[seq (condition)] { 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
• A point variable can hold values of different ranks e.g., point p; p = [1]; … p = [2,3]; …
for (point [i1, …] : [lo1:hi1, …]) Stmt
• Execute multiple instances of Stmt sequentially in lexicographic order, one per iteration in rectangular region [lo1:hi1, …]
forall (point [i1, …] : [lo1:hi1, …]) Stmt
• Create multiple parallel instances of Stmt as child async tasks, one per forall iteration in rectangular region [lo1:hi1, …]
• Implicit finish at end of forall
• Each forall has a pre-allocated phaser
foreach (point [i1, …] : [lo1:hi1, …]) [phased [(ph1<mode1>, ...)] ] Stmt
• Like forall, create multiple instances of Stmt as child async tasks, one per foreach iteration 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”
abstract performance metrics
• Programmer inserts calls of the form, perf.doWork(n), within tasks to denote n units of work
• HJ implementation computes total work and critical path length in units of work specified by the programmer’s calls to perf.doWork(n)