Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
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  const unique_ptr<FFT> fft(FFT::New(str_fft_type));
109  fft->set_parameters(params_fft);
110 
111  const unique_ptr<Source> source(Source::New(str_source_type));
112  source->set_parameters(params_source);
113 
114  const unique_ptr<Index_lex> index(new Index_lex);
115  const unique_ptr<Timer> timer(new Timer(test_name));
116 
117 
118  // #### Execution main part ####
119  Field_F b;
120  b.set(0.0);
121 
122  const int i_spin = 0;
123  const int i_color = 0;
124 
125  const int idx = i_color + Nc * i_spin;
126  source->set(b, idx);
127  vout.general(vl, "b.norm2(before FFT) = %e\n", b.norm2());
128 
129 
130  timer->start();
131 
132  fft->fft(b);
133  vout.general(vl, "b.norm2(after FFT) = %e\n", b.norm2());
134 
135  double result = 0.0;
136  if (Communicator::nodeid() == 0) {
137  const int i_site = index->site(0, 0, 0, 0);
138  result = b.cmp_r(i_color, i_spin, i_site);
139  }
140 
141  timer->report();
142 
143 
144  if (do_check) {
145  return Test::verify(result, expected_result);
146  } else {
147  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
148  return EXIT_SKIP;
149  }
150  }
151 } // namespace Test_FFT
152 #endif
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
static int NPEy()
double norm2() const
Definition: field.cpp:592
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
void general(const char *format,...)
Definition: bridgeIO.cpp:197
const std::string test_name
Class for parameters.
Definition: parameters.h:46
Wilson-type fermion field.
Definition: field_F.h:37
Parameters lookup(const string &key) const
Definition: parameters.h:79
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:69
double get_double(const string &key) const
Definition: parameters.cpp:175
Lexical site index.
Definition: index_lex.h:34
bool is_set(const string &key) const
Definition: parameters.cpp:528
static int NPEx()
static void read(const std::string &params_file, Parameters &params)
static int NPEz()
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
VerboseLevel
Definition: bridgeIO.h:42
static int nodeid()
alternative name for self().
Definition: communicator.h:105
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
double cmp_r(const int cc, const int s, const int site, const int e=0) const
Definition: field_F.h:94