On this page
power
Threading Control
Control CPU core usage and parallelization
By default, pymocd uses rayon, a Rust-based data-parallelism library that automatically leverages all available logical CPU threads. This is ideal for maximizing performance—but not always convenient when you need to run other tasks in parallel or are benchmarking performance under constrained conditions.
To limit CPU usage, you can set the number of threads used by pymocd with:
pymocd.set_thread_count(n)
This function should be used before starting the algorithm! (obviously!)
Using set_thread_count again in the samr code has no effect, due to static ThreadPoolBuilder initialization
You need to ‘free’ the library from memory, to setup a new number of logical threads again.
| Parameter | Type | Description |
|---|---|---|
| n | u16 | How many logical threads you want to use. |
Last updated 20 Nov 2025, 09:16 -0300 .