minedmap: add support for parallel processing

For now, only RegionProcessor and TileMipmapper are run in parallel.
This commit is contained in:
Matthias Schiffer 2023-08-14 15:48:05 +02:00
parent c1260a63b5
commit 78fe1ec50e
Signed by: neocturne
GPG key ID: 16EF3F64CB201D9C
6 changed files with 191 additions and 11 deletions

View file

@ -7,7 +7,7 @@ mod tile_renderer;
use std::path::PathBuf;
use anyhow::Result;
use anyhow::{Context, Result};
use clap::Parser;
use common::Config;
@ -18,15 +18,30 @@ use tile_renderer::TileRenderer;
#[derive(Debug, Parser)]
pub struct Args {
/// Number of parallel threads to use for processing
///
/// If not given, only a single thread is used. Pass 0 to
/// use one thread per logical CPU core.
#[arg(short, long)]
pub jobs: Option<usize>,
/// Minecraft save directory
pub input_dir: PathBuf,
/// MinedMap data directory
pub output_dir: PathBuf,
}
fn setup_threads(num_threads: usize) -> Result<()> {
rayon::ThreadPoolBuilder::new()
.num_threads(num_threads)
.build_global()
.context("Failed to configure thread pool")
}
fn main() -> Result<()> {
let args = Args::parse();
let config = Config::new(args);
let config = Config::new(&args);
setup_threads(config.num_threads)?;
let regions = RegionProcessor::new(&config).run()?;
TileRenderer::new(&config).run(&regions)?;