34 namespace Test_RandomNumbers_SFMT {
35 const std::string
test_name =
"RandomNumbers.SFMT.Global";
39 const std::string filename_input =
"test_RandomNumbers_SFMT_Global.yaml";
45 #ifdef USE_TESTMANAGER_AUTOREGISTER
63 int iseed = params_test.
get_int(
"int_seed");
64 const string str_vlevel = params_test.
get_string(
"verbose_level");
66 const bool do_check = params_test.
is_set(
"expected_result");
67 const double expected_result = do_check ? params_test.
get_double(
"expected_result") : 0.0;
73 vout.
general(vl,
" vlevel = %s\n", str_vlevel.c_str());
85 vout.
general(vl,
"Serial and Node-parallel test of Random Number Generator:\n");
94 vout.
general(vl,
"field size: nin = %d, nex = %d, nvol = %d, lvol = %d\n", nin, nex, nvol, lvol);
97 const size_t nsample = 1024;
99 for (
size_t i = 0; i < nsample; ++i) {
105 Field field1(nin, nvol, nex);
108 unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
112 rand->uniform_lex_global(field1);
115 for (
size_t i = 0; i < nsample; ++i) {
116 data[i] = rand->get();
121 Field field2(0, 0, 0);
124 unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
126 field2.reset(nin, lvol, nex);
128 double *p = field2.ptr(0);
130 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
136 Field field1b(0, 0, 0);
139 field1b.reset(nin, lvol, nex);
144 fieldio.gather(&field1b, &field1);
150 if (field1b.size() != field2.size()) {
155 double *p1 = field1b.ptr(0);
156 double *p2 = field2.ptr(0);
158 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
159 if (*p1++ != *p2++) ++err1;
174 for (
size_t i = 0; i < nsample; ++i) {
175 if (data[i] != buf[i]) ++err2;
187 unique_ptr<RandomNumbers_SFMT> rand(
new RandomNumbers_SFMT(iseed));
191 rand->write_file(
"RNG_SFMT.state");
195 for (
size_t i = 0; i < nsample; ++i) {
196 data[i] = rand->get();
200 rand->read_file(
"RNG_SFMT.state");
205 for (
size_t i = 0; i < nsample; ++i) {
206 if (data[i] != rand->get()) ++err3_part;
215 field1.reset(nin, nvol, nex);
218 unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
222 rand->gauss_lex_global(field1);
226 unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
228 field2.reset(nin, lvol, nex);
230 double *p = field2.ptr(0);
232 if (field2.nin() % 2 == 0) {
235 for (
int j = 0, Nex = field2.nex(); j < Nex; ++j) {
236 for (
int isite = 0, Nvol = field2.nvol(); isite < Nvol; ++isite) {
237 for (
int i = 0, Nin = field2.nin(); i < Nin; i += 2) {
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) {
259 field1b.reset(nin, lvol, nex);
262 fieldio.gather(&field1b, &field1);
267 if (field1b.size() != field2.size()) {
272 double *p1 = field1b.ptr(0);
273 double *p2 = field2.ptr(0);
275 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
276 if (*p1++ != *p2++) ++err4;
285 double result = err1 + err2 + err3 + err4;
293 vout.
detailed(vl,
"check skipped: expected_result not set.\n\n");
void detailed(const char *format,...)
void general(const char *format,...)
const std::string test_name
Container of Field-type object.
FieldIO_Text class for file I/O of Field data in plain text format.
int get_int(const string &key) const
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...
Parameters lookup(const string &key) const
static bool RegisterTest(const std::string &key, const Test_function func)
double get_double(const string &key) const
bool is_set(const string &key) const
void crucial(const char *format,...)
static void read(const std::string ¶ms_file, Parameters ¶ms)
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 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
static VerboseLevel set_verbose_level(const std::string &str)