Package org.flag4j.concurrency
Class ThreadManager
java.lang.Object
org.flag4j.concurrency.ThreadManager
This class contains the base thread pool for all concurrent operations and several methods for managing the
pool.
-
Nested Class Summary
-
Field Summary
Modifier and TypeFieldDescriptionprivate static final ThreadFactory
Simple thread factory for creating basic daemon threads.private static int
The parallelism level for the thread manager.private static final Logger
Simple logger for when a thread throws an exception during execution.private static ThreadPoolExecutor
Thread pool for managing threads executing concurrent operations. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
concurrentBlockedOperation
(int totalSize, int blockSize, TensorOperation blockedOperation) Computes a specified blocked tensor operation concurrently by evenly dividing work amoung available threads (specified byConfigurations.getNumThreads()
).static void
concurrentOperation
(int totalSize, TensorOperation operation) Computes a specified tensor operation concurrently by evenly dividing work amoung available threads (specified byConfigurations.getNumThreads()
).static void
concurrentOperation
(int totalTasks, ThreadManager.TriConsumer<Integer, Integer, Integer> task) Executes a concurrent operation on a given range of indices.static int
Gets the current parallelism level for the ThreadManager.protected static void
setParallelismLevel
(int parallelismLevel) Sets the number of threads to use in the thread pool.
-
Field Details
-
daemonFactory
Simple thread factory for creating basic daemon threads. -
parallelismLevel
private static int parallelismLevelThe parallelism level for the thread manager. That is, the number of threads to be used in the thread pool when executing concurrent operations. -
threadLogger
Simple logger for when a thread throws an exception during execution. -
threadPool
Thread pool for managing threads executing concurrent operations.
-
-
Constructor Details
-
ThreadManager
private ThreadManager()
-
-
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
Computes a specified tensor operation concurrently by evenly dividing work amoung available threads (specified byConfigurations.getNumThreads()
).- 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 amoung available threads (specified byConfigurations.getNumThreads()
).- Parameters:
totalSize
- Total size of the outer loop for the operation.blockSize
- Size of the block used in the blocekdOperation.blockedOperation
- Operation to be computed.
-
concurrentOperation
public static void concurrentOperation(int totalTasks, ThreadManager.TriConsumer<Integer, Integer, Integer> task) Executes a concurrent operation on a given range of indices. The operation is split across multiple threads, each handling a subset of the range.- Parameters:
totalTasks
- The total number of tasks (e.g., rows in a matrix) to be processed.task
- A lambda expression or function that takes three arguments: start index, end index, and thread ID. This function represents the work to be done by each thread for its assigned range.
-