Documentation of 'jsat.utils.concurrent.ParallelUtils' Java class
ParallelUtils
jsat.utils.concurrent

Class ParallelUtils



  • public class ParallelUtils
    extends java.lang.Object
    • Field Summary

      Fields 
      Modifier and Type Field and Description
      static java.util.concurrent.ExecutorService CACHED_THREAD_POOL
      This object provides a re-usable source of threads for use without having to create a new thread pool.
    • Constructor Summary

      Constructors 
      Constructor and Description
      ParallelUtils() 
    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method and Description
      static int getEndBlock(int N, int ID)
      Gets the ending index (exclusive) for splitting up a list of items into SystemInfo.LogicalCores evenly sized blocks.
      static int getEndBlock(int N, int ID, int P)
      Gets the ending index (exclusive) for splitting up a list of items into P evenly sized blocks.
      static java.util.concurrent.ExecutorService getNewExecutor(boolean parallel) 
      static int getStartBlock(int N, int ID)
      Gets the starting index (inclusive) for splitting up a list of items into SystemInfo.LogicalCores evenly sized blocks.
      static int getStartBlock(int N, int ID, int P)
      Gets the starting index (inclusive) for splitting up a list of items into P evenly sized blocks.
      static java.util.stream.IntStream range(int end, boolean parallel) 
      static java.util.stream.IntStream range(int start, int end, boolean parallel) 
      static <T> T run(boolean parallel, int N, IndexReducer<T> ir, java.util.function.BinaryOperator<T> reducer) 
      static void run(boolean parallel, int N, IndexRunnable ir) 
      static void run(boolean parallel, int N, IndexRunnable ir, java.util.concurrent.ExecutorService threadPool)
      This helper method provides a convenient way to break up a computation across N items into individual indices to be processed.
      static <T> T run(boolean parallel, int N, LoopChunkReducer<T> lcr, java.util.function.BinaryOperator<T> reducer) 
      static <T> T run(boolean parallel, int N, LoopChunkReducer<T> lcr, java.util.function.BinaryOperator<T> reducer, java.util.concurrent.ExecutorService threadPool) 
      static void run(boolean parallel, int N, LoopChunkRunner lcr)
      This helper method provides a convenient way to break up a computation across N items into contiguous ranges that can be processed independently in parallel.
      static void run(boolean parallel, int N, LoopChunkRunner lcr, java.util.concurrent.ExecutorService threadPool)
      This helper method provides a convenient way to break up a computation across N items into contiguous ranges that can be processed independently in parallel.
      static java.util.stream.DoubleStream streamP(java.util.stream.DoubleStream source, boolean parallel) 
      static java.util.stream.IntStream streamP(java.util.stream.IntStream source, boolean parallel) 
      static <T> java.util.stream.Stream<T> streamP(java.util.stream.Stream<T> source, boolean parallel) 
      • Methods inherited from class java.lang.Object

        equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • CACHED_THREAD_POOL

        public static final java.util.concurrent.ExecutorService CACHED_THREAD_POOL
        This object provides a re-usable source of threads for use without having to create a new thread pool. The cached executor service is used because no threads are created until needed. If the pool is unused for a long enough time, the threads will be destroyed. This avoids the user needing to do anything. This pool is filled with daemon threads, and so will not prevent program termination.
    • Constructor Detail

      • ParallelUtils

        public ParallelUtils()
    • Method Detail

      • run

        public static void run(boolean parallel,
                               int N,
                               LoopChunkRunner lcr)
        This helper method provides a convenient way to break up a computation across N items into contiguous ranges that can be processed independently in parallel.
        Parameters:
        parallel - a boolean indicating if the work should be done in parallel. If false, it will run single-threaded. This is for code convenience so that only one set of code is needed to handle both cases.
        N - the total number of items to process
        lcr - the runnable over a contiguous range
      • run

        public static void run(boolean parallel,
                               int N,
                               LoopChunkRunner lcr,
                               java.util.concurrent.ExecutorService threadPool)
        This helper method provides a convenient way to break up a computation across N items into contiguous ranges that can be processed independently in parallel.
        Parameters:
        parallel - a boolean indicating if the work should be done in parallel. If false, it will run single-threaded. This is for code convenience so that only one set of code is needed to handle both cases.
        N - the total number of items to process.
        lcr - the runnable over a contiguous range
        threadPool - the source of threads for the computation
      • run

        public static <T> T run(boolean parallel,
                                int N,
                                LoopChunkReducer<T> lcr,
                                java.util.function.BinaryOperator<T> reducer,
                                java.util.concurrent.ExecutorService threadPool)
      • run

        public static <T> T run(boolean parallel,
                                int N,
                                LoopChunkReducer<T> lcr,
                                java.util.function.BinaryOperator<T> reducer)
      • run

        public static <T> T run(boolean parallel,
                                int N,
                                IndexReducer<T> ir,
                                java.util.function.BinaryOperator<T> reducer)
      • run

        public static void run(boolean parallel,
                               int N,
                               IndexRunnable ir)
      • run

        public static void run(boolean parallel,
                               int N,
                               IndexRunnable ir,
                               java.util.concurrent.ExecutorService threadPool)
        This helper method provides a convenient way to break up a computation across N items into individual indices to be processed. This method is meant for when the execution time of any given index is highly variable, and so for load balancing purposes, should be treated as individual jobs. If runtime is consistent, look at run(boolean, int, jsat.utils.concurrent.LoopChunkRunner, java.util.concurrent.ExecutorService).
        Parameters:
        parallel - a boolean indicating if the work should be done in parallel. If false, it will run single-threaded. This is for code convenience so that only one set of code is needed to handle both cases.
        N - the total number of items to process.
        ir - the runnable over a contiguous range
        threadPool - the source of threads for the computation
      • getNewExecutor

        public static java.util.concurrent.ExecutorService getNewExecutor(boolean parallel)
      • streamP

        public static <T> java.util.stream.Stream<T> streamP(java.util.stream.Stream<T> source,
                                                             boolean parallel)
      • streamP

        public static java.util.stream.IntStream streamP(java.util.stream.IntStream source,
                                                         boolean parallel)
      • streamP

        public static java.util.stream.DoubleStream streamP(java.util.stream.DoubleStream source,
                                                            boolean parallel)
      • range

        public static java.util.stream.IntStream range(int end,
                                                       boolean parallel)
      • range

        public static java.util.stream.IntStream range(int start,
                                                       int end,
                                                       boolean parallel)
      • getStartBlock

        public static int getStartBlock(int N,
                                        int ID,
                                        int P)
        Gets the starting index (inclusive) for splitting up a list of items into P evenly sized blocks. In the event that N is not evenly divisible by P, the size of ranges will differ by at most 1.
        Parameters:
        N - the number of items to split up
        ID - the block number in [0, P)
        P - the number of blocks to break up the items into
        Returns:
        the starting index (inclusive) of the blocks owned by the ID'th process.
      • getStartBlock

        public static int getStartBlock(int N,
                                        int ID)
        Gets the starting index (inclusive) for splitting up a list of items into SystemInfo.LogicalCores evenly sized blocks. In the event that N is not evenly divisible by SystemInfo.LogicalCores, the size of ranges will differ by at most 1.
        Parameters:
        N - the number of items to split up
        ID - the block number in [0, SystemInfo.LogicalCores)
        Returns:
        the starting index (inclusive) of the blocks owned by the ID'th process.
      • getEndBlock

        public static int getEndBlock(int N,
                                      int ID,
                                      int P)
        Gets the ending index (exclusive) for splitting up a list of items into P evenly sized blocks. In the event that N is not evenly divisible by P, the size of ranges will differ by at most 1.
        Parameters:
        N - the number of items to split up
        ID - the block number in [0, P)
        P - the number of blocks to break up the items into
        Returns:
        the ending index (exclusive) of the blocks owned by the ID'th process.
      • getEndBlock

        public static int getEndBlock(int N,
                                      int ID)
        Gets the ending index (exclusive) for splitting up a list of items into SystemInfo.LogicalCores evenly sized blocks. In the event that SystemInfo.LogicalCores is not evenly divisible by SystemInfo.LogicalCores, the size of ranges will differ by at most 1.
        Parameters:
        N - the number of items to split up
        ID - the block number in [0, SystemInfo.LogicalCores)
        Returns:
        the ending index (exclusive) of the blocks owned by the ID'th process.

DataMelt 3.0 © DataMelt by jWork.ORG

You see the box below because you did not login.