Parallelize vector group multiplication.

This commit is contained in:
Sean Bowe 2016-09-12 16:59:13 -06:00
parent 653c92a668
commit fb0d84bac2
No known key found for this signature in database
GPG Key ID: 95684257D8F8B031
4 changed files with 21 additions and 17 deletions

View File

@ -5,6 +5,7 @@ extern crate crossbeam;
extern crate rustc_serialize;
mod taupowers;
mod multicore;
mod sequences;
mod qap;
mod spairs;

17
src/multicore.rs Normal file
View File

@ -0,0 +1,17 @@
use bn::*;
use crossbeam;
pub const THREADS: usize = 8;
pub fn mul_all_by<G: Group>(v: &mut [G], c: Fr) {
crossbeam::scope(|scope| {
let window_size = v.len() / THREADS;
for i in v.chunks_mut(window_size) {
scope.spawn(move || {
for i in i {
*i = *i * c;
}
});
}
});
}

View File

@ -1,6 +1,7 @@
use bn::*;
use snark::*;
use crossbeam;
use multicore::*;
/// Evaluates the QAP A, B and C polynomials at tau given the powers of tau.
/// Converts the powers of tau in G1 and G2 into the lagrange basis with an FFT
@ -43,21 +44,12 @@ fn lagrange_coeffs<G: Group>(v: &[G], omega: Fr) -> Vec<G>
{
assert!(v.len() >= 2);
assert_eq!((v.len() / 2) * 2, v.len());
const THREADS: usize = 8;
let overd = Fr::from_str(&format!("{}", v.len())).unwrap().inverse().unwrap();
let mut tmp = fft(v, omega, THREADS);
tmp.reverse(); // coefficients are in reverse
crossbeam::scope(|scope| {
for i in tmp.chunks_mut(v.len() / THREADS) {
scope.spawn(move || {
for i in i {
*i = *i * overd;
}
});
}
});
mul_all_by(&mut tmp, overd);
tmp
}

View File

@ -3,17 +3,11 @@ use rand::Rng;
use snark::*;
use rustc_serialize::{Encodable, Encoder, Decodable, Decoder};
use sequences::*;
use multicore::*;
use taupowers::*;
pub type BlakeHash = [u8; 32];
// TODO: make more efficient using windowing
fn mul_all_by<G: Group>(v: &mut [G], c: Fr) {
for g in v {
*g = *g * c;
}
}
#[derive(Clone)]
pub struct Stage1Values {
pub vk_a: G2,