Function num_cpus::get_physical [] [src]

pub fn get_physical() -> usize

Returns the number of physical cores of the current system.

Note

Physical count is supported only on Linux, mac OS and Windows platforms. On other platforms, or if the physical count fails on supported platforms, this function returns the same as get(), which is the number of logical CPUS.

Examples

let logical_cpus = num_cpus::get();
let physical_cpus = num_cpus::get_physical();
if logical_cpus > physical_cpus {
    println!("We have simultaneous multithreading with about {:.2} \
              logical cores to 1 physical core.", 
              (logical_cpus as f64) / (physical_cpus as f64));
} else if logical_cpus == physical_cpus {
    println!("Either we don't have simultaneous multithreading, or our \
              system doesn't support getting the number of physical CPUs.");
} else {
    println!("We have less logical CPUs than physical CPUs, maybe we only have access to \
              some of the CPUs on our system.");
}