I'm using the Rayon library:
extern crate rayon;
const N: usize = 1_000_000_000;
const W: f64 = 1f64/(N as f64);
fn f(x: f64) -> f64 {
4.0/(1.0+x*x)
}
fn main() {
use rayon::prelude::*;
let sum : f64 = (0..N)
.into_par_iter()
.map(|i| f(W*((i as f64)+0.5)))
.sum::<f64>();
println!("pi = {}", W*sum);
}
I want to run this code using different number of threads: 1, 2, 3 and 4.
I have read the documentation about How many threads will Rayon spawn? which says:
By default, Rayon uses the same number of threads as the number of CPUs available. Note that on systems with hyperthreading enabled this equals the number of logical cores and not the physical ones.
If you want to alter the number of threads spawned, you can set the environmental variable
RAYON_NUM_THREADS
to the desired number of threads or use theThreadPoolBuilder::build_global
function method.
However, the steps are not clear for me. How can I do this on my Windows 10 PC?