Skip to content
Snippets Groups Projects
Commit 3855cffe authored by Alaettin Serhan Mete's avatar Alaettin Serhan Mete :eagle:
Browse files

Generators: Allow Sherpa to run in AthenaMP

parent bf64de0d
No related branches found
No related tags found
No related merge requests found
...@@ -77,6 +77,7 @@ protected: ...@@ -77,6 +77,7 @@ protected:
class Atlas_RNG: public ATOOLS::External_RNG { class Atlas_RNG: public ATOOLS::External_RNG {
CLHEP::HepRandomEngine* p_engine; CLHEP::HepRandomEngine* p_engine;
std::string m_filename; std::string m_filename;
std::once_flag m_once_flag_atlas_rng;
public: public:
Atlas_RNG(CLHEP::HepRandomEngine*); Atlas_RNG(CLHEP::HepRandomEngine*);
...@@ -85,6 +86,7 @@ public: ...@@ -85,6 +86,7 @@ public:
bool CanRestoreStatus() const { return true; } bool CanRestoreStatus() const { return true; }
void SaveStatus(); void SaveStatus();
void RestoreStatus(); void RestoreStatus();
const std::string GenerateUID() const;
}; };
......
...@@ -28,6 +28,7 @@ ...@@ -28,6 +28,7 @@
#include <cstdio> #include <cstdio>
#include <cstring> #include <cstring>
#include <mutex>
#include <signal.h> #include <signal.h>
#include <stdlib.h> #include <stdlib.h>
#include <sys/stat.h> #include <sys/stat.h>
...@@ -379,19 +380,6 @@ using namespace ATOOLS; ...@@ -379,19 +380,6 @@ using namespace ATOOLS;
Atlas_RNG::Atlas_RNG(CLHEP::HepRandomEngine* engine) : Atlas_RNG::Atlas_RNG(CLHEP::HepRandomEngine* engine) :
External_RNG(), p_engine(engine), m_filename("Config.conf") External_RNG(), p_engine(engine), m_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)) {
m_filename = "/dev/shm/Config.conf.";
for (size_t i = 0; i < 6; ++i)
m_filename += alphabet[rand() % nMax];
}
std::cout << "RNG state being saved to: " << m_filename << std::endl;
} }
Atlas_RNG::~Atlas_RNG() { std::remove(m_filename.c_str()); } Atlas_RNG::~Atlas_RNG() { std::remove(m_filename.c_str()); }
...@@ -402,7 +390,31 @@ double Atlas_RNG::Get(){ ...@@ -402,7 +390,31 @@ double Atlas_RNG::Get(){
} }
void Atlas_RNG::SaveStatus() { p_engine->saveStatus(m_filename.c_str()); } const std::string Atlas_RNG::GenerateUID() const {
std::string result{""};
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' };
for (size_t i = 0; i < 6; ++i) {
result += alphabet[rand() % nMax];
}
return result;
}
void Atlas_RNG::SaveStatus() {
// We set the file name first time the worker calls SaveStatus
std::call_once(m_once_flag_atlas_rng, [&](){
struct stat info;
if ( !stat("/dev/shm", &info)) {
m_filename = "/dev/shm/Config.conf.";
}
m_filename += GenerateUID();
std::cout << "RNG state being saved to: " << m_filename << std::endl;
});
p_engine->saveStatus(m_filename.c_str());
}
void Atlas_RNG::RestoreStatus() { p_engine->restoreStatus(m_filename.c_str()); } void Atlas_RNG::RestoreStatus() { p_engine->restoreStatus(m_filename.c_str()); }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment