Commit 930088ab authored by Ewelina Maria Lobodzinska's avatar Ewelina Maria Lobodzinska
Browse files

Merge branch 'rng_io_patch' into '21.6'

Generators: reduce I/O load by writing to shared RAM

See merge request atlas/athena!53697
parents f6f85762 65af981f
......@@ -75,9 +75,11 @@ protected:
class Atlas_RNG: public ATOOLS::External_RNG {
CLHEP::HepRandomEngine* p_engine;
std::string p_filename;
public:
Atlas_RNG(CLHEP::HepRandomEngine*);
~Atlas_RNG();
double Get();
bool CanRestoreStatus() const { return true; }
void SaveStatus();
......
......@@ -23,6 +23,7 @@
#include <cstring>
#include <signal.h>
#include <stdlib.h>
#include <sys/stat.h>
#include "CLHEP/Random/RandFlat.h"
#include "AthenaKernel/IAtRndmGenSvc.h"
......@@ -339,19 +340,34 @@ void Sherpa_i::compilePlugin(std::string pluginCode) {
using namespace ATOOLS;
Atlas_RNG::Atlas_RNG(CLHEP::HepRandomEngine* engine) :
External_RNG(), p_engine(engine)
External_RNG(), p_engine(engine), p_filename("Config.conf")
{
const int nMax = 26;
char alphabet[nMax] = { 'a', 'b', 'c', 'd', 'e', 'f', 'g',
'h', 'i', 'j', 'k', 'l', 'm', 'n',
'o', 'p', 'q', 'r', 's', 't', 'u',
'v', 'w', 'x', 'y', 'z' };
struct stat info;
if ( !stat("/dev/shm", &info)) {
p_filename = "/dev/shm/Config.conf.";
for (size_t i = 0; i < 6; ++i)
p_filename += alphabet[rand() % nMax];
}
std::cout << "RNG state being saved to: " << p_filename << std::endl;
}
Atlas_RNG::~Atlas_RNG() { std::remove(p_filename.c_str()); }
double Atlas_RNG::Get(){
return CLHEP::RandFlat::shoot(p_engine);
}
void Atlas_RNG::SaveStatus() { p_engine->saveStatus(); }
void Atlas_RNG::SaveStatus() { p_engine->saveStatus(p_filename.c_str()); }
void Atlas_RNG::RestoreStatus() { p_engine->restoreStatus(); }
void Atlas_RNG::RestoreStatus() { p_engine->restoreStatus(p_filename.c_str()); }
// some getter magic to make this random number generator available to sherpa
DECLARE_GETTER(Atlas_RNG,"Atlas_RNG",External_RNG,RNG_Key);
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment