Bridge++  Ver. 1.3.x
test_Mult_Wilson.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "gaugeConfig.h"
17 #include "randomNumbers_Mseries.h"
18 
19 #include "fopr_Wilson.h"
20 #include "gammaMatrixSet.h"
21 
22 //- profiler of fx10
23 //#include "fj_tool/fapp.h"
24 
25 //====================================================================
27 
34 namespace Test_Mult_Wilson {
35  const std::string test_name = "Mult.Wilson";
36 
37  //- test-private parameters
38  namespace {
39  const std::string filename_input = "test_Mult_Wilson.yaml";
40  const std::string filename_output = "stdout";
41 
42  class Parameters_Test_Mult_Wilson : public Parameters {
43  public:
44  Parameters_Test_Mult_Wilson()
45  {
46  Register_string("gauge_config_status", "NULL");
47  Register_string("gauge_config_type_input", "NULL");
48  Register_string("config_filename_input", "NULL");
49 
50  Register_int("number_of_mult", 0);
51 
52  Register_string("verbose_level", "NULL");
53 
54  Register_double("expected_result", 0.0);
55  }
56  };
57  }
58 
59  //- prototype declaration
60  int mult(void);
61 
62 #ifdef USE_TESTMANAGER_AUTOREGISTER
63  namespace {
64  static const bool is_registered = TestManager::RegisterTest(
65  test_name,
66  mult
67  );
68  }
69 #endif
70 
71  //====================================================================
72  int mult(void)
73  {
74  // #### parameter setup ####
75  int Nc = CommonParameters::Nc();
76  int Nd = CommonParameters::Nd();
77  int Ndim = CommonParameters::Ndim();
78  int Nvol = CommonParameters::Nvol();
79 
80  int Lvol = CommonParameters::Lvol();
81  int NPE = CommonParameters::NPE();
83 
84  unique_ptr<Parameters> params_test(new Parameters_Test_Mult_Wilson);
85  unique_ptr<Parameters> params_fopr(ParametersFactory::New("Fopr.Wilson"));
86  unique_ptr<Parameters> params_all(new Parameters);
87 
88  params_all->Register_Parameters("Test_Mult", params_test);
89  params_all->Register_Parameters("Fopr", params_fopr);
90 
91  ParameterManager::read(filename_input, params_all);
92 
93  const string str_gconf_status = params_test->get_string("gauge_config_status");
94  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
95  const string readfile = params_test->get_string("config_filename_input");
96  const int Nmult = params_test->get_int("number_of_mult");
97  const string str_vlevel = params_test->get_string("verbose_level");
98 
99  const bool do_check = params_test->is_set("expected_result");
100  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
101 
102  const string str_gmset_type = params_fopr->get_string("gamma_matrix_type");
103  const int Ns = params_fopr->get_int("extent_of_5th_dimension");
104 
106 
107  //- print input parameters
108  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
109  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
110  vout.general(vl, " readfile = %s\n", readfile.c_str());
111  vout.general(vl, " Nmult = %d\n", Nmult);
112  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
113  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
114 
115  //- input parameter check
116  int err = 0;
117  err += ParameterCheck::non_NULL(str_gconf_status);
118 
119  if (err) {
120  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
121  exit(EXIT_FAILURE);
122  }
123 
124 
125  // #### Set up a gauge configuration ####
126  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
127  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
128 
129  if (str_gconf_status == "Continue") {
130  gconf_read->read_file(U, readfile);
131  } else if (str_gconf_status == "Cold_start") {
132  U->set_unit();
133  } else if (str_gconf_status == "Hot_start") {
134  int i_seed_noise = 1234567;
135  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
136  U->set_random(rand);
137  } else {
138  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
139  exit(EXIT_FAILURE);
140  }
141 
142 
143  // #### object setup #####
144  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
145 
146  unique_ptr<Fopr> fopr(Fopr::New("Wilson", str_gmset_type));
147  fopr->set_parameters(*params_fopr);
148  fopr->set_config(U);
149  fopr->set_mode("D");
150 
151  unique_ptr<Timer> timer(new Timer(test_name));
152 
153  vout.general(vl, "\n");
154 
155 
156  // #### Execution main part ####
157  Field_F b, y;
158  b.set(1.0);
159 
160  double result = 0.0;
161 
162  timer->start();
163  //- profiler of fx10 starts
164  // fapp_start("Mult.Domainwall",1,1);
165 
166 #pragma omp parallel
167  {
168  for (int i = 0; i < Nmult; ++i) {
169  fopr->mult(y, b);
170  }
171  result = y.norm();
172  }
173 
174 
175 #ifdef DEBUG
176  //- additional verify for Nthread > 1
177  if (Nthread > 1) {
178  double epsilon = CommonParameters::epsilon_criterion();
179 
180  fopr->mult(y, b);
181  double result_single = y.norm();
182 
183  if (Test::verify(abs(result - result_single), 0.0, epsilon)) {
184  vout.crucial("%s: result(multithread) not equal to result(single thread)\n", test_name.c_str());
185  vout.crucial("%s: result(multithread) = %22.14e\n", test_name.c_str(), result);
186  vout.crucial("%s: result(single thread) = %22.14e\n", test_name.c_str(), result_single);
187  return EXIT_FAILURE;
188  }
189  }
190 #endif
191 
192  //- profiler of fx10 ends
193  // fapp_stop("Mult.Wilson",1,1);
194  timer->stop();
195  double elapse_sec = timer->elapsed_sec();
196 
197 
198  //- Flops counting
199  double gflo_mult = fopr->flop_count() / 1.0e+9;
200  double gflops_mult = gflo_mult * Nmult / (elapse_sec * NPE * Nthread);
201 
202  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
203  vout.general(vl, "\n");
204 
205 
206  if (do_check) {
207  return Test::verify(result, expected_result);
208  } else {
209  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
210  return EXIT_SKIP;
211  }
212  }
213 } // namespace Test_Mult_Wilson
#define EXIT_SKIP
Definition: test.h:17
Random number generator base on M-series.
BridgeIO vout
Definition: bridgeIO.cpp:278
void detailed(const char *format,...)
Definition: bridgeIO.cpp:82
static double epsilon_criterion()
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:155
double elapsed_sec() const
Definition: timer.cpp:107
void general(const char *format,...)
Definition: bridgeIO.cpp:65
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
int get_int(const string &key) const
Definition: parameters.cpp:42
Class for parameters.
Definition: parameters.h:38
static int Lvol()
static Parameters * New(const std::string &realm)
void read_file(Field *U, const string &filename)
Definition: gaugeConfig.cpp:56
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
Wilson-type fermion field.
Definition: field_F.h:37
void set_unit()
Definition: field_G_imp.cpp:39
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
SU(N) gauge field.
Definition: field_G.h:38
bool is_set(const string &) const
Definition: parameters.cpp:372
double get_double(const string &key) const
Definition: parameters.cpp:27
virtual double flop_count()
returns the flops per site.
Definition: fopr.h:110
double norm() const
Definition: field.h:240
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)
Definition: checker.cpp:61
void start()
Definition: timer.cpp:44
void crucial(const char *format,...)
Definition: bridgeIO.cpp:48
void Register_Parameters(const string &, Parameters *const)
Definition: parameters.cpp:358
int verify(const double result, const double expected, double eps)
Definition: test.cpp:27
Bridge::VerboseLevel vl
Definition: checker.cpp:18
VerboseLevel
Definition: bridgeIO.h:39
virtual void mult(Field &, const Field &)=0
multiplies fermion operator to a given field (2nd argument)
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:85
const std::string test_name
static void read(const std::string &params_file, Parameters *params)
GaugeConfig class for file I/O of gauge configuration.
Definition: gaugeConfig.h:61
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:87
Test of Mult with Wilson fermion, prepared for beginners.
void stop()
Definition: timer.cpp:69
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28
static int NPE()