Difference between revisions of "Habanero"

From CSE231 Wiki
Jump to navigation Jump to search
 
(21 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 +
For Rice's official documentation on Habanero, refer to [http://pasiphae.cs.rice.edu/ this link.]
 +
 +
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html CSE 231s thin wrapper of Habanero].
 +
 
==Async, Finish==
 
==Async, Finish==
 
Async and finish make up the fundamental building blocks of task-level parallelism in Habanero.
 
Async and finish make up the fundamental building blocks of task-level parallelism in Habanero.
  
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#async-edu.rice.hj.api.HjSuspendable- async(body)] creates a new child task that can run before, after, or in parallel with all remaining statements of the parent task.
+
These concepts are first covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/be41f5f2b11a4445aa4be174e94f1717/1 RiceX Topic 1.1].
  
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#finish-edu.rice.hj.api.HjSuspendable- finish(body)] executes body and waits for all child tasks to complete.
+
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html#async-edu.rice.hj.api.HjSuspendable- async(body)] creates a new child task that can run before, after, or in parallel with all remaining statements of the parent task.
  
These concepts are first covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/be41f5f2b11a4445aa4be174e94f1717/1 RiceX Topic 1.1].
+
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html#finish-edu.rice.hj.api.HjSuspendable- finish(body)] executes body and waits for all child tasks to complete.
  
 
==Future==
 
==Future==
A future is a tasks that return a value.
+
A future is a task that returns a value.
  
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#future-edu.rice.hj.api.HjSuspendingCallable- future(body)] returns an instance of  [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html HjFuture].  Invoking the [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html#get-- get()] method on that instance waits for the task to complete.
+
Futures are covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/9eacfea8754549a4bc42918149130a74/1 RiceX Topic 2.1].
  
Futures are covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/9eacfea8754549a4bc42918149130a74/1 RiceX Topic 2.1].
+
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/f17/apidocs/edu/wustl/cse231s/rice/habanero/Habanero.html#future-edu.rice.hj.api.HjSuspendingCallable- future(body)] returns an instance of  [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html HjFuture].  Invoking the [http://www.cs.rice.edu/~vs3/hjlib/doc/edu/rice/hj/api/HjFuture.html#get-- get()] method on that instance waits for the task to complete.
  
 
==FinishAccumulator==
 
==FinishAccumulator==
 
Finish Accumulators provide a convenient way to keep track of a count (for example: the number of solutions in the n-queens problem) or perform a reduction as in the [[MapReduce_Assignment]].
 
Finish Accumulators provide a convenient way to keep track of a count (for example: the number of solutions in the n-queens problem) or perform a reduction as in the [[MapReduce_Assignment]].
  
 +
FinishAccumulators are covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/9eacfea8754549a4bc42918149130a74/7 RiceX Topic 2.3].
 +
 +
===FinishAccumulator Creation===
 
There are several ways to create the different forms of accumulators, but the two that come up in CSE231s are:
 
There are several ways to create the different forms of accumulators, but the two that come up in CSE231s are:
  
 
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#newIntegerFinishAccumulator-edu.wustl.cse231s.rice.classic.contrib.api.NumberReductionOperator- newIntegerFinishAccumulator]( [http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/contrib/api/NumberReductionOperator.html#SUM NumberReductionOperator.SUM] )
 
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#newIntegerFinishAccumulator-edu.wustl.cse231s.rice.classic.contrib.api.NumberReductionOperator- newIntegerFinishAccumulator]( [http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/contrib/api/NumberReductionOperator.html#SUM NumberReductionOperator.SUM] )
  
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#finish-edu.wustl.cse231s.rice.classic.options.RegisterAccumulatorsOption-edu.rice.hj.api.HjSuspendable- finish](register(accumulators), body)
+
and
 +
 
 +
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#newReducerFinishAccumulator-edu.wustl.cse231s.rice.classic.contrib.api.Reducer- newReducerFinishAccumulator]([http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/contrib/api/Reducer.html Reducer<T>] reducer)
 +
 
 +
===FinishAccumulator Registration===
 +
