From 18ebb399aecf6d044b0f01eae93344058ad33a8e Mon Sep 17 00:00:00 2001 From: Yang Zhou Date: Tue, 12 Nov 2024 18:33:47 -0500 Subject: [PATCH] add max_render_threads config to thread num for render_depth (#17) --- config/quad.yaml | 2 ++ src/config.rs | 2 ++ src/main.rs | 6 ++++++ 3 files changed, 10 insertions(+) diff --git a/config/quad.yaml b/config/quad.yaml index 68fb3820..4f517ff6 100644 --- a/config/quad.yaml +++ b/config/quad.yaml @@ -4,6 +4,8 @@ use_multithreading_depth_rendering: true # Enable multithreading for depth rende use_rk4_for_dynamics_update: false # Enable Runge-Kutta 4th order integration for dynamics, otherwise Euler integration is used use_rk4_for_dynamics_control: false # Enable Runge-Kutta 4th order integration for dynamics, otherwise Euler integration is used +max_render_threads: 8 # Maximum number of threads for rendering + rerun_blueprint: "config/peng_default_blueprint.rbl" simulation: diff --git a/src/config.rs b/src/config.rs index 2422c872..683be381 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,6 +24,8 @@ pub struct Config { pub planner_schedule: Vec, /// Rerun blueprint path pub rerun_blueprint: String, + /// Maximum number of threads for rendering + pub max_render_threads: Option, /// Use rerun.io for recording pub use_rerun: bool, /// Render depth diff --git a/src/main.rs b/src/main.rs index 7f3ea4d8..91731f9b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -58,6 +58,12 @@ fn main() -> Result<(), SimulationError> { config.camera.near, config.camera.far, ); + if let Some(thread_count) = config.max_render_threads { + rayon::ThreadPoolBuilder::new() + .num_threads(thread_count) + .build_global() + .unwrap(); + } let mut planner_manager = PlannerManager::new(Vector3::zeros(), 0.0); let mut trajectory = Trajectory::new(Vector3::new(0.0, 0.0, 0.0)); let mut previous_thrust = 0.0;