Threading Functions¶
Functions for configuring the global thread pool used for parallel computation.
Thread Pool Configuration¶
set_num_threads builtin ¶
Set the number of threads for parallel computation.
Configures the global thread pool used by Brahe for parallel operations such as access computations. This function can be called multiple times to dynamically change the thread pool configuration - each call will reinitialize the pool with the new thread count.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
n | int | Number of threads to use. Must be at least 1. | required |
Raises:
| Type | Description |
|---|---|
ValueError | If n < 1. |
RuntimeError | If thread pool fails to build. |
Example
Note
Unlike earlier versions, this function no longer raises an error if the thread pool has already been initialized. You can safely call it at any time to reconfigure the thread pool.
set_max_threads builtin ¶
set_max_threads() -> Any
Set the thread pool to use all available CPU cores.
This is a convenience function that sets the number of threads to 100% of available CPU cores. Can be called multiple times to reinitialize the thread pool dynamically.
Raises:
| Type | Description |
|---|---|
RuntimeError | If thread pool fails to build. |
Example
Note
This function can be called at any time, even after the thread pool has been initialized with a different configuration.
set_ludicrous_speed builtin ¶
set_ludicrous_speed() -> Any
LUDICROUS SPEED! GO!
Set the thread pool to use all available CPU cores (alias for set_max_threads).
This is a fun alias for set_max_threads() that sets the number of threads to 100% of available CPU cores for maximum performance. Can be called multiple times to dynamically reinitialize the thread pool.
Raises:
| Type | Description |
|---|---|
RuntimeError | If thread pool fails to build. |
Example
Note
This function can be called at any time to reconfigure the thread pool to use maximum available cores, regardless of previous configuration.
get_max_threads builtin ¶
get_max_threads() -> int
Get the current maximum number of threads for parallel computation.
Returns the number of threads configured for the global thread pool. If the thread pool hasn't been initialized yet, this initializes it with the default (90% of available cores) and returns that value.
Returns:
| Name | Type | Description |
|---|---|---|
int | int | Number of threads currently configured. |
Example
Note
Calling this function will initialize the thread pool with default settings (90% of cores) if it hasn't been configured yet. After initialization, you can still reconfigure it using set_num_threads() or set_max_threads().