Class ConcurrencyOps

java.lang.Object
pabeles.concurrency.ConcurrencyOps
Direct Known Subclasses:
EjmlConcurrency

public class ConcurrencyOps
extends Object
Location of controls for turning on and off concurrent (i.e. threaded) algorithms. -Djava.util.concurrent.ForkJoinPool.common.parallelism=16
  • 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

      public static void loopFor​(int start, int endExclusive, IntConsumer consumer)
      Concurrent for loop. Each loop with spawn as a thread up to the maximum number of threads.
      Parameters:
      start - starting value, inclusive
      endExclusive - ending value, exclusive
      consumer - The consumer
    • loopFor

      public static void loopFor​(int start, int endExclusive, int step, IntConsumer consumer)
      Concurrent for loop. Each loop with spawn as a thread up to the maximum number of threads.
      Parameters:
      start - starting value, inclusive
      endExclusive - ending value, exclusive
      step - fixed sized step for each iteration
      consumer - 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, inclusive
      endExclusive - ending value, exclusive
      step - fixed sized step for each iteration
      consumer - The consumer
    • loopBlocks

      public static void loopBlocks​(int start, int endExclusive, int minBlock, IntRangeConsumer consumer)
      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, inclusive
      endExclusive - Last index, exclusive
      minBlock - Minimum size of a block
      consumer - The consumer
    • loopBlocks

      public static void loopBlocks​(int start, int endExclusive, IntRangeConsumer consumer)
      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, inclusive
      endExclusive - Last index, exclusive
      consumer - 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 a GrowArray and passed on. This workspace can be used to collect results and combine later on
      Parameters:
      start - First index, inclusive
      endExclusive - Last index, exclusive
      consumer - 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 a GrowArray and passed on. This workspace can be used to collect results and combine later on
      Parameters:
      start - First index, inclusive
      endExclusive - Last index, exclusive
      minBlock - Minimum size of a block
      consumer - The consumer
    • sum

      public static Number sum​(int start, int endExclusive, Class type, IntProducerNumber producer)
      Computes sums up the results using the specified primitive type
      Parameters:
      start - First index, inclusive
      endExclusive - Last index, exclusive
      type - Primtive data type, e.g. int.class, float.class, double.class
      producer - Given an integer input produce a Number output
      Returns:
      The sum
    • max

      public static Number max​(int start, int endExclusive, Class type, IntProducerNumber producer)
      Computes the maximum value
      Parameters:
      start - First index, inclusive
      endExclusive - Last index, exclusive
      type - Primtive data type, e.g. int.class, float.class, double.class
      producer - Given an integer input produce a Number output
      Returns:
      The sum
    • min

      public static Number min​(int start, int endExclusive, Class type, IntProducerNumber producer)
      Computes the maximum value
      Parameters:
      start - First index, inclusive
      endExclusive - Last index, exclusive
      type - Primtive data type, e.g. int.class, float.class, double.class
      producer - Given an integer input produce a Number output
      Returns:
      The sum
    • getThreadPool

      public static ForkJoinPool getThreadPool()
      Returns the thread pool.