From e651cc3ee0d8c7d0329427b9de66d24b627dd283 Mon Sep 17 00:00:00 2001 From: plexx-dev Date: Tue, 17 Feb 2026 16:13:50 +0100 Subject: [PATCH] the amount of threads now adapt to the host system amount of threads --- src/main.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main.rs b/src/main.rs index d6d7d29..06f663b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,6 +8,8 @@ pub mod rtweekend; pub mod sphere; pub mod vec3; +use std::{f64, thread::available_parallelism}; + use image::{Pixel, RgbImage}; use indicatif::{ProgressBar, ProgressStyle}; use rayon::prelude::*; @@ -136,9 +138,14 @@ fn main() { dist_to_focus, ); + let num_threads: usize = match available_parallelism() { + Ok(threads) => threads.into(), + Err(_) => 1, + }; + // Render rayon::ThreadPoolBuilder::new() - .num_threads(11) + .num_threads(num_threads) .build_global() .unwrap();