[http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#finish-edu.wustl.cse231s.rice.classic.options.RegisterAccumulatorsOption-edu.rice.hj.api.HjSuspendable- finish]([http://www.cse.wustl.edu/~cosgroved/courses/cse231/s17/javadocs/edu/wustl/cse231s/rice/classic/HabaneroClassic.html#register-edu.wustl.cse231s.rice.classic.contrib.api.FinishAccumulator-edu.wustl.cse231s.rice.classic.contrib.api.FinishAccumulator...- register(accumulators)], body)
  
FinishAccumulators are covered in [https://edge.edx.org/courses/RiceX/COMP322/1T2014R/courseware/a900dd0655384de3b5ef01e508ea09d7/9eacfea8754549a4bc42918149130a74/7 RiceX Topic 2.3].
+
==Loops==
 +
 
 +
WARNING: CSE 231s is all exclusive max, all the time.  forall, forasync, and forseq are all exclusive max.
 +
 
 +
===forasync===
 +
 
 +
<nowiki>forasync(0, size, (i)->{
 +
    ...
 +
} );</nowiki>
 +
 
 +
can be thought of as:
 +
 
 +
<nowiki>for( int _i=0; _i<size; _i++ ) {
 +
    final int i = _i;
 +
    async( ()->{
 +
        ...
 +
    });
 +
}</nowiki>
 +
 
 +
===forall===
 +
 
 +
<nowiki>forall(0, size, (i)->{
 +
    ...
 +
} );</nowiki>
 +
 
 +
is just forasync wrapped in a finish:
 +
 
 +
<nowiki>finish(()-> {
 +
    forasync(0, size, (i)->{
 +
        ...
 +
    } );
 +
});</nowiki>
 +
 
 +
===forseq===
 +
 
 +
<nowiki>forseq(0, size, (i)->{
 +
    ...
 +
} );</nowiki>
 +
 
 +
is equivalent to a standard for loop:
 +
 
 +
<nowiki>for( int i=0; i<size; i++ ) {
 +
    ...
 +
}</nowiki>
 +
 
 +
===chunked===
 +
the chunked() option to the forasync, forall, forasync2d, and forall2d splits up the work in a way that the runtime system sees fit.
 +
 
 +
===grouped===
 +
more precise control over how the work is split up via support for grouping.
 +
 
 +
<nowiki>int numTasks = numThreads();
 +
HjRegion1D iterSpace = newRectangularRegion1D(0, size);
 +
forall(0,  numTasks, (groupId)-> {
 +
HjRegion1D group = myGroup(groupId, iterSpace, numTasks);
 +
forseq(group, (i) -> {
 +
...
 +
});
 +
} );
 +
</nowiki>

Latest revision as of 05:26, 30 September 2017

For Rice's official documentation on Habanero, refer to this link.

CSE 231s thin wrapper of Habanero.

Async, Finish

Async and finish make up the fundamental building blocks of task-level parallelism in Habanero.

These concepts are first covered in RiceX Topic 1.1.

async(body) creates a new child task that can run before, after, or in parallel with all remaining statements of the parent task.

finish(body) executes body and waits for all child tasks to complete.

Future

A future is a task that returns a value.

Futures are covered in RiceX Topic 2.1.

future(body) returns an instance of HjFuture. Invoking the get() method on that instance waits for the task to complete.

FinishAccumulator

Finish Accumulators provide a convenient way to keep track of a count (for example: the number of solutions in the n-queens problem) or perform a reduction as in the MapReduce_Assignment.

FinishAccumulators are covered in RiceX Topic 2.3.

FinishAccumulator Creation

There are several ways to create the different forms of accumulators, but the two that come up in CSE231s are:

newIntegerFinishAccumulator( NumberReductionOperator.SUM )

and

newReducerFinishAccumulator(Reducer<T> reducer)

FinishAccumulator Registration

finish(register(accumulators), body)

Loops

WARNING: CSE 231s is all exclusive max, all the time. forall, forasync, and forseq are all exclusive max.

forasync

forasync(0, size, (i)->{
    ...
} );

can be thought of as:

for( int _i=0; _i<size; _i++ ) {
    final int i = _i;
    async( ()->{
        ...
    });
}

forall

forall(0, size, (i)->{
    ...
} );

is just forasync wrapped in a finish:

finish(()-> {
    forasync(0, size, (i)->{
        ...
    } );
});

forseq

forseq(0, size, (i)->{
    ...
} );

is equivalent to a standard for loop:

for( int i=0; i<size; i++ ) {
    ...
}

chunked

the chunked() option to the forasync, forall, forasync2d, and forall2d splits up the work in a way that the runtime system sees fit.

grouped

more precise control over how the work is split up via support for grouping.

int numTasks = numThreads();
HjRegion1D iterSpace = newRectangularRegion1D(0, size);
forall(0,  numTasks, (groupId)-> {
	HjRegion1D group = myGroup(groupId, iterSpace, numTasks);
	forseq(group, (i) -> {
		...
	});
} );