Class ThreadManager

java.lang.Object
org.flag4j.concurrency.ThreadManager

public final class ThreadManager extends Object
This class contains the base thread pool for all concurrent ops and methods for managing the pool.
  • Method Details

    • setParallelismLevel

      protected static void setParallelismLevel(int parallelismLevel)
      Sets the number of threads to use in the thread pool.
      Parameters:
      parallelismLevel - Number of threads to use in the thread pool. If this is less than 1, the parallelism will simply be set to 1.
    • getParallelismLevel

      public static int getParallelismLevel()
      Gets the current parallelism level for the ThreadManager. That is, the number of threads used in the thread pool.
      Returns:
      The current parallelism level for the ThreadManager.
    • concurrentOperation

      public static void concurrentOperation(int totalSize, TensorOperation operation)

      Computes a specified tensor operation concurrently by evenly dividing work among available threads (specified by Configurations.getNumThreads()).

      WARNING: This method provides no guarantees of thread safety. It is the responsibility of the caller to ensure that operation is thread safe.

      Parameters:
      totalSize - Total size of the outer loop for the operation.
      operation - Operation to be computed.
    • concurrentBlockedOperation

      public static void concurrentBlockedOperation(int totalSize, int blockSize, TensorOperation blockedOperation)

      Computes a specified blocked tensor operation concurrently by evenly dividing work among available threads (specified by Configurations.getNumThreads()).

      Unlike concurrentOperation(int, TensorOperation) this method respects the block size of the blocked operation. This means tasks split across threads will be aligned to block borders if possible which allows for the improved cache performance benefits of blocked ops to be fully realized. For this reason, it is not recommended to use concurrentOperation(int, TensorOperation) to compute a blocked operation concurrently.

      WARNING: This method provides no guarantees of thread safety. It is the responsibility of the caller to ensure that blockedOperation is thread safe.

      Parameters:
      totalSize - Total size of the outer loop for the operation.
      blockSize - Size of the block used in the blockedOperation.
      blockedOperation - Operation to be computed.