public class ParallelLoop
extends java.lang.Object
ForkJoinPool. The range [0, n) is divided into contiguous
chunks, each of which is passed to a ParallelLoop.RangeBody. Since each chunk is
executed by a single thread, bodies can allocate per-chunk scratch storage
without needing thread-local variables.| Modifier and Type | Class and Description |
|---|---|
static interface |
ParallelLoop.RangeBody
Body of a parallel loop, called for the index sub-range
[lo, hi). |
| Constructor and Description |
|---|
ParallelLoop() |
| Modifier and Type | Method and Description |
|---|---|
static void |
forRange(int n,
int minChunk,
ParallelLoop.RangeBody body)
Executes
body over the range [0, n), dividing the range
into contiguous chunks that are processed in parallel. |
static int |
getNumThreads()
Queries the number of threads used for parallel loops.
|
static int |
numChunks(int n,
int minChunk)
Returns the number of chunks that
forRange(int, int, maspack.concurrency.ParallelLoop.RangeBody) will use for a
given range size and minimum chunk size. |
static void |
setNumThreads(int num)
Sets the number of threads used for parallel loops.
|
public static void setNumThreads(int num)
<= 1
causes loops to be executed serially in the calling thread.num - number of threadspublic static int getNumThreads()
public static int numChunks(int n,
int minChunk)
forRange(int, int, maspack.concurrency.ParallelLoop.RangeBody) will use for a
given range size and minimum chunk size.n - range sizeminChunk - minimum chunk sizepublic static void forRange(int n,
int minChunk,
ParallelLoop.RangeBody body)
body over the range [0, n), dividing the range
into contiguous chunks that are processed in parallel. If only one
chunk is needed, body is called directly in the calling thread.
The method returns after all chunks have completed. Any exception thrown
by a chunk is rethrown in the calling thread.n - range sizeminChunk - minimum size of each chunkbody - loop body