Skip to content

Commit 223319a

Browse files
committed
Use threadpool
1 parent 58e0c56 commit 223319a

File tree

3 files changed

+19
-8
lines changed

3 files changed

+19
-8
lines changed

circ_blocks/Cargo.lock

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

spartan_parallel/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ colored = { version = "2", default-features = false, optional = true }
3030
flate2 = { version = "1" }
3131
goldilocks = { git = "https://github.com/scroll-tech/ceno-Goldilocks" }
3232
ff = "0.13.0"
33+
threadpool = "1.8"
3334

3435
[dev-dependencies]
3536
criterion = "0.5"

spartan_parallel/src/r1csinstance.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ use std::iter::zip;
1919
use merlin::Transcript;
2020
use serde::{Deserialize, Serialize};
2121

22+
use threadpool::ThreadPool;
2223
use std::sync::{Arc, Mutex};
2324
use std::thread;
2425

@@ -238,7 +239,7 @@ impl<S: SpartanExtensionField + 'static> R1CSInstance<S> {
238239
let Bz: Arc<Mutex<Vec<Vec<Vec<Vec<S>>>>>> = Arc::new(Mutex::new(vec![Vec::new(); num_instances]));
239240
let Cz: Arc<Mutex<Vec<Vec<Vec<Vec<S>>>>>> = Arc::new(Mutex::new(vec![Vec::new(); num_instances]));
240241

241-
let mut instance_threads = vec![];
242+
let pool = ThreadPool::new(1000);
242243

243244
// Non-zero instances
244245
for p in 0..num_instances {
@@ -254,7 +255,10 @@ impl<S: SpartanExtensionField + 'static> R1CSInstance<S> {
254255
let inst = Arc::clone(&inst);
255256
let z_mat = Arc::clone(&z_mat);
256257

257-
let inst_handle = thread::spawn(move || {
258+
// debug_parallel
259+
print!("num_instances: {:?}, num_proofs: {:?}", num_instances, nps);
260+
261+
pool.execute(move || {
258262
let z_list = &z_mat[p];
259263

260264
for q in 0..nps {
@@ -285,13 +289,9 @@ impl<S: SpartanExtensionField + 'static> R1CSInstance<S> {
285289
)]);
286290
}
287291
});
288-
289-
instance_threads.push(inst_handle);
290292
}
291293

292-
for h in instance_threads {
293-
h.join().unwrap();
294-
}
294+
pool.join();
295295

296296
let Az = Az.lock().unwrap();
297297
let Bz = Bz.lock().unwrap();

0 commit comments

Comments
 (0)