From 3186163c228f2cb3404e54fbc9ed5a63d143dc1e Mon Sep 17 00:00:00 2001 From: Marco Giacalone Date: Sat, 21 Nov 2026 22:26:59 +0100 Subject: [PATCH] Cap hybrid workers to configured generators Workers beyond the number of generators defined in the JSON configurations for Hybrid are never busy so a cap is applied to avoid wasting resources --- Generators/src/GeneratorHybrid.cxx | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/Generators/src/GeneratorHybrid.cxx b/Generators/src/GeneratorHybrid.cxx index 1afb9446cbe05..cdebde104e4f2 100644 --- a/Generators/src/GeneratorHybrid.cxx +++ b/Generators/src/GeneratorHybrid.cxx @@ -329,8 +329,16 @@ Bool_t GeneratorHybrid::Init() // in sequential mode we have one queue per generator mResultQueue.resize(gens.size()); } - // Create a task arena with a specified number of threads - mTaskArena.initialize(GeneratorHybridParam::Instance().num_workers); + // Create a task arena with a specified number of threads. + // Workers beyond the number of generators defined in the JSON are + // never busy so a cap is applied to avoid wasting resources + const int requestedWorkers = GeneratorHybridParam::Instance().num_workers; + const int nWorkers = std::max(1, std::min(requestedWorkers, static_cast(gens.size()))); + if (nWorkers != requestedWorkers) { + LOG(info) << "GeneratorHybrid.num_workers = " << requestedWorkers << " adjusted to " << nWorkers + << " (number of generators: " << gens.size() << ")"; + } + mTaskArena.initialize(nWorkers); // the process task function actually calls event generation // when it is done it notifies the outside world by pushing it's index into an appropriate queue