Package pabeles.concurrency
Class ConcurrencyOps
java.lang.Object
pabeles.concurrency.ConcurrencyOps
- Direct Known Subclasses:
EjmlConcurrency
Location of controls for turning on and off concurrent (i.e. threaded) algorithms.
-Djava.util.concurrent.ForkJoinPool.common.parallelism=16
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfacestatic interface -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intReturns the maximum number of threads which can be run at once in this poolstatic ForkJoinPoolReturns the thread pool.static <T> voidloopBlocks(int start, int endExclusive, int minBlock, GrowArray<T> workspace, IntRangeObjectConsumer<T> consumer) Splits the range of values up into blocks.static voidloopBlocks(int start, int endExclusive, int minBlock, IntRangeConsumer consumer) Automatically breaks the problem up into blocks based on the number of threads available.static <T> voidloopBlocks(int start, int endExclusive, GrowArray<T> workspace, IntRangeObjectConsumer<T> consumer) Splits the range of values up into blocks.static voidloopBlocks(int start, int endExclusive, IntRangeConsumer consumer) Splits the range of values up into blocks.static voidloopFor(int start, int endExclusive, int step, IntConsumer consumer) Concurrent for loop.static <T> voidloopFor(int start, int endExclusive, int step, GrowArray<T> workspace, IntObjectConsumer<T> consumer) Concurrent for loop.static voidloopFor(int start, int endExclusive, IntConsumer consumer) Concurrent for loop.static Numbermax(int start, int endExclusive, Class type, IntProducerNumber producer) Computes the maximum valuestatic Numbermin(int start, int endExclusive, Class type, IntProducerNumber producer) Computes the maximum valuestatic voidsetMaxThreads(int maxThreads) Changes the maximum number of threads available in the thread poolstatic Numbersum(int start, int endExclusive, Class type, IntProducerNumber producer) Computes sums up the results using the specified primitive type
-
Constructor Details
-
ConcurrencyOps
public ConcurrencyOps()
-
-
Method Details
-
setMaxThreads
public static void setMaxThreads(int maxThreads) Changes the maximum number of threads available in the thread pool- Parameters:
maxThreads- Maximum number of threads. If less than 1 it will be forced to be one
-
getMaxThreads
public static int getMaxThreads()Returns the maximum number of threads which can be run at once in this pool -
loopFor
Concurrent for loop. Each loop with spawn as a thread up to the maximum number of threads.- Parameters:
start- starting value, inclusiveendExclusive- ending value, exclusiveconsumer- The consumer
-
loopFor
Concurrent for loop. Each loop with spawn as a thread up to the maximum number of threads.- Parameters:
start- starting value, inclusiveendExclusive- ending value, exclusivestep- fixed sized step for each iterationconsumer- The consumer
-
loopFor
public static <T> void loopFor(int start, int endExclusive, int step, GrowArray<T> workspace, IntObjectConsumer<T> consumer) Concurrent for loop. Each loop with spawn as a thread up to the maximum number of threads.- Parameters:
start- starting value, inclusiveendExclusive- ending value, exclusivestep- fixed sized step for each iterationconsumer- The consumer
-
loopBlocks
Automatically breaks the problem up into blocks based on the number of threads available. It is assumed that there is some cost associated with processing a block and the number of blocks is minimized. Examples:- Given a range of 0 to 100, and minBlock is 5, and 10 threads. Blocks will be size 10.
- Given a range of 0 to 100, and minBlock is 20, and 10 threads. Blocks will be size 20.
- Given a range of 0 to 100, and minBlock is 15, and 10 threads. Blocks will be size 16 and 20.
- Given a range of 0 to 100, and minBlock is 80, and 10 threads. Blocks will be size 100.
- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusiveminBlock- Minimum size of a blockconsumer- The consumer
-
loopBlocks
Splits the range of values up into blocks. It's assumed the cost to process a block is small so more can be created.- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusiveconsumer- The consumer
-
loopBlocks
public static <T> void loopBlocks(int start, int endExclusive, GrowArray<T> workspace, IntRangeObjectConsumer<T> consumer) Splits the range of values up into blocks. For each block workspace data will be declared using aGrowArrayand passed on. This workspace can be used to collect results and combine later on- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusiveconsumer- The consumer
-
loopBlocks
public static <T> void loopBlocks(int start, int endExclusive, int minBlock, GrowArray<T> workspace, IntRangeObjectConsumer<T> consumer) Splits the range of values up into blocks. For each block workspace data will be declared using aGrowArrayand passed on. This workspace can be used to collect results and combine later on- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusiveminBlock- Minimum size of a blockconsumer- The consumer
-
sum
Computes sums up the results using the specified primitive type- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusivetype- Primtive data type, e.g. int.class, float.class, double.classproducer- Given an integer input produce a Number output- Returns:
- The sum
-
max
Computes the maximum value- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusivetype- Primtive data type, e.g. int.class, float.class, double.classproducer- Given an integer input produce a Number output- Returns:
- The sum
-
min
Computes the maximum value- Parameters:
start- First index, inclusiveendExclusive- Last index, exclusivetype- Primtive data type, e.g. int.class, float.class, double.classproducer- Given an integer input produce a Number output- Returns:
- The sum
-
getThreadPool
Returns the thread pool.
-