Skip to content

Commit

Permalink
Migrate bellman to crossbeam 0.7
Browse files Browse the repository at this point in the history
  • Loading branch information
str4d committed Sep 12, 2019
1 parent 1775843 commit c063509
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ futures = "0.1"
futures-cpupool = { version = "0.1", optional = true }
group = { path = "../group" }
num_cpus = { version = "1", optional = true }
crossbeam = { version = "0.3", optional = true }
crossbeam = { version = "0.7", optional = true }
pairing = { path = "../pairing", optional = true }
rand_core = "0.5"
byteorder = "1"
Expand Down
14 changes: 7 additions & 7 deletions src/domain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
let minv = self.minv;

for v in self.coeffs.chunks_mut(chunk) {
scope.spawn(move || {
scope.spawn(move |_scope| {
for v in v {
v.group_mul_assign(&minv);
}
Expand All @@ -103,7 +103,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
pub fn distribute_powers(&mut self, worker: &Worker, g: E::Fr) {
worker.scope(self.coeffs.len(), |scope, chunk| {
for (i, v) in self.coeffs.chunks_mut(chunk).enumerate() {
scope.spawn(move || {
scope.spawn(move |_scope| {
let mut u = g.pow(&[(i * chunk) as u64]);
for v in v.iter_mut() {
v.group_mul_assign(&u);
Expand Down Expand Up @@ -146,7 +146,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {

worker.scope(self.coeffs.len(), |scope, chunk| {
for v in self.coeffs.chunks_mut(chunk) {
scope.spawn(move || {
scope.spawn(move |_scope| {
for v in v {
v.group_mul_assign(&i);
}
Expand All @@ -165,7 +165,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
.chunks_mut(chunk)
.zip(other.coeffs.chunks(chunk))
{
scope.spawn(move || {
scope.spawn(move |_scope| {
for (a, b) in a.iter_mut().zip(b.iter()) {
a.group_mul_assign(&b.0);
}
Expand All @@ -184,7 +184,7 @@ impl<E: ScalarEngine, G: Group<E>> EvaluationDomain<E, G> {
.chunks_mut(chunk)
.zip(other.coeffs.chunks(chunk))
{
scope.spawn(move || {
scope.spawn(move |_scope| {
for (a, b) in a.iter_mut().zip(b.iter()) {
a.group_sub_assign(&b);
}
Expand Down Expand Up @@ -335,7 +335,7 @@ fn parallel_fft<E: ScalarEngine, T: Group<E>>(
let a = &*a;

for (j, tmp) in tmp.iter_mut().enumerate() {
scope.spawn(move || {
scope.spawn(move |_scope| {
// Shuffle into a sub-FFT
let omega_j = omega.pow(&[j as u64]);
let omega_step = omega.pow(&[(j as u64) << log_new_n]);
Expand Down Expand Up @@ -363,7 +363,7 @@ fn parallel_fft<E: ScalarEngine, T: Group<E>>(
let tmp = &tmp;

for (idx, a) in a.chunks_mut(chunk).enumerate() {
scope.spawn(move || {
scope.spawn(move |_scope| {
let mut idx = idx * chunk;
let mask = (1 << log_cpus) - 1;
for a in a {
Expand Down
6 changes: 3 additions & 3 deletions src/groth16/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ where
let powers_of_tau = powers_of_tau.as_mut();
worker.scope(powers_of_tau.len(), |scope, chunk| {
for (i, powers_of_tau) in powers_of_tau.chunks_mut(chunk).enumerate() {
scope.spawn(move || {
scope.spawn(move |_scope| {
let mut current_tau_power = tau.pow(&[(i * chunk) as u64]);

for p in powers_of_tau {
Expand All @@ -251,7 +251,7 @@ where
{
let mut g1_wnaf = g1_wnaf.shared();

scope.spawn(move || {
scope.spawn(move |_scope| {
// Set values of the H query to g1^{(tau^i * t(tau)) / delta}
for (h, p) in h.iter_mut().zip(p.iter()) {
// Compute final exponent
Expand Down Expand Up @@ -330,7 +330,7 @@ where
let mut g1_wnaf = g1_wnaf.shared();
let mut g2_wnaf = g2_wnaf.shared();

scope.spawn(move || {
scope.spawn(move |_scope| {
for ((((((a, b_g1), b_g2), ext), at), bt), ct) in a
.iter_mut()
.zip(b_g1.iter_mut())
Expand Down
8 changes: 5 additions & 3 deletions src/multicore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
#[cfg(feature = "multicore")]
mod implementation {
use crossbeam::{self, Scope};
use crossbeam::{self, thread::Scope};
use futures::{Future, IntoFuture, Poll};
use futures_cpupool::{CpuFuture, CpuPool};
use num_cpus;
Expand Down Expand Up @@ -59,7 +59,9 @@ mod implementation {
elements / self.cpus
};

// TODO: Handle case where threads fail
crossbeam::scope(|scope| f(scope, chunk_size))
.expect("Threads aren't allowed to fail yet")
}
}

Expand Down Expand Up @@ -152,8 +154,8 @@ mod implementation {
pub struct DummyScope;

impl DummyScope {
pub fn spawn<F: FnOnce()>(&self, f: F) {
f();
pub fn spawn<F: FnOnce(&DummyScope)>(&self, f: F) {
f(self);
}
}
}
Expand Down

0 comments on commit c063509

Please sign in to comment.