fix: compute `num_chunks` more precisely (#172)

This commit is contained in:
Han 2023-04-27 15:00:55 +08:00 committed by GitHub
parent 5a0525dc3d
commit 5f7cfcd4b6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 4 deletions

View File

@ -49,12 +49,12 @@ impl<C: CurveAffine> Argument<C> {
transcript: &mut T,
) -> Result<Committed<C>, Error> {
// Sample a random polynomial of degree n - 1
let n_threads = current_num_threads();
let n = 1usize << domain.k() as usize;
let n_chunks = n_threads + if n % n_threads != 0 { 1 } else { 0 };
let chunk_size = (n as f64 / current_num_threads() as f64).ceil() as usize;
let num_chunks = (n as f64 / chunk_size as f64).ceil() as usize;
let mut rand_vec = vec![C::Scalar::ZERO; n];
let mut thread_seeds: Vec<ChaCha20Rng> = (0..n_chunks)
let mut thread_seeds: Vec<ChaCha20Rng> = (0..num_chunks)
.into_iter()
.map(|_| {
let mut seed = [0u8; 32];
@ -65,7 +65,7 @@ impl<C: CurveAffine> Argument<C> {
thread_seeds
.par_iter_mut()
.zip_eq(rand_vec.par_chunks_mut(n / n_threads))
.zip_eq(rand_vec.par_chunks_mut(chunk_size))
.for_each(|(mut rng, chunk)| {
chunk
.iter_mut()