the amount of threads now adapt to the host system amount of threads

This commit is contained in:
2026-02-17 16:13:50 +01:00
parent 25a3661fd0
commit e651cc3ee0

View File

@@ -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();