From 922355a064698cf0c099f3656d02e89961f67602 Mon Sep 17 00:00:00 2001 From: Daniel Schadt Date: Sat, 14 Jan 2023 18:44:24 +0100 Subject: make number of threads configurable per CLI --- src/main.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/main.rs b/src/main.rs index 77af69f..9c3250e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -4,6 +4,7 @@ use clap::Parser; use color_eyre::eyre::{bail, Result}; use indicatif::{MultiProgress, ProgressBar, ProgressDrawTarget, ProgressStyle}; use is_terminal::IsTerminal; +use rayon::ThreadPoolBuilder; mod gpx; mod layer; @@ -16,11 +17,17 @@ struct Args { #[arg(required = true)] files: Vec, + /// Minimum zoom level to generate tiles for. #[arg(long, default_value_t = 0)] min_zoom: u32, + /// Maximum zoom level to generate tiles for. #[arg(long, default_value_t = 19)] max_zoom: u32, + + /// Number of threads to use. Set to 0 to use all available CPU cores. + #[arg(long, short, default_value_t = 0)] + threads: usize, } fn main() -> Result<()> { @@ -32,6 +39,10 @@ fn main() -> Result<()> { bail!("Max zoom cannot be smaller than min zoom!"); } + ThreadPoolBuilder::new() + .num_threads(args.threads) + .build_global()?; + let progress_style = ProgressStyle::with_template("[{elapsed}] {prefix:.cyan} {wide_bar} {pos:.green}/{len}")?; let zoom_style = -- cgit v1.2.3