Bridge++  Ver. 2.0.2
test_Solver_Wilson.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "IO/gaugeConfig.h"
17 
18 #include "Field/field_F.h"
22 
23 #include "Tools/gammaMatrixSet.h"
25 
26 using std::round;
27 
28 //====================================================================
30 
36 namespace Test_Solver_Wilson {
37  const std::string test_name = "Solver.Wilson";
38 
39  //- test-private parameters
40  namespace {
41  // const std::string filename_input = "test_Solver_Wilson.yaml";
42  }
43 
44  //- prototype declaration
45  int solver(const std::string&);
46 
47  //- solver for various algorithms
49  {
50  return solver("test_Solver_Wilson_BiCGStab_Cmplx.yaml");
51  }
52 
53 
55  {
56  return solver("test_Solver_Wilson_BiCGStab_DS_L_Cmplx.yaml");
57  }
58 
59 
61  {
62  return solver("test_Solver_Wilson_BiCGStab_IDS_L_Cmplx.yaml");
63  }
64 
65 
67  {
68  return solver("test_Solver_Wilson_BiCGStab_L_Cmplx.yaml");
69  }
70 
71 
73  {
74  return solver("test_Solver_Wilson_CGNE.yaml");
75  }
76 
77 
79  {
80  return solver("test_Solver_Wilson_CGNR.yaml");
81  }
82 
83 
85  {
86  return solver("test_Solver_Wilson_GMRES_m_Cmplx.yaml");
87  }
88 
89 
90 #ifdef USE_TESTMANAGER_AUTOREGISTER
91  namespace {
92 #if defined(USE_GROUP_SU2)
93  // Nc=2 is not available.
94 #else
95  static const bool is_registered_BiCGStab_Cmplx = TestManager::RegisterTest(
96  "Solver.Wilson.BiCGStab_Cmplx",
98  );
99 
100  static const bool is_registered_BiCGStab_DS_L_Cmplx = TestManager::RegisterTest(
101  "Solver.Wilson.BiCGStab_DS_L_Cmplx",
103  );
104 
105  static const bool is_registered_BiCGStab_IDS_L_Cmplx = TestManager::RegisterTest(
106  "Solver.Wilson.BiCGStab_IDS_L_Cmplx",
108  );
109 
110  static const bool is_registered_BiCGStab_L_Cmplx = TestManager::RegisterTest(
111  "Solver.Wilson.BiCGStab_L_Cmplx",
113  );
114 
115  static const bool is_registered_CGNE = TestManager::RegisterTest(
116  "Solver.Wilson.CGNE",
118  );
119 
120  static const bool is_registered_CGNR = TestManager::RegisterTest(
121  "Solver.Wilson.CGNR",
123  );
124 
125  static const bool is_registered_GMRES_m_Cmplx = TestManager::RegisterTest(
126  "Solver.Wilson.GMRES_m_Cmplx",
128  );
129 #endif
130  }
131 #endif
132 
133  //====================================================================
134  int solver(const std::string& filename_input)
135  {
136  // #### parameter setup ####
137  const int Nc = CommonParameters::Nc();
138  const int Nd = CommonParameters::Nd();
139  const int Ndim = CommonParameters::Ndim();
140  const int Nvol = CommonParameters::Nvol();
141 
142  const int NPE = CommonParameters::NPE();
143  const int Nthread = ThreadManager::get_num_threads_available();
144 
145  const Parameters params_all = ParameterManager::read(filename_input);
146 
147  const Parameters params_test = params_all.lookup("Test_Solver");
148  const Parameters params_gfix = params_all.lookup("GaugeFixing");
149  const Parameters params_fopr = params_all.lookup("Fopr");
150  const Parameters params_solver = params_all.lookup("Solver");
151  const Parameters params_source = params_all.lookup("Source");
152 
153  const string str_gconf_status = params_test.get_string("gauge_config_status");
154  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
155  const string readfile = params_test.get_string("config_filename_input");
156  const string str_rand_type = params_test.get_string("random_number_type");
157  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
158  const string str_vlevel = params_test.get_string("verbose_level");
159 
160  const bool do_check = params_test.is_set("expected_result");
161  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
162 
163  const string str_gfix_type = params_gfix.get_string("gauge_fixing_type");
164  const string str_fopr_type = params_fopr.get_string("fermion_type");
165  const string str_solver_type = params_solver.get_string("solver_type");
166  const string str_source_type = params_source.get_string("source_type");
167 
168  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
169 
170  //- print input parameters
171  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
172  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
173  vout.general(vl, " readfile = %s\n", readfile.c_str());
174  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
175  vout.general(vl, " seed = %lu\n", seed);
176  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
177  vout.general(vl, " gfix_type = %s\n", str_gfix_type.c_str());
178  vout.general(vl, " solver_type = %s\n", str_solver_type.c_str());
179  vout.general(vl, " source_type = %s\n", str_source_type.c_str());
180 
181  //- input parameter check
182  int err = 0;
183  err += ParameterCheck::non_NULL(str_gconf_status);
184 
185  if (err) {
186  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
187  exit(EXIT_FAILURE);
188  }
189 
190  if (str_solver_type == "CG") {
191  vout.crucial(vl, "Error at %s: CG can not be adopted. Use CGNE,CGNR, instead.\n", test_name.c_str());
192  exit(EXIT_FAILURE);
193  }
194 
195  RandomNumberManager::initialize(str_rand_type, seed);
196 
197 
198  // #### Set up a gauge configuration ####
199  Field_G U(Nvol, Ndim);
200 
201  if (str_gconf_status == "Continue") {
202  GaugeConfig(str_gconf_read).read(U, readfile);
203  } else if (str_gconf_status == "Cold_start") {
204  GaugeConfig("Unit").read(U);
205  } else if (str_gconf_status == "Hot_start") {
206  GaugeConfig("Random").read(U);
207  } else {
208  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
209  exit(EXIT_FAILURE);
210  }
211 
212 
213  // #### Gauge fixing ####
214  {
215  Field_G Ufix(Nvol, Ndim);
216  unique_ptr<GaugeFixing> gfix(GaugeFixing::New(str_gfix_type, params_gfix));
217 
218  gfix->fix(Ufix, U);
219  copy(U, Ufix);
220  }
221 
222 
223  // #### object setup #####
224  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, params_fopr));
225  fopr->set_config(&U);
226 
227  unique_ptr<Solver> solver(Solver::New(str_solver_type, fopr.get(), params_solver));
228 
229  unique_ptr<Fprop> fprop_lex(new Fprop_Standard_lex(solver.get()));
230 
231  unique_ptr<Source> source(Source::New(str_source_type, params_source));
232 
233  Timer timer(test_name);
234 
235 
236  // #### Execution main part ####
237  timer.start();
238 
239  std::vector<Field_F> sq(Nc * Nd);
240  for (int i_cd = 0; i_cd < Nc * Nd; ++i_cd) {
241  sq[i_cd].set(0.0);
242  }
243 
244  vout.general(vl, "\n");
245  vout.general(vl, "Solving quark propagator:\n");
246  vout.general(vl, " color spin Nconv diff diff2\n");
247 
248  int ispin = 0;
249  // for (int ispin = 0; ispin < Nd; ++ispin) {
250 
251  int icolor = 0;
252  // for (int icolor = 0; icolor < Nc; ++icolor) {
253  int i_cd = icolor + Nc * ispin;
254 
255  Field_F b; // b.set(0.0);
256  source->set(b, i_cd);
257 
258  int Nconv;
259  double diff;
260  fprop_lex->invert_D(sq[i_cd], b, Nconv, diff);
261 
262  Field_F y(b);
263  fopr->set_mode("D");
264  fopr->mult(y, sq[i_cd]); // y = fopr->mult(sq[i_cd]);
265  axpy(y, -1.0, b); // y -= b;
266  double diff2 = y.norm2() / b.norm2();
267 
268  vout.general(vl, " %2d %2d %6d %12.4e %12.4e\n",
269  icolor, ispin, Nconv, diff, diff2);
270  // }
271  // }
272 
273  const double result = round(Nconv / 10.0);
274 
275  timer.report();
276  const double elapse_sec = timer.elapsed_sec();
277 
278 
279  //- Flops counting in giga unit
280  const double gflops_mult = fprop_lex->flop_count() / (elapse_sec * NPE * Nthread);
281 
282  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
283  vout.general(vl, "\n");
284 
285 
287 
288 
289  if (do_check) {
290  return Test::verify(result, expected_result);
291  } else {
292  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
293  return EXIT_SKIP;
294  }
295  }
296 } // namespace Test_Solver_Wilson
Test_Solver_Wilson::solver_BiCGStab_DS_L_Cmplx
int solver_BiCGStab_DS_L_Cmplx()
Definition: test_Solver_Wilson.cpp:54
Test::verify
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
ParameterCheck::non_NULL
int non_NULL(const std::string v)
Definition: parameterCheck.cpp:65
Fprop_Standard_lex
Get quark propagator for Fopr with lexical site index.
Definition: fprop_Standard_lex.h:33
field_F.h
Test_Solver_Wilson::solver_BiCGStab_Cmplx
int solver_BiCGStab_Cmplx()
Definition: test_Solver_Wilson.cpp:48
CommonParameters::Ndim
static int Ndim()
Definition: commonParameters.h:117
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
GaugeConfig::read
void read(Field_G &U, const string &filename=string())
Definition: gaugeConfig.cpp:121
fprop_Standard_lex.h
gaugeConfig.h
CommonParameters::Nvol
static int Nvol()
Definition: commonParameters.h:109
axpy
void axpy(Field &y, const double a, const Field &x)
axpy(y, a, x): y := a * x + y
Definition: field.cpp:380
source.h
Timer
Definition: timer.h:31
RandomNumberManager::finalize
static void finalize()
Definition: randomNumberManager.cpp:80
copy
void copy(Field &y, const Field &x)
copy(y, x): y = x
Definition: field.cpp:212
Test_Solver_Wilson::solver_CGNR
int solver_CGNR()
Definition: test_Solver_Wilson.cpp:78
RandomNumberManager::initialize
static bool initialize(const std::string &rng_type, unsigned long seed)
Definition: randomNumberManager.cpp:57
Field::norm2
double norm2() const
Definition: field.cpp:113
Timer::start
void start()
Definition: timer.cpp:44
CommonParameters::Nc
static int Nc()
Definition: commonParameters.h:115
ParameterCheck::vl
Bridge::VerboseLevel vl
Definition: parameterCheck.cpp:18
Test_Solver_Wilson::solver_BiCGStab_IDS_L_Cmplx
int solver_BiCGStab_IDS_L_Cmplx()
Definition: test_Solver_Wilson.cpp:60
test.h
Test_Solver_Wilson::solver_CGNE
int solver_CGNE()
Definition: test_Solver_Wilson.cpp:72
ParameterManager::read
static void read(const std::string &params_file, Parameters &params)
Definition: parameterManager.cpp:33
Test_Solver_Wilson::test_name
const std::string test_name
Definition: test_Solver_Wilson.cpp:37
Parameters::get_double
double get_double(const string &key) const
Definition: parameters.cpp:175
CommonParameters::NPE
static int NPE()
Definition: commonParameters.h:101
Test_Solver_Wilson::solver
int solver(const std::string &)
Definition: test_Solver_Wilson.cpp:134
Parameters::get_unsigned_long
unsigned long get_unsigned_long(const string &key) const
Definition: parameters.cpp:209
EXIT_SKIP
#define EXIT_SKIP
Definition: test.h:17
ThreadManager::get_num_threads_available
static int get_num_threads_available()
returns number of threads (works outside of parallel region).
Definition: threadManager.h:86
CommonParameters::Nd
static int Nd()
Definition: commonParameters.h:116
randomNumberManager.h
GaugeConfig
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:80
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
Test_Solver_Wilson::solver_BiCGStab_L_Cmplx
int solver_BiCGStab_L_Cmplx()
Definition: test_Solver_Wilson.cpp:66
Field_F
Wilson-type fermion field.
Definition: field_F.h:37
Parameters::get_string
string get_string(const string &key) const
Definition: parameters.cpp:221
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Timer::elapsed_sec
double elapsed_sec() const
Definition: timer.cpp:107
Bridge::VerboseLevel
VerboseLevel
Definition: bridgeIO.h:42
Field_G
SU(N) gauge field.
Definition: field_G.h:38
gaugeFixing.h
Test_Solver_Wilson::solver_GMRES_m_Cmplx
int solver_GMRES_m_Cmplx()
Definition: test_Solver_Wilson.cpp:84
Test_Solver_Wilson
Test of Solver with Wilson fermion.
Definition: test_Solver_Wilson.cpp:36
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
gammaMatrixSet.h
Parameters::lookup
Parameters lookup(const string &key) const
Definition: parameters.h:79
Timer::report
void report(const Bridge::VerboseLevel vl=Bridge::GENERAL)
Definition: timer.cpp:128
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