How many CPU cores can you use in parallel?

When it comes to determining the number of CPU cores to use for a parallel program, the advice seems straightforward: match the thread or process pool size to the number of CPU cores on your machine. However, it turns out to be more complicated than that. The Python standard library offers APIs to get this information, but they are not sufficient. Additionally, factors like CPU features and the code you have written can affect the number of cores you can effectively use. Logical CPUs and physical CPUs also come into play, with logical cores allowing for more parallelism. Ultimately, determining the optimal number of threads or cores for a program requires empirical measurement. By measuring the run time for different numbers of threads, you can find the optimal level of parallelism for your specific code.

https://pythonspeed.com/articles/cpu-thread-pool-size/

To top