Skip to content

Commit f0decf3

Browse files
committed
Add parallelism
1 parent e705c42 commit f0decf3

File tree

5 files changed

+23
-19
lines changed

5 files changed

+23
-19
lines changed

circ_blocks/Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@ itertools = "0.10"
5252
petgraph = { version = "0.6", optional = true }
5353
spartan = { version = "0.8", default-features = false, optional = true }
5454
spartan_parallel = { path = "../spartan_parallel", default-features = false, features = [
55-
"multicore",
5655
"profile",
5756
] }
5857
merlin = { version = "3.0.0" }

spartan_parallel/Cargo.toml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ rand = { version = "0.8", features = ["getrandom"], default-features = false }
2020
digest = { version = "0.10", default-features = false }
2121
sha3 = { version = "0.10", default-features = false }
2222
byteorder = { version = "1", default-features = false }
23-
rayon = { version = "1", optional = true }
23+
rayon = { version = "1" }
2424
serde = { version = "1", features = ["derive"], default-features = false }
2525
bincode = { version = "1", default-features = false }
2626
subtle = { version = "2", features = ["i128"], default-features = false }
@@ -52,9 +52,8 @@ std = [
5252
"itertools/use_std",
5353
"flate2/rust_backend",
5454
]
55-
multicore = ["rayon"]
5655
profile = ["colored"]
5756

5857
[[example]]
5958
name = "interface"
60-
required-features = ["multicore", "profile"]
59+
required-features = ["profile"]

spartan_parallel/src/r1csinstance.rs

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ use flate2::{write::ZlibEncoder, Compression};
1818
use std::iter::zip;
1919
use merlin::Transcript;
2020
use serde::{Deserialize, Serialize};
21+
use rayon::prelude::*;
2122

2223
#[derive(Debug, Serialize, Deserialize, Clone)]
2324
pub struct R1CSInstance<S: SpartanExtensionField> {
@@ -243,28 +244,31 @@ impl<S: SpartanExtensionField> R1CSInstance<S> {
243244
Az.push(Vec::new());
244245
Bz.push(Vec::new());
245246
Cz.push(Vec::new());
246-
for q in 0..num_proofs[p] {
247-
let z = &z_list[q];
248247

249-
Az[p].push(vec![self.A_list[p_inst].multiply_vec_disjoint_rounds(
248+
Az[p] = (0..num_proofs[p]).into_par_iter().map(|q|
249+
vec![self.A_list[p_inst].multiply_vec_disjoint_rounds(
250250
num_cons[p_inst].clone(),
251251
max_num_inputs,
252252
num_inputs[p],
253-
z,
254-
)]);
255-
Bz[p].push(vec![self.B_list[p_inst].multiply_vec_disjoint_rounds(
253+
&z_list[q],
254+
)]
255+
).collect();
256+
Bz[p] = (0..num_proofs[p]).into_par_iter().map(|q|
257+
vec![self.B_list[p_inst].multiply_vec_disjoint_rounds(
256258
num_cons[p_inst].clone(),
257259
max_num_inputs,
258260
num_inputs[p],
259-
z,
260-
)]);
261-
Cz[p].push(vec![self.C_list[p_inst].multiply_vec_disjoint_rounds(
261+
&z_list[q],
262+
)]
263+
).collect();
264+
Cz[p] = (0..num_proofs[p]).into_par_iter().map(|q|
265+
vec![self.C_list[p_inst].multiply_vec_disjoint_rounds(
262266
num_cons[p_inst].clone(),
263267
max_num_inputs,
264268
num_inputs[p],
265-
z,
266-
)]);
267-
}
269+
&z_list[q],
270+
)]
271+
).collect();
268272
}
269273

270274
(

spartan_parallel/src/scalar/mod.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@ pub trait SpartanExtensionField:
4747
+ fmt::Debug
4848
+ Mul<Self::BaseField, Output = Self>
4949
+ MulAssign<Self::BaseField>
50+
+ Send
51+
+ Sync
5052
{
5153
/// Inner Goldilocks extension field
52-
type InnerType: ExtensionField + Field;
54+
type InnerType: ExtensionField + Field + Send + Sync;
5355

5456
/// Basefield for conserving computational resources
55-
type BaseField: Field;
57+
type BaseField: Field + Send + Sync;
5658

5759
/// Return inner Goldilocks field element
5860
fn inner(&self) -> &Self::InnerType;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
const u32 REPETITION = 10000
1+
const u32 REPETITION = 1000

0 commit comments

Comments
 (0)