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