Skip to content

Commit 5bf0798

Browse files
committed
Add rayon
1 parent 2b901a6 commit 5bf0798

File tree

3 files changed

+13
-15
lines changed

3 files changed

+13
-15
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: 1 addition & 2 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 }
@@ -53,7 +53,6 @@ std = [
5353
"itertools/use_std",
5454
"flate2/rust_backend",
5555
]
56-
multicore = ["rayon"]
5756
profile = ["colored"]
5857

5958
[[example]]

spartan_parallel/src/sparse_mlpoly.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ use super::timer::Timer;
1414
use super::transcript::{AppendToTranscript, ProofTranscript};
1515
use core::cmp::Ordering;
1616
use merlin::Transcript;
17+
use rayon::prelude::*;
1718
use serde::{Deserialize, Serialize};
18-
use std::sync::Arc;
19+
use std::sync::{Arc, Mutex};
1920

2021
#[derive(Clone, Debug, Serialize, Deserialize)]
2122
pub struct SparseMatEntry<S: SpartanExtensionField> {
@@ -415,20 +416,19 @@ impl<S: SpartanExtensionField> SparseMatPolynomial<S> {
415416
p: usize,
416417
q: usize,
417418
) -> Vec<S> {
419+
let res = Arc::new(Mutex::new(vec![S::field_zero(); num_rows]));
420+
418421
(0..inst.A_list[p_inst].M.len())
419-
.map(|i| {
422+
.into_par_iter()
423+
.for_each(|i| {
420424
let row = inst.A_list[p_inst].M[i].row;
421425
let col = inst.A_list[p_inst].M[i].col;
422-
let val = &inst.A_list[p_inst].M[i].val;
423-
(
424-
row,
425-
*val * z_mat[p][q][col / max_num_cols][col % max_num_cols],
426-
)
427-
})
428-
.fold(vec![S::field_zero(); num_rows], |mut Mz, (r, v)| {
429-
Mz[r] = Mz[r] + v;
430-
Mz
431-
})
426+
let val = inst.A_list[p_inst].M[i].val;
427+
let mut Mz = res.lock().unwrap();
428+
Mz[row] += val * z_mat[p][q][col / max_num_cols][col % max_num_cols]
429+
});
430+
let vec = res.lock().unwrap();
431+
vec.clone()
432432
}
433433

434434
// Z is consisted of vector segments

0 commit comments

Comments
 (0)