Multithreading¶
Brahe uses a global thread pool to parallelize computationally intensive operations, such as computing access windows between satellites and ground locations. The threading utilities allow you to configure the number of threads used by the thread pool.
For complete API details, see the Threading API Reference.
Default Behavior¶
By default, Brahe automatically configures the thread pool to use 90% of available CPU cores on first use. This greatly accelerates computations while leaving some resources for other processes to avoid resource-starving other processes on the machine.
For example, on a system with 8 CPU cores, Brahe will use 7 threads by default.
Lazy Initialization
The thread pool is initialized on first use, not when you import Brahe. This means the default thread count is determined when you first call a function that uses the thread pool.
You can configure the thread pool before first use to override the default behavior by calling set_num_threads() or set_max_threads() as shown below.
Thread Safety
All Brahe functions are thread-safe. You can safely call Brahe functions from multiple threads simultaneously.
Setting Thread Count¶
Set Specific Number¶
You can set the thread pool to use a specific number of threads:
Set Maximum Threads¶
To use all available CPU cores (100%), use set_max_threads():
When to Use Maximum Threads
Use set_max_threads() when Brahe is the sole computational task running on a server and you want to maximize throughput.
Ludicrous Speed!¶
For a bit of fun, there's an alias for set_max_threads():
Querying Thread Count¶
You can check the current thread pool configuration at any time:
Reconfiguring the Thread Pool¶
The thread pool can be reconfigured at any time during program execution. Simply call set_num_threads() or set_max_threads() again with the new desired configuration:
Complete Example¶
Here's a complete example demonstrating all threading configuration functions:
See Also¶
- Utilities Overview - Overview of all utilities
- Threading API Reference - Complete threading function documentation