|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||
java.lang.Objectcom.numericalmethod.suanshu.parallel.ParallelExecutor
public class ParallelExecutor
This class provides a framework for executing an algorithm in parallel. A thread pool is created when executing a list of tasks.
| Constructor Summary | |
|---|---|
ParallelExecutor()
Creates an instance using default concurrency number, which is the number of available processors returned by
Runtime.getRuntime().availableProcessors()
|
|
ParallelExecutor(int concurrency)
Creates an instance with a specified concurrency number. |
|
| Method Summary | ||
|---|---|---|
|
conditionalForEach(boolean conditionToParallelize,
java.lang.Iterable<T> iterable,
IterationBody<T> body)
Calls forEach
only if conditionToParallelize is true. |
|
void |
conditionalForLoop(boolean conditionToParallelize,
int start,
int end,
int increment,
LoopBody body)
Runs a parallel for-loop only if conditionToParallelize is true. |
|
void |
conditionalForLoop(boolean conditionToParallelize,
int start,
int end,
LoopBody body)
Calls conditionalForLoop
with increment of 1. |
|
|
executeAll(java.util.concurrent.Callable<T>... tasks)
Executes an arbitrary number of Callable tasks, and returns a
list of results in the same order. |
|
|
executeAll(java.util.List<? extends java.util.concurrent.Callable<T>> tasks)
Executes a list of Callable tasks, and returns a list of results
in the same order. |
|
|
executeAny(java.util.concurrent.Callable<T>... tasks)
Executes a list of tasks in parallel, and returns the result from the earliest successfully completed tasks (without throwing an exception). |
|
|
executeAny(java.util.List<? extends java.util.concurrent.Callable<T>> tasks)
Executes a list of tasks in parallel, and returns the result from the earliest successfully completed tasks (without throwing an exception). |
|
|
forEach(java.lang.Iterable<T> iterable,
IterationBody<T> body)
Runs a "foreach" loop in parallel. |
|
void |
forLoop(int start,
int end,
int increment,
LoopBody body)
Runs a for-loop in parallel. |
|
void |
forLoop(int start,
int end,
LoopBody body)
Calls forLoop
with increment of 1. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public ParallelExecutor()
Runtime.getRuntime().availableProcessors()
public ParallelExecutor(int concurrency)
concurrency - the maximum number of threads can be used when executing a list of tasks| Method Detail |
|---|
public <T> java.util.List<T> executeAll(java.util.List<? extends java.util.concurrent.Callable<T>> tasks)
throws MultipleExecutionException
Callable tasks, and returns a list of results
in the same order.
T - the type of resultstasks - the list of tasks
MultipleExecutionException - if one or more tasks throws an exception
public <T> java.util.List<T> executeAll(java.util.concurrent.Callable<T>... tasks)
throws MultipleExecutionException
Callable tasks, and returns a
list of results in the same order. This is a convenient method and is the
same as calling:
executeAll(Arrays.<Callable<T>>asList(tasks));
T - the type of resultstasks - the list of tasks
MultipleExecutionException - if one or more tasks throws an exception
public <T> T executeAny(java.util.List<? extends java.util.concurrent.Callable<T>> tasks)
throws java.util.concurrent.ExecutionException
T - the type of resultstasks - the list of tasks
java.util.concurrent.ExecutionException - if no task successfully completes
public <T> T executeAny(java.util.concurrent.Callable<T>... tasks)
throws java.util.concurrent.ExecutionException
executeAny(Arrays.<Callable<T>>asList(tasks));
T - the type of resultstasks - the list of tasks
java.util.concurrent.ExecutionException - if no task successfully completes
public void forLoop(int start,
int end,
int increment,
LoopBody body)
throws MultipleExecutionException
for (int i = start; i < end; i += increment) {
body.run(i);
}
start - the first loop index (inclusive)end - the last loop index (exclusive)increment - the increment of the loop index in each iterationbody - the loop body
MultipleExecutionException - if one or more partitioned for-loop throws an exception
public void forLoop(int start,
int end,
LoopBody body)
throws MultipleExecutionException
forLoop
with increment of 1.
start - the first loop index (inclusive)end - the last loop index (exclusive)body - the loop body
MultipleExecutionException - if one or more partitioned for-loop throws an exception
public void conditionalForLoop(boolean conditionToParallelize,
int start,
int end,
int increment,
LoopBody body)
throws MultipleExecutionException
conditionToParallelize is true.
Otherwise, the loop body will be executed in a single thread.
conditionToParallelize - the condition to parallelize the for-loop executionstart - the first loop index (inclusive)end - the last loop index (exclusive)increment - the increment of the loop index in each iterationbody - the loop body
MultipleExecutionException - if one or more partitioned for-loop throws an exception
public void conditionalForLoop(boolean conditionToParallelize,
int start,
int end,
LoopBody body)
throws MultipleExecutionException
conditionalForLoop
with increment of 1.
conditionToParallelize - the condition to parallelize the for-loop executionstart - the first loop index (inclusive)end - the last loop index (exclusive)body - the loop body
MultipleExecutionException - if one or more partitioned for-loop throws an exception
public <T> void forEach(java.lang.Iterable<T> iterable,
IterationBody<T> body)
throws MultipleExecutionException
for (T item : collection) {
body.run(item);
}
T - data type of elements in iterableiterable - the Iterable collectionbody - the loop body
MultipleExecutionException - if one or more threads throws an exception
public <T> void conditionalForEach(boolean conditionToParallelize,
java.lang.Iterable<T> iterable,
IterationBody<T> body)
throws MultipleExecutionException
forEach
only if conditionToParallelize is true.
Otherwise, the loop body will be executed in a single thread.
T - data type of elements in iterableconditionToParallelize - the condition to parallelize the "foreach" executioniterable - the Iterable collectionbody - the loop body
MultipleExecutionException - if one or more threads throws an exception
|
SuanShu, a Java numerical and statistical library | |||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||