some inconsequential refactors to tidepool::main
This commit is contained in:
parent
cf9fd27ca0
commit
e673198704
|
@ -61,9 +61,11 @@ fn single(args: cli::SingleRun) -> Result<()> {
|
|||
let (tx, rx) = create_mailbox();
|
||||
let exit_early = Arc::new(atomic::AtomicBool::new(false));
|
||||
|
||||
let exit_early2 = exit_early.clone();
|
||||
let config2 = config.clone();
|
||||
std::thread::spawn(move || run_simulation(&args.data, config2, args.seed, 0, tx, exit_early2));
|
||||
std::thread::spawn({
|
||||
let config = config.clone();
|
||||
let exit_early = exit_early.clone();
|
||||
move || run_simulation(&args.data, config, args.seed, 0, &tx, &exit_early)
|
||||
});
|
||||
|
||||
while let Ok(msg) = rx.recv() {
|
||||
tracing::trace!(msg = debug(&msg));
|
||||
|
@ -116,8 +118,8 @@ fn multi(args: cli::MultiRun) -> Result<()> {
|
|||
let config = parse_config_file(&args.config_file)?;
|
||||
|
||||
let (tx, rx) = create_mailbox();
|
||||
let tasks = args.count.unwrap_or(u32::MAX);
|
||||
let tasks = Arc::new(atomic::AtomicI64::new(tasks as i64));
|
||||
let tasks = args.count.map_or(i64::MAX, |n| n as i64);
|
||||
let tasks = Arc::new(atomic::AtomicI64::new(tasks));
|
||||
let exit_early = Arc::new(atomic::AtomicBool::new(false));
|
||||
|
||||
let n_jobs = args.jobs.unwrap_or_else(num_cpus::get);
|
||||
|
@ -127,13 +129,13 @@ fn multi(args: cli::MultiRun) -> Result<()> {
|
|||
tracing::debug!("spawning {n_jobs} jobs");
|
||||
for id in 0..n_jobs {
|
||||
jobs.insert(id, None);
|
||||
let tx2 = tx.clone();
|
||||
let tasks2 = tasks.clone();
|
||||
let exit_early2 = exit_early.clone();
|
||||
let config2 = config.clone();
|
||||
std::thread::spawn({
|
||||
let data_args = args.data.clone();
|
||||
std::thread::spawn(move || {
|
||||
run_simulations(&data_args, config2, id, tx2, tasks2, exit_early2);
|
||||
let config = config.clone();
|
||||
let tx = tx.clone();
|
||||
let tasks = tasks.clone();
|
||||
let exit_early = exit_early.clone();
|
||||
move || run_simulations(&data_args, config, id, &tx, &tasks, &exit_early)
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -335,8 +337,8 @@ fn run_simulation(
|
|||
config: config::Config,
|
||||
seed: Option<u64>,
|
||||
id: usize,
|
||||
tx: mpsc::SyncSender<Msg>,
|
||||
exit_early: Arc<atomic::AtomicBool>,
|
||||
tx: &mpsc::SyncSender<Msg>,
|
||||
exit_early: &atomic::AtomicBool,
|
||||
) {
|
||||
let mut moves = data_args.list_moves.then(Vec::new);
|
||||
let seed = seed.unwrap_or_else(|| rand::thread_rng().next_u64());
|
||||
|
@ -415,20 +417,16 @@ fn run_simulations(
|
|||
data_args: &cli::OutputDataArgs,
|
||||
config: config::Config,
|
||||
id: usize,
|
||||
tx: mpsc::SyncSender<Msg>,
|
||||
tasks: Arc<atomic::AtomicI64>,
|
||||
exit_early: Arc<atomic::AtomicBool>,
|
||||
tx: &mpsc::SyncSender<Msg>,
|
||||
tasks: &atomic::AtomicI64,
|
||||
exit_early: &atomic::AtomicBool,
|
||||
) {
|
||||
while tasks.fetch_sub(1, atomic::Ordering::Relaxed) > 0 {
|
||||
if exit_early.load(atomic::Ordering::Relaxed) {
|
||||
break;
|
||||
}
|
||||
|
||||
let seed = None;
|
||||
let config2 = config.clone();
|
||||
let tx2 = tx.clone();
|
||||
let exit_early2 = exit_early.clone();
|
||||
run_simulation(&data_args, config2, seed, id, tx2, exit_early2);
|
||||
run_simulation(data_args, config.clone(), None, id, tx, exit_early);
|
||||
}
|
||||
|
||||
if tx.send(Msg::Shutdown(id)).is_err() {
|
||||
|
|
Loading…
Reference in New Issue