Skip to content

Commit 426582b

Browse files
committed
Method consistency
1 parent 5bf0798 commit 426582b

File tree

1 file changed

+20
-22
lines changed

1 file changed

+20
-22
lines changed

spartan_parallel/src/sparse_mlpoly.rs

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -444,20 +444,19 @@ impl<S: SpartanExtensionField> SparseMatPolynomial<S> {
444444
p: usize,
445445
q: usize,
446446
) -> Vec<S> {
447+
let res = Arc::new(Mutex::new(vec![S::field_zero(); num_rows]));
448+
447449
(0..inst.B_list[p_inst].M.len())
448-
.map(|i| {
450+
.into_par_iter()
451+
.for_each(|i| {
449452
let row = inst.B_list[p_inst].M[i].row;
450453
let col = inst.B_list[p_inst].M[i].col;
451-
let val = &inst.B_list[p_inst].M[i].val;
452-
(
453-
row,
454-
*val * z_mat[p][q][col / max_num_cols][col % max_num_cols],
455-
)
456-
})
457-
.fold(vec![S::field_zero(); num_rows], |mut Mz, (r, v)| {
458-
Mz[r] = Mz[r] + v;
459-
Mz
460-
})
454+
let val = inst.B_list[p_inst].M[i].val;
455+
let mut Mz = res.lock().unwrap();
456+
Mz[row] += val * z_mat[p][q][col / max_num_cols][col % max_num_cols]
457+
});
458+
let vec = res.lock().unwrap();
459+
vec.clone()
461460
}
462461

463462
// Z is consisted of vector segments
@@ -473,20 +472,19 @@ impl<S: SpartanExtensionField> SparseMatPolynomial<S> {
473472
p: usize,
474473
q: usize,
475474
) -> Vec<S> {
475+
let res = Arc::new(Mutex::new(vec![S::field_zero(); num_rows]));
476+
476477
(0..inst.C_list[p_inst].M.len())
477-
.map(|i| {
478+
.into_par_iter()
479+
.for_each(|i| {
478480
let row = inst.C_list[p_inst].M[i].row;
479481
let col = inst.C_list[p_inst].M[i].col;
480-
let val = &inst.C_list[p_inst].M[i].val;
481-
(
482-
row,
483-
*val * z_mat[p][q][col / max_num_cols][col % max_num_cols],
484-
)
485-
})
486-
.fold(vec![S::field_zero(); num_rows], |mut Mz, (r, v)| {
487-
Mz[r] = Mz[r] + v;
488-
Mz
489-
})
482+
let val = inst.C_list[p_inst].M[i].val;
483+
let mut Mz = res.lock().unwrap();
484+
Mz[row] += val * z_mat[p][q][col / max_num_cols][col % max_num_cols]
485+
});
486+
let vec = res.lock().unwrap();
487+
vec.clone()
490488
}
491489

492490
pub fn compute_eval_table_sparse(&self, rx: &[S], num_rows: usize, num_cols: usize) -> Vec<S> {

0 commit comments

Comments
 (0)