|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.knowceans.topics.cgen.ParallelFor
public abstract class ParallelFor
ParallelFor implements what in OpenMP is called a parallel for loop, i.e., a loop that executes in parallel on several threads with a barrier (join) at the end. Implementors simply subclass and implement the process() method and make sure the loop() method is not called while a loop of one instance is running. Execution can be stopped using stop(), which completes the iterations currently running. After the last usage of the class, it should be shut down properly using function shutdown() or the hard way using System.exit();
Field Summary | |
---|---|
protected boolean |
isStopping
stop flag |
protected java.util.concurrent.atomic.AtomicInteger |
iteration
current item index |
protected int |
nthreads
number of threads = number of processors / cores |
(package private) static long |
start
|
(package private) static java.util.concurrent.atomic.AtomicInteger |
test
|
protected java.util.concurrent.ExecutorService |
threadpool
pool of threads spread over processors |
Constructor Summary | |
---|---|
ParallelFor()
instantiate with as many threads as there are processors and block-wise execution |
|
ParallelFor(int nthreads)
number of threads and mode: 1 = serial, negative = element-wise, positive = block-wise execution |
Method Summary | |
---|---|
void |
loop(int range)
Loop through all iterations. |
void |
loopOnce(int N)
loops once, then shuts down |
static void |
main(java.lang.String[] args)
|
abstract void |
process(int iteration,
int thread)
processing method |
void |
shutdown()
shut down the thread pool after final usage |
void |
stop()
stop loop execution |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
protected int nthreads
protected java.util.concurrent.atomic.AtomicInteger iteration
protected java.util.concurrent.ExecutorService threadpool
protected boolean isStopping
static java.util.concurrent.atomic.AtomicInteger test
static long start
Constructor Detail |
---|
public ParallelFor()
public ParallelFor(int nthreads)
nthreads
- Method Detail |
---|
public void loop(int range)
range
- public void shutdown()
public void loopOnce(int N) throws java.lang.InterruptedException
N
-
java.lang.InterruptedException
public void stop()
public abstract void process(int iteration, int thread)
iteration
- thread
- public static void main(java.lang.String[] args) throws java.lang.InterruptedException
java.lang.InterruptedException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |