149 {
150
151 std::ofstream
output(
"testThreaded.cout");
152
153#if CLHEP_RUN_THREADED_TESTS == 0
154 output <<
"Not running testThreaded.cc tests because compiler does not support needed features.\n";
155 return 0;
156#else
157 output <<
"Running testThreaded.cc tests.\n";
158
159 long seedL = 100;
162 std::vector<double> generatedNumbers;
163
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());
169
170 bool result1 = true;
171
172 std::thread t1(
testRandGauss, std::cref(generatedNumbers), std::ref(result1));
173 t1.join();
174 if(!result1) {
175 output <<
"testRandGauss failed on thread 1. fire and 2 shoot functions do not give the same results.\n";
176 return 1;
177 }
178
179 bool result2 = true;
180
181
182
183
184
185 std::thread t2(
testRandGauss, std::cref(generatedNumbers), std::ref(result2));
186 t2.join();
187 if(!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";
190 return 1;
191 }
192
193 output <<
"Verified that CLHEP_THREAD_LOCAL types are really thread local\n";
194
196 if(numberOfEngines.load() == 0) {
197 output <<
"If this is printing, it means CLHEP_ATOMIC_INT_TYPE really has type atomic<int>\n";
198 }
199
200
201
202
203
204 double epsilon = 0.0001;
205 {
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";
213 return 1;
214 }
215 }
216 {
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";
224 return 1;
225 }
226 }
227 {
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";
235 return 1;
236 }
237 }
238 {
239
240
241
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";
249 return 1;
250 }
251 }
252 {
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";
260 return 1;
261 }
262 }
263 {
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";
271 return 1;
272 }
273 }
274 {
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";
282 return 1;
283 }
284 }
285 {
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";
293 return 1;
294 }
295 }
296 {
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";
304 return 1;
305 }
306 }
307 {
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";
315 return 1;
316 }
317 }
318 {
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";
326 return 1;
327 }
328 }
329 {
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";
337 return 1;
338 }
339 }
340
341
342
343 {
344 long seedL2 = 100;
347 output <<
"Error, results changed for RandBinomial.\n";
348 return 1;
349 }
350 }
351 {
352 long seedL3 = 100;
355 output <<
"Error, results changed for RandChiSquared.\n";
356 return 1;
357 }
358 }
359 {
360 long seedL4 = 100;
363 output <<
"Error, results changed for RandExpZiggurat.\n";
364 return 1;
365 }
366 }
367 {
368 long seedL5 = 100;
371 output <<
"Error, results changed for RandGamma.\n";
372 return 1;
373 }
374 }
375 {
376 long seedL6 = 100;
379 output <<
"Error, results changed for RandGaussZiggurat.\n";
380 return 1;
381 }
382 }
383 return 0;
384#endif
385}
#define CLHEP_ATOMIC_INT_TYPE
std::ofstream output("ranRestoreTest.cout")