jellyfish
jellyfish copied to clipboard
using rayon while keeping no_std support
Currently, I implemented a very simplistic to optionally turn on rayon
and use its par_iter()
:
/// # Usage
/// let v = [1, 2, 3, 4, 5];
/// let sum = parallelizable_slice_iter(&v).sum();
///
/// // the above code is a shorthand for (thus equivalent to)
/// #[cfg(feature = "parallel")]
/// let sum = v.par_iter().sum();
/// #[cfg(not(feature = "parallel"))]
/// let sum = v.iter().sum();
#[cfg(feature = "parallel")]
pub fn parallelizable_slice_iter<T: Sync>(data: &[T]) -> rayon::slice::Iter<T> {
use rayon::iter::IntoParallelIterator;
data.into_par_iter()
}
#[cfg(not(feature = "parallel"))]
pub fn parallelizable_slice_iter<T>(data: &[T]) -> ark_std::slice::Iter<T> {
data.iter()
}
but there's already an existing, better, more comprehensive solution by plonky2 team: maybe_rayon
given that they recently added MIT + Apache2 license, we should consider switching to that.