33 const std::string
test_name =
"RandomNumbers.MT19937.Global";
37 const std::string filename_input =
"test_RandomNumbers_MT19937_Global.yaml";
38 const std::string filename_output =
"stdout";
40 class Parameters_Test_RandomNumbers :
public Parameters {
42 Parameters_Test_RandomNumbers()
44 Register_int(
"seed", 0);
46 Register_string(
"verbose_level",
"NULL");
48 Register_double(
"expected_result", 0.0);
56 #ifdef USE_TESTMANAGER_AUTOREGISTER
76 int seed = params_test->
get_int(
"seed");
77 const string str_vlevel = params_test->
get_string(
"verbose_level");
79 const bool do_check = params_test->
is_set(
"expected_result");
80 const double expected_result = do_check ? params_test->
get_double(
"expected_result") : 0.0;
86 vout.
general(vl,
" vlevel = %s\n", str_vlevel.c_str());
98 vout.
general(vl,
"Serial and Node-parallel test of Random Number Generator:\n");
109 const size_t nsample = 1024;
110 double data[nsample];
111 for (
size_t i = 0; i < nsample; ++i) {
117 Field field1(nin, nvol, nex);
127 for (
size_t i = 0; i < nsample; ++i) {
128 data[i] = rand->
get();
133 Field field2(0, 0, 0);
138 field2.
reset(nin, lvol, nex);
140 double *p = field2.
ptr(0);
142 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
148 Field field1b(0, 0, 0);
151 field1b.
reset(nin, lvol, nex);
156 fieldio.
gather(&field1b, &field1);
162 if (field1b.
size() != field2.
size()) {
163 vout.
crucial(vl,
"%s: field size mismatch.\n", test_name.c_str());
167 double *p1 = field1b.
ptr(0);
168 double *p2 = field2.
ptr(0);
170 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
171 if (*p1++ != *p2++) ++err1;
176 vout.
general(vl,
"%s: serial and parallel: err = %d\n", test_name.c_str(), err1);
186 for (
size_t i = 0; i < nsample; ++i) {
187 if (data[i] != buf[i]) ++err2;
192 vout.
general(vl,
"%s: check local state at rank %d, err = %d\n", test_name.c_str(), ipe, err2);
205 vout.
detailed(
"%s: number of samples = %lu\n", test_name.c_str(), nsample);
207 for (
size_t i = 0; i < nsample; ++i) {
208 data[i] = rand->
get();
212 rand->
readfile(
"RNG_MT19937.state");
217 for (
size_t i = 0; i < nsample; ++i) {
218 if (data[i] != rand->
get()) ++err3_part;
223 vout.
general(vl,
"%s: save/restore test: err = %d\n", test_name.c_str(), err3);
227 field1.
reset(nin, nvol, nex);
240 field2.
reset(nin, lvol, nex);
242 double *p = field2.
ptr(0);
244 if (field2.
nin() % 2 == 0) {
247 for (
int j = 0, Nex = field2.
nex(); j < Nex; ++j) {
248 for (
int isite = 0, Nvol = field2.
nvol(); isite < Nvol; ++isite) {
249 for (
int i = 0, Nin = field2.
nin(); i < Nin; i += 2) {
259 for (
int j = 0, Nex = field2.
nex(); j < Nex; ++j) {
260 for (
int isite = 0, Nvol = field2.
nvol(); isite < Nvol; ++isite) {
261 for (
int i = 0, Nin = field2.
nin(); i < Nin; ++i) {
271 field1b.
reset(nin, lvol, nex);
274 fieldio.
gather(&field1b, &field1);
279 if (field1b.
size() != field2.
size()) {
280 vout.
crucial(vl,
"%s: field size mismatch.\n", test_name.c_str());
284 double *p1 = field1b.
ptr(0);
285 double *p2 = field2.
ptr(0);
287 for (
size_t i = 0, n = field2.
size(); i < n; ++i) {
288 if (*p1++ != *p2++) ++err4;
293 vout.
general(vl,
"%s: serial and parallel for gaussian: err = %d\n", test_name.c_str(), err4);
297 double result = err1 + err2 + err3 + err4;
305 vout.
detailed(vl,
"check skipped: expected_result not set.\n\n");
void writefile(const std::string &)
void detailed(const char *format,...)
const double * ptr(const int jin, const int site, const int jex) const
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,...)
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)
int verify(const double result, const double expected, double eps)
static int size()
size of small world.
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 void read(const std::string ¶ms_file, Parameters *params)
static int broadcast(int count, double *data, int sender)
broadcast array of double from sender.
static bool is_primary()
check if the present node is primary in small communicator.
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)
void gauss(double &rand1, double &rand2)
static VerboseLevel set_verbose_level(const std::string &str)
Test of random number generator.