public abstract class BaseRuntime extends Object implements HjRuntime
BaseRuntime class.
Modifier and Type | Field and Description |
---|---|
protected DeadlockTracker |
deadlockTracker
Deals with deadlock tracking
|
EventLogger |
eventLogger
The event logger
|
protected IsolationManager |
isolationManager
The IsolationManager used to run the isolated construct
|
AbstractMetricsManager |
metricsManager
The abstract metrics manager
|
protected PhaserManager |
phaserManager
Deals with phaser related operations
|
Constructor and Description |
---|
BaseRuntime()
No-args constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
abort()
Aborts the currently executing task.
|
HjMetrics |
abstractMetrics()
abstractMetrics.
|
protected abstract BaseThreadPool[] |
allocateExecutors(int numPlaces,
int numWorkers,
boolean asyncMode) |
<T> void |
asyncAwait(List<HjFuture<T>> dependencies,
HjRunnable runnable)
Will execute the body of the runnable only after the dependences have been satisfied.
|
void |
asyncPhased(List<HjPhaserPair> phaserList,
HjSuspendable suspendable)
asyncPhased.
|
void |
asyncSeqAt(boolean sequentialize,
HjPlace place,
HjRunnable runnable)
Runs the body of code (possibly) asynchronously at the specified place.
|
void |
asyncSuspAt(HjPlace place,
HjSuspendable suspendable)
Runs the body of code (possibly) asynchronously at the specified place.
|
<T> void |
asyncSuspAwait(List<HjFuture<T>> dependencies,
HjSuspendable suspendable)
Will execute the body of the runnable only after the dependences have been satisfied.
|
void |
asyncWhen(HjExpression.HjAwaitExpression expression,
HjRunnable hjRunnable)
Mechanism to create an asynchronous task where the await expression is designed to coordinate relationships of
this parallel tasks with other tasks (using the
HjFuture handles. |
<T> void |
checkEureka(T eurekaValue) |
void |
cleanup()
Cleans up the runtime in anticipation for shutdown.
|
HabaneroActivity |
currentActivity()
Returns The currently executing activity.
|
static HabaneroActivity |
currentHabaneroActivity()
currentBlockingActivity.
|
HjPlace |
currentPlace() |
static BaseThread |
currentThread()
currentThread.
|
void |
doWait()
Perform the wait operation on all registered phasers in an activity.
|
void |
doWork(long workUnits)
Registers n units of work against the currently running activity.
|
void |
dumpEventLog(PrintStream printStream)
Dumps the events tracked by the runtime.
|
void |
emergencyShutdown(Throwable cause)
Shutdown the runtime, this means also shutting down all places associated with this runtime and all currently
executing activities.
|
void |
finish(HjEureka<?,?,?> hjEureka,
HjSuspendable suspendable)
Registers a HjEureka with the finish scope and continues to execute the body of the finish scope.
|
void |
finish(HjSuspendable suspendable)
Runs the body of code in a finish block.
|
void |
finish(List<HjFinishAccumulator> accumulators,
HjSuspendable suspendable)
finish.
|
<T,V> HjFuture<V> |
futureAwait(List<HjFuture<T>> dependencies,
HjCallable<V> callable)
Equivalent of
HjRuntime.asyncAwait(java.util.List, HjRunnable) which returns a futureNb. |
<V> HjFuture<V> |
futureSeq(boolean sequentialize,
HjCallable<V> callable)
Creates an asynchronous task and returns the futureNb object representing the value of the computation.
|
<V> HjFuture<V> |
futureSusp(HjSuspendingCallable<V> callable)
Creates an asynchronous task and returns the futureNb object representing the value of the computation.
|
<T,V> HjFuture<V> |
futureSuspAwait(List<HjFuture<T>> dependencies,
HjSuspendingCallable<V> callable)
Equivalent of
HjRuntime.asyncAwait(java.util.List, HjRunnable) which returns a future. |
<V> HjFuture<V> |
futureWhen(HjExpression.HjAwaitExpression expression,
HjCallable<V> hjCallable)
Mechanism to create an asynchronous task where the await expression is designed to coordinate relationships of
this parallel tasks with other tasks (using the
HjFuture handles. |
protected static String |
generateActivityName(String inName)
generateActivityName.
|
void |
initialize()
Initializes the runtime.
|
void |
isolated(HjRunnable runnable)
isolated.
|
void |
isolated(Object[] participants,
HjRunnable runnable)
Isolated statement identifies a critical section.
|
void |
isolated(Object participant,
HjRunnable runnable)
Isolated statement identifies a critical section.
|
<V> V |
isolatedWithReturn(HjCallable<V> callable)
isolatedWithReturn.
|
<V> V |
isolatedWithReturn(Object[] participants,
HjCallable<V> callable)
isolatedWithReturn.
|
<V> V |
isolatedWithReturn(Object participant,
HjCallable<V> callable)
isolatedWithReturn.
|
static boolean |
isWorkerThread()
isWorkerThread.
|
<L,R> HjBinaryEureka<L,R> |
newBinaryEureka(HjLogicalOperator operator,
HjEureka<L,Object,L> leftEureka,
HjEureka<R,Object,R> rightEureka)
Factory method to create a new
HjBinaryEureka instance. |
<T> HjConvergenceEureka<T> |
newConvergenceEureka(T initialValue,
java.util.function.BiPredicate<T,T> checker,
HjProcedure<T> convergenceCallback)
Factory method to create a new
HjConvergenceEureka instance. |
<T> HjCountEureka<T> |
newCountEureka(long maxCount,
int spaceForResult)
Factory method to create a new
HjCountEureka instance. |
<V> HjDataDrivenFuture<V> |
newDataDrivenFuture(boolean allowDuplicatePuts)
Factory method for a DataDrivenFuture.
|
<T> HjEngineEureka<T> |
newEngineEureka(int maxUnits)
Factory method to create a new
HjEngineEureka instance. |
HjEventCount |
newEventCount(int initialCount)
Returns a new instance of an HjEventCount.
|
<T> HjExtremaEureka<T> |
newExtremaEureka(T initialValue,
Comparator<T> comparator,
boolean shouldAbortOnOffer)
Factory method to create a new
HjExtremaEureka instance. |
HjFastBarrierEureka |
newFastBarrierEureka(int numPhases)
Factory method to create a new
HjFastBarrierEureka instance. |
HjFinishAccumulator |
newFinishAccumulator(HjOperator ope,
Class type)
newFinishAccumulator.
|
HjPhaser |
newPhaser(HjPhaserMode phaserMode,
int busyWaitLimit)
Create a new phaser in the specified registration mode..
|
<T> HjSearchEureka<T> |
newSearchEureka(T initialValue)
Factory method to create a new
HjSearchEureka instance. |
<T> HjTimerEureka<T> |
newTimerEureka(int timeUnitsInMillis)
Factory method to create a new
HjTimerEureka instance. |
<T> HjVersionEureka<T> |
newVersionEureka(int n)
Factory method to create a new
HjVersionEureka instance. |
void |
next()
Perform the next operation on all registered phasers in an activity.
|
int |
numWorkerThreads()
Returns the number of worker threads employed by the runtime for the current place.
|
<T> void |
offerEureka(T eurekaValue) |
<T> T |
readEureka()
Return the current value stored on the registered eureka.
|
Object |
readMode(Object wrappee)
readMode.
|
void |
registerListenerForMetrics(HabaneroActivity habaneroActivity)
registerListenerForMetrics.
|
<T> HjEureka<T,T,T> |
retrieveEureka()
Return the eureka to be registered in the finish scope.
|
HjEventLogger |
retrieveEventLogger()
Retrieves the
HjEventLogger used by the runtime. |
protected void |
runActivity(HabaneroActivity activity)
Submit an activity to place's thread pool This method is initialize some activity properties such as FinishState
and current Place.
|
void |
runKernel(HjSuspendable suspendable)
Entry of the user's program body into the Habanero runtime.
|
void |
scheduleActivity(HjPlace hjPlace,
Runnable runnable)
Schedules an activity whose body is represented by the
Runnable instance. |
void |
scheduleActivity(Runnable runnable)
Schedules an activity whose body is represented by the
Runnable instance. |
void |
signal()
Perform the signal operation on all registered phasers in an activity.
|
Object |
writeMode(Object wrappee)
writeMode.
|
public final AbstractMetricsManager metricsManager
public final EventLogger eventLogger
protected final IsolationManager isolationManager
protected final PhaserManager phaserManager
protected final DeadlockTracker deadlockTracker
protected abstract BaseThreadPool[] allocateExecutors(int numPlaces, int numWorkers, boolean asyncMode)
public static boolean isWorkerThread()
isWorkerThread.
public static BaseThread currentThread()
currentThread.
public void initialize()
initialize
in interface HjRuntime
public void runKernel(HjSuspendable suspendable)
public void cleanup()
public HabaneroActivity currentActivity()
currentActivity
in interface HjRuntime
public void scheduleActivity(Runnable runnable)
Runnable
instance.scheduleActivity
in interface HjRuntime
runnable
- The runnable activity to schedule.public void scheduleActivity(HjPlace hjPlace, Runnable runnable)
Runnable
instance.scheduleActivity
in interface HjRuntime
hjPlace
- The place at which to schedule this activity.runnable
- The runnable activity to schedule.public int numWorkerThreads()
numWorkerThreads
in interface HjRuntime
public HjPlace currentPlace()
currentPlace
in interface HjRuntime
public void finish(HjSuspendable suspendable) throws SuspendableException
finish
in interface HjRuntime
suspendable
- The body of the code to run wrapped in a finish block.SuspendableException
protected static String generateActivityName(String inName)
generateActivityName.
inName
- The undecorated activity namepublic void asyncSeqAt(boolean sequentialize, HjPlace place, HjRunnable runnable)
asyncSeqAt
in interface HjRuntime
sequentialize
- The flag that determines whether the runtime should consider running the body
asynchronously.place
- The place where the async task should run. This parameter may be ignored if the task is to
be run sequentially.runnable
- The body of the code to run, possibly asynchronously.public final void asyncSuspAt(HjPlace place, HjSuspendable suspendable)
asyncSuspAt
in interface HjRuntime
place
- The place where the async task should run. This parameter may be ignored if the task is to be
run sequentially.suspendable
- The body of the code to run, possibly asynchronously. The body of the code possibly contains a
suspendable condition.public <V> HjFuture<V> futureSeq(boolean sequentialize, HjCallable<V> callable)
futureSeq
in interface HjRuntime
V
- The return type of the body.sequentialize
- The flag that determines whether the runtime should consider running the body
asynchronously.callable
- The body of the callable to run, possibly asynchronously.public <V> HjFuture<V> futureSusp(HjSuspendingCallable<V> callable)
futureSusp
in interface HjRuntime
V
- The return type of the body.callable
- The body of the callable to run, possibly asynchronously.public <T,V> HjFuture<V> futureAwait(List<HjFuture<T>> dependencies, HjCallable<V> callable)
HjRuntime.asyncAwait(java.util.List, HjRunnable)
which returns a futureNb.futureAwait
in interface HjRuntime
V
- The return type of the body.dependencies
- The data dependencies of the asynchronous taskcallable
- The body of the callable to run, possibly asynchronously.public <T,V> HjFuture<V> futureSuspAwait(List<HjFuture<T>> dependencies, HjSuspendingCallable<V> callable)
HjRuntime.asyncAwait(java.util.List, HjRunnable)
which returns a future.futureSuspAwait
in interface HjRuntime
V
- The return type of the body.dependencies
- The data dependencies of the asynchronous taskcallable
- The body of the callable to run, possibly asynchronously.public <V> HjDataDrivenFuture<V> newDataDrivenFuture(boolean allowDuplicatePuts)
newDataDrivenFuture
in interface HjRuntime
V
- The type of the data wrapped in the DDF.public <T> void asyncAwait(List<HjFuture<T>> dependencies, HjRunnable runnable)
asyncAwait
in interface HjRuntime
dependencies
- The data dependencies of the asynchronous taskrunnable
- The body of the code to run, possibly asynchronously.public <T> void asyncSuspAwait(List<HjFuture<T>> dependencies, HjSuspendable suspendable)
asyncSuspAwait
in interface HjRuntime
dependencies
- The data dependencies of the asynchronous tasksuspendable
- The body of the code to run, possibly asynchronously.public void isolated(HjRunnable runnable)
isolated.
public void isolated(Object participant, HjRunnable runnable)
public void isolated(Object[] participants, HjRunnable runnable)
public <V> V isolatedWithReturn(HjCallable<V> callable)
isolatedWithReturn.
isolatedWithReturn
in interface HjRuntime
V
- a V object.callable
- The body of the code to run using weak isolation.public <V> V isolatedWithReturn(Object participant, HjCallable<V> callable)
isolatedWithReturn.
isolatedWithReturn
in interface HjRuntime
V
- a V object.participant
- The object involved in the atomic block.callable
- The body of the code to run using weak isolation.public <V> V isolatedWithReturn(Object[] participants, HjCallable<V> callable)
isolatedWithReturn.
isolatedWithReturn
in interface HjRuntime
V
- a V object.participants
- The objects involved in the atomic block.callable
- The body of the code to run using weak isolation.public HjFinishAccumulator newFinishAccumulator(HjOperator ope, Class type)
newFinishAccumulator.
newFinishAccumulator
in interface HjRuntime
ope
- The type of the HjOperatortype
- The result typepublic void finish(List<HjFinishAccumulator> accumulators, HjSuspendable suspendable) throws SuspendableException
finish.
finish
in interface HjRuntime
accumulators
- The accumulators registered on the finish.suspendable
- The body of the code to run wrapped in a finish block.SuspendableException
public HjPhaser newPhaser(HjPhaserMode phaserMode, int busyWaitLimit)
public static HabaneroActivity currentHabaneroActivity()
currentBlockingActivity.
HabaneroActivity
object.public void asyncPhased(List<HjPhaserPair> phaserList, HjSuspendable suspendable)
asyncPhased.
asyncPhased
in interface HjRuntime
phaserList
- The list of phasers the async is registered on.suspendable
- The body of the code to run, possibly asynchronously.public void next() throws SuspendableException
next
in interface HjRuntime
SuspendableException
public void signal()
public void doWait() throws SuspendableException
doWait
in interface HjRuntime
SuspendableException
public void emergencyShutdown(Throwable cause)
emergencyShutdown
in interface HjRuntime
cause
- The exception causing the shutdown.public void doWork(long workUnits)
public HjMetrics abstractMetrics()
abstractMetrics.
abstractMetrics
in interface HjRuntime
public HjEventLogger retrieveEventLogger()
HjRuntime
HjEventLogger
used by the runtime.retrieveEventLogger
in interface HjRuntime
HjEventLogger
used by the runtime.public void dumpEventLog(PrintStream printStream)
HjRuntime
dumpEventLog
in interface HjRuntime
printStream
- The stream to use while dumping the events.public void asyncWhen(HjExpression.HjAwaitExpression expression, HjRunnable hjRunnable)
HjFuture
handles.
The body of this async is only executed when the expression evaluates to true, the expression can only be safely evaluated after all the futures involved in the expression have been resolved when in strict mode (expression contains a NOT). There is also a short-circuit mode (expression contains only AND and OR) where the expression is evaluated early and the asynchronous computation triggered even when some of the other dependent tasks may not yet have completed execution.
The semantics of
asyncWhen(awaitExpr, () -> S1)
are as follows:
async(() -> {
boolean exprVal = expr.evaluate();
if (exprVal) {
S1;
}
});
public <V> HjFuture<V> futureWhen(HjExpression.HjAwaitExpression expression, HjCallable<V> hjCallable)
HjFuture
handles. Also returns the
futureNb object representing the value of the computation.
The body of this async is only executed when the expression evaluates to true, the expression can only be safely evaluated after all the futures involved in the expression have been resolved when in strict mode (expression contains a NOT). There is also a short-circuit mode (expression contains only AND and OR) where the expression is evaluated early and the asynchronous computation triggered even when some of the other dependent tasks may not yet have completed execution.
The semantics of
futureWhen(awaitExpr, () -> S1)
are as follows:
futureNb(() -> {
boolean exprVal = expr.evaluate();
if (exprVal) {
S1;
} else {
throw new RuntimeException("clause failed!");
}
});
futureWhen
in interface HjRuntime
expression
- The expression that controls when the async is ready for execution.hjCallable
- The body of the async.public void finish(HjEureka<?,?,?> hjEureka, HjSuspendable suspendable) throws SuspendableException
finish
in interface HjRuntime
hjEureka
- the eureka to be registeredsuspendable
- the body of the finish scopeSuspendableException
public <T> HjSearchEureka<T> newSearchEureka(T initialValue)
HjSearchEureka
instance.newSearchEureka
in interface HjRuntime
initialValue
- The initial value of the search eureka objectHjSearchEureka
instancepublic <T> HjExtremaEureka<T> newExtremaEureka(T initialValue, Comparator<T> comparator, boolean shouldAbortOnOffer)
HjExtremaEureka
instance.newExtremaEureka
in interface HjRuntime
initialValue
- The initial value of the extrema, it should be smaller than expected result.comparator
- The comparator used to maximize the extrema value. The first argument of the comparator
is the existing value in the eureka, and the second argument is the new argument passed
inside the call to offer
and check
.shouldAbortOnOffer
- Whether a successful offer should abort the current taskHjExtremaEureka
instance.public <T> HjConvergenceEureka<T> newConvergenceEureka(T initialValue, java.util.function.BiPredicate<T,T> checker, HjProcedure<T> convergenceCallback)
HjConvergenceEureka
instance.newConvergenceEureka
in interface HjRuntime
initialValue
- The initial value of the eureka.checker
- The predicate used to check for convergence.convergenceCallback
- A callback invoked once the eureka has converged.HjConvergenceEureka
instance.public HjFastBarrierEureka newFastBarrierEureka(int numPhases)
HjFastBarrierEureka
instance.newFastBarrierEureka
in interface HjRuntime
numPhases
- The number of phases in the fast barrier.HjFastBarrierEureka
instance.public <T> HjCountEureka<T> newCountEureka(long maxCount, int spaceForResult)
HjCountEureka
instance.newCountEureka
in interface HjRuntime
maxCount
- The maximum number of eureka events before the eureka is resolved.spaceForResult
- The maximum number of results to store in the eureka.HjCountEureka
instance.public <T> HjVersionEureka<T> newVersionEureka(int n)
HjVersionEureka
instance.newVersionEureka
in interface HjRuntime
n
- The number of items that need to match before the eureka is resolved.HjVersionEureka
instance.HjRuntime.newVersionEureka(int)
public <T> HjEngineEureka<T> newEngineEureka(int maxUnits)
HjEngineEureka
instance.newEngineEureka
in interface HjRuntime
maxUnits
- The maximum number of time units in the eureka.HjEngineEureka
instance.public <T> HjTimerEureka<T> newTimerEureka(int timeUnitsInMillis)
HjTimerEureka
instance.newTimerEureka
in interface HjRuntime
timeUnitsInMillis
- The maximum number of milliseconds before the eureka is considered resolved.HjTimerEureka
instance.public <L,R> HjBinaryEureka<L,R> newBinaryEureka(HjLogicalOperator operator, HjEureka<L,Object,L> leftEureka, HjEureka<R,Object,R> rightEureka)
HjBinaryEureka
instance.newBinaryEureka
in interface HjRuntime
operator
- The maximum number of milliseconds before the eureka is considered resolved.leftEureka
- The left eureka instance.rightEureka
- The right eureka instance.HjTimerEureka
instance.public <T> HjEureka<T,T,T> retrieveEureka()
retrieveEureka
in interface HjRuntime
T
- The type of value stored in the Eurekapublic <T> void offerEureka(T eurekaValue) throws SuspendableException
offerEureka
in interface HjRuntime
T
- The type of value stored in the EurekaeurekaValue
- The value to be associated with the eurekaSuspendableException
public <T> void checkEureka(T eurekaValue) throws SuspendableException
checkEureka
in interface HjRuntime
T
- The type of value stored in the EurekaeurekaValue
- The value to be associated with the eurekaSuspendableException
public <T> T readEureka()
readEureka
in interface HjRuntime
T
- The type of value stored in the Eurekapublic void abort() throws SuspendableException
abort
in interface HjRuntime
SuspendableException
public HjEventCount newEventCount(int initialCount)
newEventCount
in interface HjRuntime
protected void runActivity(HabaneroActivity activity)
activity
- The activity to spawn.public void registerListenerForMetrics(HabaneroActivity habaneroActivity)
registerListenerForMetrics.
habaneroActivity
- a HabaneroActivity
object.Copyright © 2015 Rice University - Department of Computer Science. All rights reserved.