Bridge++  Ver. 1.3.x
test_Mult.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.h"
20 #include "gammaMatrixSet.h"
21 
22 //- profiler of fx10
23 //#include "fj_tool/fapp.h"
24 
25 //====================================================================
27 
34 namespace Test_Mult {
35  const std::string test_name = "Mult";
36 
37  //- test-private parameters
38  namespace {
39  // const std::string filename_input = "test_Mult.yaml";
40  const std::string filename_output = "stdout";
41 
42  class Parameters_Test_Mult : public Parameters {
43  public:
44  Parameters_Test_Mult()
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(const std::string&);
61 
62  //- mult for various fermions
64  {
65  return mult("test_Mult_Clover.yaml");
66  }
67 
68 
70  {
71  return mult("test_Mult_Clover_General.yaml");
72  }
73 
74 
76  {
77  return mult("test_Mult_Clover_Isochemical.yaml");
78  }
79 
80 
81  //- NB. Fopr_Clover_SF is implemented only in Chiral rep.
82  // int mult_Clover_SF()
83  // {
84  // return mult("test_Mult_Clover_SF.yaml");
85  // }
86 
87  //- NB. test_Mult_Wilson is implemented separately for beginners
88  // int mult_Wilson()
89  // {
90  // return mult("test_Mult_Wilson.yaml");
91  // }
92 
93 
95  {
96  return mult("test_Mult_Wilson_General.yaml");
97  }
98 
99 
101  {
102  return mult("test_Mult_Wilson_Isochemical.yaml");
103  }
104 
105 
106  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
107  // int mult_Wilson_SF()
108  // {
109  // return mult("test_Mult_Wilson_SF.yaml");
110  // }
111 
112 
113 #ifdef USE_TESTMANAGER_AUTOREGISTER
114  namespace {
115 #if defined(USE_GROUP_SU2)
116  // Nc=2 is not available.
117 #else
118  static const bool is_registered_Clover = TestManager::RegisterTest(
119  "Mult.Clover",
121  );
122 
123 #if defined(USE_IMP_BGQ)
124  // Imp_BGQ has not been available for Clover_General yet.
125 #else
126  static const bool is_registered_Clover_General = TestManager::RegisterTest(
127  "Mult.Clover_General",
129  );
130 #endif
131 
132  static const bool is_registered_Clover_Isochemical = TestManager::RegisterTest(
133  "Mult.Clover_Isochemical",
135  );
136 
137  //- NB. Fopr_Clover_SF is implemented only in Chiral rep.
138  // static const bool is_registered_Clover_SF = TestManager::RegisterTest(
139  // "Mult.Clover_SF",
140  // mult_Clover_SF
141  // );
142 
143 
144  //- NB. test_Mult_Wilson is implemented separately for beginners
145  // static const bool is_registered_Wilson = TestManager::RegisterTest(
146  // "Mult.Wilson",
147  // mult_Wilson
148  // );
149 
150 #if defined(USE_IMP_BGQ)
151  // Imp_BGQ has not been available for Wilson_General yet.
152 #else
153  static const bool is_registered_Wilson_General = TestManager::RegisterTest(
154  "Mult.Wilson_General",
156  );
157 #endif
158 
159  static const bool is_registered_Wilson_Isochemical = TestManager::RegisterTest(
160  "Mult.Wilson_Isochemical",
162  );
163 
164  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
165  // static const bool is_registered_Wilson_SF = TestManager::RegisterTest(
166  // "Mult.Wilson_SF",
167  // mult_Wilson_SF
168  // );
169 #endif
170  }
171 #endif
172 
173  //====================================================================
174  int mult(const std::string& filename_input)
175  {
176  // #### parameter setup ####
177  int Nc = CommonParameters::Nc();
178  int Nd = CommonParameters::Nd();
179  int Ndim = CommonParameters::Ndim();
180  int Nvol = CommonParameters::Nvol();
181 
182  int Lvol = CommonParameters::Lvol();
183  int NPE = CommonParameters::NPE();
185 
186  unique_ptr<Parameters> params_test(new Parameters_Test_Mult);
187  unique_ptr<Parameters> params_fopr(ParametersFactory::New("Fopr"));
188  unique_ptr<Parameters> params_all(new Parameters);
189 
190  params_all->Register_Parameters("Test_Mult", params_test);
191  params_all->Register_Parameters("Fopr", params_fopr);
192 
193  ParameterManager::read(filename_input, params_all);
194 
195  const string str_gconf_status = params_test->get_string("gauge_config_status");
196  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
197  const string readfile = params_test->get_string("config_filename_input");
198  const int Nmult = params_test->get_int("number_of_mult");
199  const string str_vlevel = params_test->get_string("verbose_level");
200 
201  const bool do_check = params_test->is_set("expected_result");
202  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
203 
204  const string str_fopr_type = params_fopr->get_string("fermion_type");
205  const string str_gmset_type = params_fopr->get_string("gamma_matrix_type");
206 
208 
209  //- print input parameters
210  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
211  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
212  vout.general(vl, " readfile = %s\n", readfile.c_str());
213  vout.general(vl, " Nmult = %d\n", Nmult);
214  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
215  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
216 
217  //- input parameter check
218  int err = 0;
219  err += ParameterCheck::non_NULL(str_gconf_status);
220 
221  if (err) {
222  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
223  exit(EXIT_FAILURE);
224  }
225 
226 
227  // #### Set up a gauge configuration ####
228  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
229  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
230 
231  if (str_gconf_status == "Continue") {
232  gconf_read->read_file(U, readfile);
233  } else if (str_gconf_status == "Cold_start") {
234  U->set_unit();
235  } else if (str_gconf_status == "Hot_start") {
236  int i_seed_noise = 1234567;
237  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
238  U->set_random(rand);
239  } else {
240  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
241  exit(EXIT_FAILURE);
242  }
243 
244 
245  // #### object setup #####
246  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
247 
248  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
249  fopr->set_parameters(*params_fopr);
250  fopr->set_config(U);
251  fopr->set_mode("D");
252 
253  unique_ptr<Timer> timer(new Timer(test_name));
254 
255  vout.general(vl, "\n");
256 
257 
258  // #### Execution main part ####
259  Field_F b, y;
260  b.set(1.0);
261 
262  double result = 0.0;
263 
264 
265  timer->start();
266  //- profiler of fx10 starts
267  // fapp_start("Mult",1,1);
268 
269 #pragma omp parallel
270  {
271  for (int i = 0; i < Nmult; ++i) {
272  fopr->mult(y, b);
273  }
274  result = y.norm();
275  }
276 
277 #ifdef DEBUG
278  //- additional verify for Nthread > 1
279  if (Nthread > 1) {
280  double epsilon = CommonParameters::epsilon_criterion();
281 
282  fopr->mult(y, b);
283  double result_single = y.norm();
284 
285  if (Test::verify(abs(result - result_single), 0.0, epsilon)) {
286  vout.crucial("%s: result(multithread) not equal to result(single thread)\n", test_name.c_str());
287  vout.crucial("%s: result(multithread) = %22.14e\n", test_name.c_str(), result);
288  vout.crucial("%s: result(single thread) = %22.14e\n", test_name.c_str(), result_single);
289  return EXIT_FAILURE;
290  }
291  }
292 #endif
293 
294 
295  //- profiler of fx10 ends
296  // fapp_stop("Mult",1,1);
297  timer->stop();
298  double elapse_sec = timer->elapsed_sec();
299 
300 
301  //- Flops counting
302  double gflo_mult = fopr->flop_count() / 1.0e+9;
303  double gflops_mult = gflo_mult * Nmult / (elapse_sec * NPE * Nthread);
304 
305  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
306  vout.general(vl, "\n");
307 
308 
309  if (do_check) {
310  return Test::verify(result, expected_result);
311  } else {
312  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
313  return EXIT_SKIP;
314  }
315  }
316 } // namespace Test_Mult
#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 mult_Wilson_Isochemical()
Definition: test_Mult.cpp:100
Test of Mult.
Definition: test_Mult.cpp:34
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
int mult_Wilson_General()
Definition: test_Mult.cpp:94
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
Wilson-type fermion field.
Definition: field_F.h:37
const std::string test_name
Definition: test_Mult.cpp:35
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 mult_Clover_Isochemical()
Definition: test_Mult.cpp:75
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
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
void stop()
Definition: timer.cpp:69
int mult_Clover()
Definition: test_Mult.cpp:63
int mult(const std::string &)
Definition: test_Mult.cpp:174
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28
static int NPE()
int mult_Clover_General()
Definition: test_Mult.cpp:69