1#include "CLHEP/Random/DualRand.h"
2#include "CLHEP/Random/Hurd160Engine.h"
3#include "CLHEP/Random/Hurd288Engine.h"
4#include "CLHEP/Random/JamesRandom.h"
5#include "CLHEP/Random/MixMaxRng.h"
6#include "CLHEP/Random/MTwistEngine.h"
7#include "CLHEP/Random/RandEngine.h"
8#include "CLHEP/Random/RanecuEngine.h"
9#include "CLHEP/Random/Ranlux64Engine.h"
10#include "CLHEP/Random/RanluxEngine.h"
11#include "CLHEP/Random/RanluxppEngine.h"
12#include "CLHEP/Random/RanshiEngine.h"
13#include "CLHEP/Random/TripleRand.h"
15#include "CLHEP/Random/RandBinomial.h"
16#include "CLHEP/Random/RandChiSquare.h"
17#include "CLHEP/Random/RandGauss.h"
18#include "CLHEP/Random/RandGamma.h"
19#include "CLHEP/Random/RandGaussZiggurat.h"
20#include "CLHEP/Random/RandExpZiggurat.h"
21#include "CLHEP/Utility/atomic_int.h"
28#if __cplusplus >= 201103L
30 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 7)
31 #define CLHEP_RUN_THREADED_TESTS 1
34 #if __has_feature(cxx_thread_local) && __has_feature(c_atomic)
35 #define CLHEP_RUN_THREADED_TESTS 1
38 #define CLHEP_RUN_THREADED_TESTS 0
41 #define CLHEP_RUN_THREADED_TESTS 0
45 #define CLHEP_RUN_THREADED_TESTS 0
69 std::vector<double> v;
70 v.push_back(dist.
fire());
71 v.push_back(dist.
fire());
72 v.push_back(dist.
fire());
73 v.push_back(dist.
fire());
74 v.push_back(dist.
fire());
78 if (reference[0] != v[0] ||
79 reference[1] != v[1] ||
80 reference[2] != v[2] ||
81 reference[3] != v[3] ||
82 reference[4] != v[4]) {
96 if (reference[0] != v[0] ||
97 reference[1] != v[1] ||
98 reference[2] != v[2] ||
99 reference[3] != v[3] ||
100 reference[4] != v[4]) {
120 if (reference[0] != v[0] ||
121 reference[1] != v[1] ||
122 reference[2] != v[2] ||
123 reference[3] != v[3] ||
124 reference[4] != v[4]) {
131 #if __GNUC__ > 3 && __GNUC_MINOR__ > 6
132 #pragma GCC diagnostic push
133 #pragma GCC diagnostic ignored "-Wshadow"
136 #pragma GCC diagnostic push
137 #pragma GCC diagnostic ignored "-Wshadow"
140#if defined __INTEL_COMPILER
142 #pragma warning disable 1599
145 #pragma clang diagnostic push
146 #pragma clang diagnostic ignored "-Wshadow"
151 std::ofstream
output(
"testThreaded.cout");
153#if CLHEP_RUN_THREADED_TESTS == 0
154 output <<
"Not running testThreaded.cc tests because compiler does not support needed features.\n";
157 output <<
"Running testThreaded.cc tests.\n";
162 std::vector<double> generatedNumbers;
164 generatedNumbers.push_back(dist.
fire());
165 generatedNumbers.push_back(dist.
fire());
166 generatedNumbers.push_back(dist.
fire());
167 generatedNumbers.push_back(dist.
fire());
168 generatedNumbers.push_back(dist.
fire());
172 std::thread t1(
testRandGauss, std::cref(generatedNumbers), std::ref(result1));
175 output <<
"testRandGauss failed on thread 1. fire and 2 shoot functions do not give the same results.\n";
185 std::thread t2(
testRandGauss, std::cref(generatedNumbers), std::ref(result2));
188 output <<
"testRandGauss failed on thread 2. This might mean the cache in RandGauss is not really thread local.\n";
189 output <<
"Maybe a problem in the macro logic in CLHEP/Utility/thread_local.h.\n";
193 output <<
"Verified that CLHEP_THREAD_LOCAL types are really thread local\n";
196 if(numberOfEngines.load() == 0) {
197 output <<
"If this is printing, it means CLHEP_ATOMIC_INT_TYPE really has type atomic<int>\n";
204 double epsilon = 0.0001;
209 if(std::fabs(engine1.
flat() - 0.412678) > epsilon ||
210 std::fabs(engine2.
flat() - 0.112937) > epsilon ||
211 std::fabs(engine3.
flat() - 0.998563) > epsilon) {
212 output <<
"Error, default seeds changed for DualRand random engine.\n";
220 if(std::fabs(engine1.
flat() - 0.104097) > epsilon ||
221 std::fabs(engine2.
flat() - 0.392414) > epsilon ||
222 std::fabs(engine3.
flat() - 0.7008) > epsilon) {
223 output <<
"Error, default seeds changed for Hurd160Engine random engine.\n";
231 if(std::fabs(engine1.
flat() - 0.942396) > epsilon ||
232 std::fabs(engine2.
flat() - 0.422952) > epsilon ||
233 std::fabs(engine3.
flat() - 0.528602) > epsilon) {
234 output <<
"Error, default seeds changed for Hurd288Engine random engine.\n";
245 if(std::fabs(engine3.
flat() - 0.286072) > epsilon ||
246 std::fabs(engine4.
flat() - 0.233610) > epsilon ||
247 std::fabs(engine5.
flat() - 0.837788) > epsilon) {
248 output <<
"Error, default seeds changed for HepJamesRandom random engine.\n";
256 if(std::fabs(engine1.
flat() - 0.840834) > epsilon ||
257 std::fabs(engine2.
flat() - 0.338951) > epsilon ||
258 std::fabs(engine3.
flat() - 0.840794) > epsilon) {
259 output <<
"Error, default seeds changed for MixMaxRng random engine.\n";
267 if(std::fabs(engine1.
flat() - 0.350114) > epsilon ||
268 std::fabs(engine2.
flat() - 0.575236) > epsilon ||
269 std::fabs(engine3.
flat() - 0.143409) > epsilon) {
270 output <<
"Error, default seeds changed for MTwistEngine random engine.\n";
278 if(std::fabs(engine1.
flat() - 0.154707) > epsilon ||
279 std::fabs(engine2.
flat() - 0.417668) > epsilon ||
280 std::fabs(engine3.
flat() - 0.350542) > epsilon) {
281 output <<
"Error, default seeds changed for RanecuEngine random engine.\n";
289 if(std::fabs(engine1.
flat() - 0.943338) > epsilon ||
290 std::fabs(engine2.
flat() - 0.175414) > epsilon ||
291 std::fabs(engine3.
flat() - 0.965602) > epsilon) {
292 output <<
"Error, default seeds changed for Ranlux64Engine random engine.\n";
300 if(std::fabs(engine1.
flat() - 0.117402) > epsilon ||
301 std::fabs(engine2.
flat() - 0.856504) > epsilon ||
302 std::fabs(engine3.
flat() - 0.68177) > epsilon) {
303 output <<
"Error, default seeds changed for RanluxEngine random engine.\n";
311 if(std::fabs(engine1.
flat() - 0.239639) > epsilon ||
312 std::fabs(engine2.
flat() - 0.566275) > epsilon ||
313 std::fabs(engine3.
flat() - 0.958136) > epsilon) {
314 output <<
"Error, default seeds changed for RanluxppEngine random engine.\n";
322 if(std::fabs(engine1.
flat() - 0.989873) > epsilon ||
323 std::fabs(engine2.
flat() - 0.548671) > epsilon ||
324 std::fabs(engine3.
flat() - 0.917996) > epsilon) {
325 output <<
"Error, default seeds changed for RanshiEngine random engine.\n";
333 if(std::fabs(engine1.
flat() - 0.838579) > epsilon ||
334 std::fabs(engine2.
flat() - 0.212374) > epsilon ||
335 std::fabs(engine3.
flat() - 0.84029) > epsilon) {
336 output <<
"Error, default seeds changed for TripleRand random engine.\n";
347 output <<
"Error, results changed for RandBinomial.\n";
355 output <<
"Error, results changed for RandChiSquared.\n";
363 output <<
"Error, results changed for RandExpZiggurat.\n";
371 output <<
"Error, results changed for RandGamma.\n";
379 output <<
"Error, results changed for RandGaussZiggurat.\n";
387 #if __GNUC__ > 3 && __GNUC_MINOR__ > 6
388 #pragma GCC diagnostic pop
391 #pragma GCC diagnostic pop
394#if defined __INTEL_COMPILER
398 #pragma clang diagnostic pop
#define CLHEP_ATOMIC_INT_TYPE
static HepRandomEngine * getTheEngine()
static void setTheEngine(HepRandomEngine *theNewEngine)
static void setFlag(bool val)
std::ofstream output("ranRestoreTest.cout")