36 namespace Test_RandomNumbers_SFMT {
37 const std::string
test_name =
"RandomNumbers.SFMT.Global";
41 const std::string filename_input =
"test_RandomNumbers_SFMT_Global.yaml";
47 #ifdef USE_TESTMANAGER_AUTOREGISTER
65 const int iseed = params_test.
get_int(
"int_seed");
66 const string str_vlevel = params_test.
get_string(
"verbose_level");
68 const bool do_check = params_test.
is_set(
"expected_result");
69 const double expected_result = do_check ? params_test.
get_double(
"expected_result") : 0.0;
75 vout.
general(vl,
" vlevel = %s\n", str_vlevel.c_str());
87 vout.
general(vl,
"Serial and Node-parallel test of Random Number Generator:\n");
96 vout.
general(vl,
"field size: nin = %d, nex = %d, nvol = %d, lvol = %d\n", nin, nex, nvol, lvol);
99 const size_t nsample = 1024;
100 double data[nsample];
101 for (
size_t i = 0; i < nsample; ++i) {
107 Field field1(nin, nvol, nex);
110 const unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
114 rand->uniform_lex_global(field1);
117 for (
size_t i = 0; i < nsample; ++i) {
118 data[i] = rand->get();
123 Field field2(0, 0, 0);
126 const unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
128 field2.reset(nin, lvol, nex);
130 double *p = field2.ptr(0);
132 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
138 Field field1b(0, 0, 0);
141 field1b.reset(nin, lvol, nex);
146 fieldio.gather(&field1b, &field1);
152 if (field1b.size() != field2.size()) {
157 double *p1 = field1b.ptr(0);
158 double *p2 = field2.ptr(0);
160 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
161 if (*p1++ != *p2++) ++err1;
176 for (
size_t i = 0; i < nsample; ++i) {
177 if (data[i] != buf[i]) ++err2;
189 const unique_ptr<RandomNumbers_SFMT> rand(
new RandomNumbers_SFMT(iseed));
193 rand->write_file(
"RNG_SFMT.state");
197 for (
size_t i = 0; i < nsample; ++i) {
198 data[i] = rand->get();
202 rand->read_file(
"RNG_SFMT.state");
207 for (
size_t i = 0; i < nsample; ++i) {
208 if (data[i] != rand->get()) ++err3_part;
217 field1.reset(nin, nvol, nex);
220 const unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
224 rand->gauss_lex_global(field1);
228 const unique_ptr<RandomNumbers> rand(
new RandomNumbers_SFMT(iseed));
230 field2.reset(nin, lvol, nex);
232 double *p = field2.ptr(0);
234 if (field2.nin() % 2 == 0) {
237 for (
int j = 0, Nex = field2.nex(); j < Nex; ++j) {
238 for (
int isite = 0, Nvol = field2.nvol(); isite < Nvol; ++isite) {
239 for (
int i = 0, Nin = field2.nin(); i < Nin; i += 2) {
249 for (
int j = 0, Nex = field2.nex(); j < Nex; ++j) {
250 for (
int isite = 0, Nvol = field2.nvol(); isite < Nvol; ++isite) {
251 for (
int i = 0, Nin = field2.nin(); i < Nin; ++i) {
261 field1b.reset(nin, lvol, nex);
264 fieldio.gather(&field1b, &field1);
269 if (field1b.size() != field2.size()) {
274 double *p1 = field1b.ptr(0);
275 double *p2 = field2.ptr(0);
277 for (
size_t i = 0, n = field2.size(); i < n; ++i) {
278 if (*p1++ != *p2++) ++err4;
287 const double result = err1 + err2 + err3 + err4;
295 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
long long_t
definition of long for Bridge++
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)