25 JetScapeTaskSupport *JetScapeTaskSupport::m_pInstance =
nullptr;
27 unsigned int JetScapeTaskSupport::random_seed_ = 0;
28 bool JetScapeTaskSupport::initialized_ =
false;
29 bool JetScapeTaskSupport::one_generator_per_task_ =
false;
35 VERBOSE(1) <<
"Created JetScapeTaskSupport Instance";
41 int JetScapeTaskSupport::RegisterTask() {
42 VERBOSE(1) <<
"JetScapeTaskSupport::RegisterTask called, answering "
45 return CurrentTaskNumber - 1;
49 void JetScapeTaskSupport::ReadSeedFromXML() {
50 VERBOSE(1) <<
"JetScapeTaskSupport::ReadSeedFromXML called. ";
54 JetScapeXML::Instance()->GetElement({
"Random"});
56 if (RandomXmlDescription) {
59 throw std::runtime_error(
"Cannot parse xml");
62 JSWARN <<
"No <Random> element found in xml, seeding to 0";
65 VERBOSE(7) <<
"Seeding JetScapeTaskSupport to " << random_seed_;
66 if (random_seed_ == 0) {
68 random_seed_ = std::chrono::system_clock::now().time_since_epoch().count();
69 JSINFO <<
"JetScapeTaskSupport found seed 0, using one engine for all and "
72 one_generator_per_task_ =
false;
74 JSINFO <<
"JetScapeTaskSupport found seed " << random_seed_
75 <<
", using individual engines with seeds created from "
77 one_generator_per_task_ =
true;
80 one_for_all_ = make_shared<std::mt19937>(random_seed_);
92 JSWARN <<
"Trying to use JetScapeTaskSupport::GetMt19937Generator before "
94 throw std::runtime_error(
95 "Trying to use JetScapeTaskSupport::GetMt19937Generator before "
100 throw std::runtime_error(
"generator not initialized?");
105 if (one_generator_per_task_) {
106 if (random_seed_ == 0)
107 throw std::runtime_error(
"This should never happen");
109 one_for_all_->seed(random_seed_);
113 one_for_all_->discard(TaskId);
115 unsigned int localseed = (*one_for_all_)();
116 JSDEBUG <<
"Asked by " << TaskId
117 <<
" for an individual generator, returning one seeded with "
119 return make_shared<std::mt19937>(localseed);
123 JSDEBUG <<
"Asked by " << TaskId
124 <<
" for the static generator, returning one originally seeded with "