From 00a7c93ea049317e28087edd43d37027247b5a39 Mon Sep 17 00:00:00 2001 From: Sean Bowe Date: Sat, 17 Sep 2016 12:17:41 -0600 Subject: [PATCH] Multithread the last step of the FFT. --- src/protocol/qap.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/src/protocol/qap.rs b/src/protocol/qap.rs index 6ae26cc..cceed42 100644 --- a/src/protocol/qap.rs +++ b/src/protocol/qap.rs @@ -94,11 +94,26 @@ fn fft(v: &[G], omega: Fr, threads: usize) -> Vec (rx_evens.recv().unwrap(), rx_odds.recv().unwrap()) }; - let mut acc = omega; let mut res = Vec::with_capacity(v.len()); - for i in 0..v.len() { - res.push(evens[i%d2] + odds[i%d2] * acc); - acc = acc * omega; + if threads < 2 { + let mut acc = omega; + for i in 0..v.len() { + res.push(evens[i%d2] + odds[i%d2] * acc); + acc = acc * omega; + } + } else { + res.extend_from_slice(&evens); + res.extend_from_slice(&evens); + + parallel(&mut res, |mut i, v| { + let mut acc = omega.pow(Fr::from_str(&format!("{}", i+1)).unwrap()); + + for a in v { + *a = *a + odds[i%d2] * acc; + acc = acc * omega; + i += 1; + } + }, threads); } res