32 releases (17 stable)
|new 1.11.1||Nov 12, 2019|
|1.10.1||Jun 10, 2019|
|1.10.0||Feb 11, 2019|
|1.9.0||Dec 11, 2018|
|0.1.0||Mar 16, 2015|
#1 in Hardware support
608,902 downloads per month
Used in 5,528 crates (374 directly)
Count the number of CPUs on the current machine.
Add to Cargo.toml:
[dependencies] num_cpus = "1.0"
extern crate num_cpus; // count logical cores this process could try to use let num = num_cpus::get();
A crate with utilities to determine the number of CPUs available on the current system.
Sometimes the CPU will exaggerate the number of CPUs it contains, because it can use processor tricks to deliver increased performance when there are more threads. This crate provides methods to get both the logical and physical numbers of cores.
This information can be used as a guide to how many tasks can be run in parallel. There are many properties of the system architecture that will affect parallelism, for example memory access speeds (for all the caches and RAM) and the physical architecture of the processor, so the number of CPUs should be used as a rough guide only.
Fetch the number of logical CPUs.
let cpus = num_cpus::get();
rayon::Threadpool for an example of where the number of CPUs could be
used when setting up parallel jobs (Where the threadpool example uses a fixed
number 8, it could use the number of CPUs).