Bridge++  Ver. 2.0.2
test_FFT.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Tools/fft.h"
17 
18 #include "Field/field_F.h"
20 
21 //====================================================================
23 
28 #ifdef USE_FFTWLIB
29 namespace Test_FFT {
30  const std::string test_name = "FFT.fft";
31 
32  //- test-private parameters
33  namespace {
34  const std::string filename_input = "test_FFT.yaml";
35  }
36 
37  //- prototype declaration
38  int fft(void);
39 
40 #ifdef USE_TESTMANAGER_AUTOREGISTER
41  namespace {
42  static const bool is_registered = TestManager::RegisterTest(
43  test_name,
44  fft
45  );
46  }
47 #endif
48 
49  //====================================================================
50  int fft(void)
51  {
52  // #### parameter setup ####
53  //- global lattice size
54  const int Lt = CommonParameters::Lt();
55 
56  //- local size
57  const int Nx = CommonParameters::Nx();
58  const int Ny = CommonParameters::Ny();
59  const int Nz = CommonParameters::Nz();
60  const int Nvol = CommonParameters::Nvol();
61 
62  const int Nc = CommonParameters::Nc();
63 
64  const Parameters params_all = ParameterManager::read(filename_input);
65 
66  const Parameters params_test = params_all.lookup("Test_FFT");
67  const Parameters params_fft = params_all.lookup("FFT");
68  const Parameters params_source = params_all.lookup("Source");
69 
70  const string str_vlevel = params_test.get_string("verbose_level");
71 
72  const bool do_check = params_test.is_set("expected_result");
73  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
74 
75  const string str_fft_type = params_fft.get_string("FFT_type");
76  const string str_source_type = params_source.get_string("source_type");
77 
78  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
79 
80 
81  // #### check conditions ####
82  int NPEx = CommonParameters::NPEx();
83  int NPEy = CommonParameters::NPEy();
84  int NPEz = CommonParameters::NPEz();
85  int NPEt = CommonParameters::NPEt();
86 
87  if (str_fft_type == "FFT_xyz_1dim") {
88  if ((NPEt == 1) &&
89  ((NPEx * NPEy == 1) || (NPEx * NPEz == 1) || (NPEy * NPEz == 1)))
90  {
91  // ok.
92  } else {
93  vout.general(vl, "%s: FFT_xyz_1dim supports parallelization in one direction among x, y, z. skip.\n", test_name.c_str());
94  return EXIT_SKIP;
95  }
96  } else if (str_fft_type == "FFT_xyz_3dim") {
97  if ((NPEt == 1) && (NPEx == 1) && (NPEy == 1) && (NPEz == 1))
98  {
99  // ok.
100  } else {
101  vout.general(vl, "%s: FFT_xyz_3dim supports parallelization only in z direction. skip.\n", test_name.c_str());
102  return EXIT_SKIP;
103  }
104  }
105 
106 
107  // #### object setup #####
108  unique_ptr<FFT> fft(FFT::New(str_fft_type, params_fft));
109 
110  unique_ptr<Source> source(Source::New(str_source_type, params_source));
111 
112  Index_lex index;
113 
114  Timer timer(test_name);
115 
116 
117  // #### Execution main part ####
118  Field_F b;
119  b.set(0.0);
120 
121  const int i_spin = 0;
122  const int i_color = 0;
123 
124  const int idx = i_color + Nc * i_spin;
125  source->set(b, idx);
126  vout.general(vl, "b.norm2(before FFT) = %e\n", b.norm2());
127 
128 
129  timer.start();
130 
131  fft->fft(b);
132  vout.general(vl, "b.norm2(after FFT) = %e\n", b.norm2());
133 
134  double result = 0.0;
135  if (Communicator::nodeid() == 0) {
136  const int i_site = index.site(0, 0, 0, 0);
137  result = b.cmp_r(i_color, i_spin, i_site);
138  }
139 
140  timer.report();
141 
142 
143  if (do_check) {
144  return Test::verify(result, expected_result);
145  } else {
146  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
147  return EXIT_SKIP;
148  }
149  }
150 } // namespace Test_FFT
151 #endif
CommonParameters::Ny
static int Ny()
Definition: commonParameters.h:106
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
CommonParameters::Nz
static int Nz()
Definition: commonParameters.h:107
Test_Eigensolver::test_name
const std::string test_name
Definition: test_Eigensolver.cpp:40
field_F.h
Index_lex
Lexical site index.
Definition: index_lex.h:34
Field::set
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
Parameters
Class for parameters.
Definition: parameters.h:46
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
source.h
Timer
Definition: timer.h:31
Field::norm2
double norm2() const
Definition: field.cpp:113
CommonParameters::Nx
static int Nx()
Definition: commonParameters.h:105
CommonParameters::Lt
static int Lt()
Definition: commonParameters.h:94
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Field_F::cmp_r
double cmp_r(const int cc, const int s, const int site, const int e=0) const
Definition: field_F.h:94
CommonParameters::NPEz
static int NPEz()
Definition: commonParameters.h:99
AIndex_eo_qxs::idx
int idx(const int in, const int Nin, const int ist, const int Nx2, const int Ny, const int leo, const int Nvol2, const int ex)
Definition: aindex_eo.h:27
test.h
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
Index_lex::site
int site(const int &x, const int &y, const int &z, const int &t) const
Definition: index_lex.h:55
CommonParameters::NPEy
static int NPEy()
Definition: commonParameters.h:98
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
Parameters::is_set
bool is_set(const string &key) const
Definition: parameters.cpp:525
CommonParameters::NPEx
static int NPEx()
Definition: commonParameters.h:97
fft.h
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
CommonParameters::NPEt
static int NPEt()
Definition: commonParameters.h:100
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
TestManager::RegisterTest
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69