Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 0 additions & 5 deletions Generators/include/Generators/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,11 +104,6 @@ class Generator : public FairGenerator
// Check if simulation is running in Hyperloop mode
static bool isHyperloop();

// Number of parallel sub-generator clones a Hyperloop-aware generator expands into
// (currently used by the external-generator-to-hybrid expansion in GeneratorFactory).
// 8 matches the standard core counts of Grid/Hyperloop nodes
static constexpr int NHyperloopParallelGenerators = 8;

/** other **/
void clearParticles() { mParticles.clear(); };

Expand Down
55 changes: 39 additions & 16 deletions Generators/src/GeneratorFactory.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#include <rapidjson/ostreamwrapper.h>
#include <fstream>
#include <unistd.h>
#include <algorithm>
#endif
#include <Generators/PrimaryGenerator.h>
#include <Generators/BoxGunParam.h>
Expand All @@ -56,17 +57,33 @@ namespace eventgen
{

#if defined(GENERATORS_WITH_PYTHIA8) && defined(GENERATORS_WITH_HEPMC3)
// Builds a parallel GeneratorHybrid JSON configuration out of
// 8 (Generator::NHyperloopParallelGenerators) identical "external" sub-generator entries,
// using the configured GeneratorExternalParam. This makes the simulation parallelisation automatic
// on Hyperloop.
// Maximum number of parallel sub-generators on Hyperloop. Fixed rather than taken from the host
// core count, which does not reflect the CPU slot assigned to the job: 8 is the largest slot
// available on GRID/Hyperloop nodes.
constexpr int MaxHyperloopParallelGenerators = 8;

// Number of identical sub-generators the external generator is expanded into on Hyperloop:
// one sub-generator per GeneratorHybrid.num_workers (1 by default), capped to
// MaxHyperloopParallelGenerators.
int getHyperloopNParallelGenerators()
{
const int nWorkers = GeneratorHybridParam::Instance().num_workers;
if (nWorkers > MaxHyperloopParallelGenerators) {
LOG(warning) << "GeneratorHybrid.num_workers = " << nWorkers << " exceeds the maximum of "
<< MaxHyperloopParallelGenerators << " parallel sub-generators: capping to " << MaxHyperloopParallelGenerators;
}
return std::clamp(nWorkers, 1, MaxHyperloopParallelGenerators);
}

// Builds a parallel GeneratorHybrid JSON configuration out of nGenerators
// identical "external" sub-generator entries, using the configured GeneratorExternalParam.
// This makes the simulation parallelisation automatic on Hyperloop.
// To-do: Define the behaviour with ini configuration which are already definining a hybrid gen
//
// Note on GeneratorHybrid.num_workers: expanding to 8 sub-generators does not by itself raise
// the number of TBB workers that actually run them in parallel. This is controlled by
// the parameter GeneratorHybrid.num_workers. On Hyperloop this will be part
// of the standard train configuration
std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& extparams)
// Note on GeneratorHybrid.num_workers: it controls both the number of TBB workers running the
// sub-generators in parallel and nGenerators (see getHyperloopNParallelGenerators).
// On Hyperloop it is part of the standard train configuration for MCGen datasets
std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& extparams, int nGenerators)
{
rapidjson::Document doc;
doc.SetObject();
Expand All @@ -75,7 +92,7 @@ std::string buildHyperloopExternalHybridConfig(GeneratorExternalParam const& ext

rapidjson::Value generators(rapidjson::kArrayType);
rapidjson::Value fractions(rapidjson::kArrayType);
for (int i = 0; i < Generator::NHyperloopParallelGenerators; ++i) {
for (int i = 0; i < nGenerators; ++i) {
rapidjson::Value config(rapidjson::kObjectType);
config.AddMember("fileName", rapidjson::Value(extparams.fileName.c_str(), alloc), alloc);
config.AddMember("funcName", rapidjson::Value(extparams.funcName.c_str(), alloc), alloc);
Expand Down Expand Up @@ -157,12 +174,18 @@ void GeneratorFactory::setPrimaryGenerator(o2::conf::SimConfig const& conf, Fair
genconfig = "hybrid";
} else if (Generator::isHyperloop()) {
// Running under Hyperloop: transparently expand the single external generator
// configuration into a parallel hybrid of Generator::NHyperloopParallelGenerators
// clones, to increase on-the-fly MC-generation throughput.
LOG(info) << "IS_HYPERLOOP detected: expanding external generator into "
<< Generator::NHyperloopParallelGenerators << " parallel hybrid sub-generators";
hyperloopExtHybridConfigFile = buildHyperloopExternalHybridConfig(GeneratorExternalParam::Instance());
genconfig = "hybrid";
// configuration into a parallel hybrid of clones (one per worker, capped to
// MaxHyperloopParallelGenerators), to increase on-the-fly MC-generation throughput.
// A single clone brings no parallelism, so the plain external generator is kept.
const int nGenerators = getHyperloopNParallelGenerators();
if (nGenerators > 1) {
LOG(info) << "IS_HYPERLOOP detected: expanding external generator into "
<< nGenerators << " parallel hybrid sub-generators";
hyperloopExtHybridConfigFile = buildHyperloopExternalHybridConfig(GeneratorExternalParam::Instance(), nGenerators);
genconfig = "hybrid";
} else {
LOG(info) << "IS_HYPERLOOP detected: single worker requested, keeping the external generator as is";
}
}
}
#endif
Expand Down