jellyfish icon indicating copy to clipboard operation
jellyfish copied to clipboard

using rayon while keeping no_std support

Open alxiong opened this issue 2 years ago • 0 comments

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.

alxiong avatar Aug 18 '22 03:08 alxiong