I want to spawn a certain number of tasks based on the cores that a machine has. Is there anything in Rust that can find the number of cores, or should I just run external commands and parse the output?
Open Task Manager (press Ctrl+Shift+Esc) Select Performance tab. Look for Cores and Logical Processors (Threads)
[LOW FPS] RUST ONLY USE 1 CPU CORE :: Rust General Discussions.
To calculate the total number of the core of each node = CPU SOCKET* CPU CORE.
Each CPU core can have two threads. So a processor with two cores will have four threads. A processor with eight cores will have 16 threads.
There's now a crate to do this: https://crates.io/crates/num_cpus
Add this to your Cargo.toml
:
[dependencies] num_cpus = "0.2"
Then in your source:
extern crate num_cpus; let num = num_cpus::get();
You could use std::os::num_cpus
. Example:
fn main() { println!("{}", std::os::num_cpus()); }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With