23 namespace Test_RandomNumbers_MT19937 {
24 const std::string
test_name =
"RandomNumbers.MT19937.Global";
28 const std::string filename_input =
"test_RandomNumbers_MT19937_Global.yaml";
29 const std::string filename_output =
"stdout";
31 class Parameters_Test_RandomNumbers :
public Parameters {
33 Parameters_Test_RandomNumbers()
35 Register_int(
"seed", 0);
37 Register_string(
"verbose_level",
"NULL");
39 Register_double(
"expected_result", 0.0);
47 #ifdef USE_TESTMANAGER_AUTOREGISTER
60 Parameters *params_test =
new Parameters_Test_RandomNumbers;
66 params_manager.
read_params(filename_input, params_all);
68 int seed = params_test->
get_int(
"seed");
69 const string str_vlevel = params_test->
get_string(
"verbose_level");
71 const bool do_check = params_test->
is_set(
"expected_result");
72 const double expected_result = do_check ? params_test->
get_double(
"expected_result") : 0.0;
78 vout.
general(vl,
" vlevel = %s\n", str_vlevel.c_str());
90 vout.
general(vl,
"Serial and Node-parallel test of Random Number Generator:\n");
102 const size_t nsample = 1024;
103 double data[nsample];
104 for (
size_t i = 0; i < nsample; ++i) {
110 Field field1(nin, nvol, nex);
120 for (
size_t i = 0; i < nsample; ++i) {
121 data[i] = rand->
get();
128 Field field2(0, 0, 0);
133 field2.
reset(nin, lvol, nex);
135 double *p = field2.
ptr(0);
137 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
145 Field field1b(0, 0, 0);
148 field1b.
reset(nin, lvol, nex);
153 fieldio.
gather(&field1b, &field1);
159 if (field1b.
size() != field2.
size()) {
164 double *p1 = field1b.
ptr(0);
165 double *p2 = field2.
ptr(0);
167 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
168 if (*p1++ != *p2++) ++err1;
183 for (
size_t i = 0; i < nsample; ++i) {
184 if (data[i] != buf[i]) ++err2;
205 for (
size_t i = 0; i < nsample; ++i) {
206 data[i] = rand->
get();
210 rand->
readfile(
"RNG_MT19937.state");
215 for (
size_t i = 0; i < nsample; ++i) {
216 if (data[i] != rand->
get()) ++err3_part;
228 field1.
reset(nin, nvol, nex);
243 field2.
reset(nin, lvol, nex);
245 double *p = field2.
ptr(0);
247 if (field2.
nin() % 2 == 0) {
250 for (
int j = 0, Nex = field2.
nex(); j < Nex; ++j) {
251 for (
int isite = 0, Nvol = field2.
nvol(); isite < Nvol; ++isite) {
252 for (
int i = 0, Nin = field2.
nin(); i < Nin; i += 2) {
262 for (
int j = 0, Nex = field2.
nex(); j < Nex; ++j) {
263 for (
int isite = 0, Nvol = field2.
nvol(); isite < Nvol; ++isite) {
264 for (
int i = 0, Nin = field2.
nin(); i < Nin; ++i) {
276 field1b.
reset(nin, lvol, nex);
279 fieldio.
gather(&field1b, &field1);
284 if (field1b.
size() != field2.
size()) {
289 double *p1 = field1b.
ptr(0);
290 double *p2 = field2.
ptr(0);
292 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
293 if (*p1++ != *p2++) ++err4;
303 double result = err1 + err2 + err3 + err4;
318 vout.
detailed(vl,
"check skipped: expected_result not set.\n\n");
void writefile(const std::string &)
void read_params(const std::string ¶ms_file, Parameters *params)
read parameters from file.
void detailed(const char *format,...)
void set_parameter_verboselevel(const Bridge::VerboseLevel vl)
virtual void uniform_lex_global(Field &)
uniform random number defined on global lattice.
void general(const char *format,...)
double * ptr(const int jin, const int site, const int jex)
Container of Field-type object.
FieldIO_Text class for file I/O of Field data in plain text format.
void readfile(const std::string &)
int get_int(const string &key) const
virtual void gauss_lex_global(Field &)
gaussian random number defined on global lattice.
static int send_1to1(int count, double *recv_buf, double *send_buf, int p_to, int p_from, int tag)
send array of double from rank p_from to rank p_to. communication distinguished by tag...
static bool RegisterTest(const std::string &key, const Test_function func)
bool is_set(const string &) const
double get_double(const string &key) const
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=COMPLEX)
const std::string test_name
void crucial(const char *format,...)
void Register_Parameters(const string &, Parameters *const)
static int size()
size of small world.
Base class of random number generators.
static int reduce_sum(int count, double *recv_buf, double *send_buf, int pattern=0)
make a global sum of an array of double over the communicator. pattern specifies the dimensions to be...
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
Parameter manager with YAML parser.
static bool is_primary()
check if the present node is primary in small communicator.
int verify(const double expected, const double result)
string get_string(const string &key) const
void gather(Field *vglobal, Field *vlocal)
gather data on parallel nodes to primary node.
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
static VerboseLevel set_verbose_level(const std::string &str)
void gauss(double &rn1, double &rn2)