Why is rust's rayon taking longer with Arc<Mutex<anyhow::Result<()>>>?

I am trying to parallelize my codes using the crate rayon. The process is to read a file, process it and output the processed file. I want to take note of the result of the processing of each file such that I have an Arc<Mutex<Vec<anyhow::Result<()>>>> which I lock and push each anyhow::Result<()> resulting from the… Read More Why is rust's rayon taking longer with Arc<Mutex<anyhow::Result<()>>>?

Is rayon's parallelism limited to the cores of the machine?

I have the following toy Rust program: use rayon::prelude::*; use std::{env, thread, time}; /// Sleeps 1 second n times fn seq_sleep(n: usize) { for _ in 0..n { thread::sleep(time::Duration::from_millis(1000)); } } /// Launches n threads that sleep 1 second fn thread_sleep(n: usize) { let mut handles = Vec::new(); for _ in 0..n { handles.push(thread::spawn(|| {… Read More Is rayon's parallelism limited to the cores of the machine?

Rayon support for itertools tuple_combinations

I’m trying to use Rayon‘s par_iter over a TupleCombinations struct from itertools as in the code below. use itertools::Itertools; use rayon::prelude::*; fn main() { let v: Vec<i32> = vec!(1, 2, 3); let t = v.iter().tuple_combinations::<(_, _)>(); let sum: i32 = t.par_iter().map(|&(i, j)| i * j).sum(); println!("{}", sum); } The problem is that Rayon seems to… Read More Rayon support for itertools tuple_combinations