/*+ ARES/HADES/BORG Package -- ./libLSS/tests/test_rgen.cpp Copyright (C) 2014-2020 Guilhem Lavaux Copyright (C) 2009-2020 Jens Jasche Additional contributions from: Guilhem Lavaux (2023) +*/ #include #include #include #include #include "libLSS/tools/static_init.hpp" #include "libLSS/samplers/rgen/gsl_random_number.hpp" using namespace LibLSS; using boost::chrono::system_clock; using boost::chrono::duration; using boost::format; using boost::str; static const long int LOOP_NO = 100000000; int main() { StaticInit::execute(); Console::instance().setVerboseLevel(); RandomNumberThreaded rgen(-1); system_clock::time_point start = system_clock::now(); #pragma omp parallel for schedule(static) for (long l = 0; l < LOOP_NO; l++) rgen.get(); duration perf = system_clock::now() - start; Console::instance().print(format("Number / sec = %lg Mint / sec") % (LOOP_NO/perf.count()/1000000) ); { H5::H5File f("PRNG.state", H5F_ACC_TRUNC); rgen.save(f); } try { RandomNumberThreaded rgen2(2*smp_get_max_threads()); H5::H5File f("PRNG.state", 0); rgen2.restore(f); abort(); Console::instance().print("Did not get any error. Bad"); } catch (const ErrorBadState& s) { Console::instance().print("Got error. Exact"); } try { RandomNumberThreaded rgen2(-1); H5::H5File f("PRNG.state", 0); rgen2.restore(f); } catch (const ErrorBase& s) { Console::instance().print("Got an error. Bad"); abort(); } return 0; }