Skip to content

Commit 952782c

Browse files
committed
Set hybrid expansion to num_workers in HY
The expansion to the hybrid configuration when running external generators on HY is updated so that the cloning happens only up to the set number of workers. The previous version proved to be successful, however it caused an increased configuration time per MCGen job, which is fixed here (it will be expanded by a multi-threaded initialisation of the generators in hybrid mode in the near future).
1 parent 05c13ec commit 952782c

2 files changed

Lines changed: 39 additions & 21 deletions

File tree

‎Generators/include/Generators/Generator.h‎

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -104,11 +104,6 @@ class Generator : public FairGenerator
104104
// Check if simulation is running in Hyperloop mode
105105
static bool isHyperloop();
106106

107-
// Number of parallel sub-generator clones a Hyperloop-aware generator expands into
108-
// (currently used by the external-generator-to-hybrid expansion in GeneratorFactory).
109-
// 8 matches the standard core counts of Grid/Hyperloop nodes
110-
static constexpr int NHyperloopParallelGenerators = 8;
111-
112107
/** other **/
113108
void clearParticles() { mParticles.clear(); };
114109

‎Generators/src/GeneratorFactory.cxx‎

Lines changed: 39 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
#include <rapidjson/ostreamwrapper.h>
4141
#include <fstream>
4242
#include <unistd.h>
43+
#include <algorithm>
4344
#endif
4445
#include <Generators/PrimaryGenerator.h>
4546
#include <Generators/BoxGunParam.h>
@@ -56,17 +57,33 @@ namespace eventgen
5657
{
5758

5859
#if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3)
59-
// Builds a parallel GeneratorHybrid JSON configuration out of
60-
// 8 (Generator::NHyperloopParallelGenerators) identical "external" sub-generator entries,
61-
// using the configured GeneratorExternalParam. This makes the simulation parallelisation automatic
62-
// on Hyperloop.
60+
// Maximum number of parallel sub-generators on Hyperloop. Fixed rather than taken from the host
61+
// core count, which does not reflect the CPU slot assigned to the job: 8 is the largest slot
62+
// available on GRID/Hyperloop nodes.
63+
constexpr int MaxHyperloopParallelGenerators = 8;
64+
65+
// Number of identical sub-generators the external generator is expanded into on Hyperloop:
66+
// one sub-generator per GeneratorHybrid.num_workers (1 by default), capped to
67+
// MaxHyperloopParallelGenerators.
68+
int getHyperloopNParallelGenerators()
69+
{
70+
const int nWorkers = GeneratorHybridParam::Instance().num_workers;
71+
if (nWorkers > MaxHyperloopParallelGenerators) {
72+
LOG(warning) << "GeneratorHybrid.num_workers = " << nWorkers << " exceeds the maximum of "
73+
<< MaxHyperloopParallelGenerators << " parallel sub-generators: capping to " << MaxHyperloopParallelGenerators;
74+
}
75+
return std::clamp(nWorkers, 1, MaxHyperloopParallelGenerators);
76+
}
77+
78+
// Builds a parallel GeneratorHybrid JSON configuration out of nGenerators
79+
// identical "external" sub-generator entries, using the configured GeneratorExternalParam.
80+
// This makes the simulation parallelisation automatic on Hyperloop.
6381
// To-do: Define the behaviour with ini configuration which are already definining a hybrid gen
6482
//
65-
// Note on GeneratorHybrid.num_workers: expanding to 8 sub-generators does not by itself raise
66-
// the number of TBB workers that actually run them in parallel. This is controlled by
67-
// the parameter GeneratorHybrid.num_workers. On Hyperloop this will be part
68-
// of the standard train configuration
69-
std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& extparams)
83+
// Note on GeneratorHybrid.num_workers: it controls both the number of TBB workers running the
84+
// sub-generators in parallel and nGenerators (see getHyperloopNParallelGenerators).
85+
// On Hyperloop it is part of the standard train configuration for MCGen datasets
86+
std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& extparams, int nGenerators)
7087
{
7188
rapidjson::Document doc;
7289
doc.SetObject();
@@ -75,7 +92,7 @@ std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& ext
7592

7693
rapidjson::Value generators(rapidjson::kArrayType);
7794
rapidjson::Value fractions(rapidjson::kArrayType);
78-
for (int i = 0; i < Generator::NHyperloopParallelGenerators; ++i) {
95+
for (int i = 0; i < nGenerators; ++i) {
7996
rapidjson::Value config(rapidjson::kObjectType);
8097
config.AddMember("fileName", rapidjson::Value(extparams.fileName.c_str(), alloc), alloc);
8198
config.AddMember("funcName", rapidjson::Value(extparams.funcName.c_str(), alloc), alloc);
@@ -157,12 +174,18 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
157174
genconfig = "hybrid";
158175
} else if (Generator::isHyperloop()) {
159176
// Running under Hyperloop: transparently expand the single external generator
160-
// configuration into a parallel hybrid of Generator::NHyperloopParallelGenerators
161-
// clones, to increase on-the-fly MC-generation throughput.
162-
LOG(info) << "IS_HYPERLOOP detected: expanding external generator into "
163-
<< Generator::NHyperloopParallelGenerators << " parallel hybrid sub-generators";
164-
hyperloopExtHybridConfigFile = buildHyperloopExternalHybridConfig(GeneratorExternalParam::Instance());
165-
genconfig = "hybrid";
177+
// configuration into a parallel hybrid of clones (one per worker, capped to
178+
// MaxHyperloopParallelGenerators), to increase on-the-fly MC-generation throughput.
179+
// A single clone brings no parallelism, so the plain external generator is kept.
180+
const int nGenerators = getHyperloopNParallelGenerators();
181+
if (nGenerators > 1) {
182+
LOG(info) << "IS_HYPERLOOP detected: expanding external generator into "
183+
<< nGenerators << " parallel hybrid sub-generators";
184+
hyperloopExtHybridConfigFile = buildHyperloopExternalHybridConfig(GeneratorExternalParam::Instance(), nGenerators);
185+
genconfig = "hybrid";
186+
} else {
187+
LOG(info) << "IS_HYPERLOOP detected: single worker requested, keeping the external generator as is";
188+
}
166189
}
167190
}
168191
#endif

0 commit comments

Comments
 (0)