木綿(momen) is low overhead thread pool library. 木綿(momen) means cotton in Japanese.

Usage

rust fn daxpy(alpha: f64, x: &[f64], y: &mut [f64]) { y.iter_mut().zip(x.iter()).for_each(|(y, x)| *y += alpha * *x); } let thread_pool = momen::ThreadPoolDyn::new(); let n = thread_pool.max_len(); let mut x = Vec::with_capacity(1000); let mut y = vec![0f64; 1000]; for i in 0..1000 { x.push(i as f64); } let chunck_size = (1000 + n - 1) / n; let mut v = x.chunks(chunck_size).zip(y.chunks_mut(chunck_size)).collect::<Vec<_>>(); let alpha = std::f64::consts::PI; thread_pool.run(&mut v, &|(x, y)| daxpy(alpha, x, y)); for i in 0..1000 { assert_eq!(alpha * x[i], y[i]); }

benchmark

Gnuplot Produced by GNUPLOT 5.2 patchlevel 2 0.1 1 10 100 1000 100000 1x106 1x107 Average time (µs) Input Size (Bytes) copy: Comparison Rayon Rayon gnuplot_plot_2 Rayon chunk Rayon chunk gnuplot_plot_4 Reference Reference gnuplot_plot_6 ThreadPool ThreadPool gnuplot_plot_8 ThreadPoolDyn ThreadPoolDyn gnuplot_plot_10