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;
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 RandomNumbers_SFMT rand(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 RandomNumbers_SFMT rand(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 RandomNumbers_SFMT rand(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 RandomNumbers_SFMT rand(iseed);
224 rand.gauss_lex_global(field1);
228 RandomNumbers_SFMT rand(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;