Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Mult.cpp
Go to the documentation of this file.
1 
14 #include "test.h"
15 
16 #include "Fopr/fopr.h"
17 
18 #include "IO/gaugeConfig.h"
19 
20 #include "Tools/gammaMatrixSet.h"
22 
23 //- profiler
24 #ifdef FUJITSU_FX
25 # ifdef __has_include
26 # if __has_include(<fj_tool/fapp.h>)
27 # include <fj_tool/fapp.h>
28 # endif
29 # endif
30 #endif
31 
32 //====================================================================
34 
42 namespace Test_Mult {
43  const std::string test_name = "Mult";
44 
45  //- test-private parameters
46  namespace {
47  // const std::string filename_input = "test_Mult.yaml";
48  }
49 
50  //- prototype declaration
51  int mult(const std::string&);
52 
53  //- mult for various fermions
55  {
56  return mult("test_Mult_Clover.yaml");
57  }
58 
59 
61  {
62  return mult("test_Mult_CloverGeneral.yaml");
63  }
64 
65 
67  {
68  return mult("test_Mult_Clover_Isochemical.yaml");
69  }
70 
71 
72  //- NB. Fopr_Clover_SF is implemented only in Chiral rep.
73  // int mult_Clover_SF()
74  // {
75  // return mult("test_Mult_Clover_SF.yaml");
76  // }
77 
78 
79  // int mult_TMWilson()
80  // {
81  // return mult("test_Mult_TMWilson.yaml");
82  // }
83 
84 
85  //- NB. test_Mult_Wilson is implemented separately for beginners
86  // int mult_Wilson()
87  // {
88  // return mult("test_Mult_Wilson.yaml");
89  // }
90 
91 
93  {
94  return mult("test_Mult_WilsonGeneral.yaml");
95  }
96 
97 
99  {
100  return mult("test_Mult_Wilson_Isochemical.yaml");
101  }
102 
103 
104  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
105  // int mult_Wilson_SF()
106  // {
107  // return mult("test_Mult_Wilson_SF.yaml");
108  // }
109 
110 
111 #ifdef USE_TESTMANAGER_AUTOREGISTER
112  namespace {
113 #if defined(USE_GROUP_SU2)
114  // Nc=2 is not available.
115 #else
116  static const bool is_registered_Clover = TestManager::RegisterTest(
117  "Mult.Clover",
119  );
120 
121  static const bool is_registered_CloverGeneral = TestManager::RegisterTest(
122  "Mult.CloverGeneral",
124  );
125 
126  static const bool is_registered_Clover_Isochemical = TestManager::RegisterTest(
127  "Mult.Clover_Isochemical",
129  );
130 
131  //- NB. Fopr_Clover_SF is implemented only in Chiral rep.
132  // static const bool is_registered_Clover_SF = TestManager::RegisterTest(
133  // "Mult.Clover_SF",
134  // mult_Clover_SF
135  // );
136 
137  // static const bool is_registered_TMWilson = TestManager::RegisterTest(
138  // "Mult.TMWilson",
139  // mult_TMWilson
140  // );
141 
142  //- NB. test_Mult_Wilson is implemented separately for beginners
143  // static const bool is_registered_Wilson = TestManager::RegisterTest(
144  // "Mult.Wilson",
145  // mult_Wilson
146  // );
147 
148  static const bool is_registered_WilsonGeneral = TestManager::RegisterTest(
149  "Mult.WilsonGeneral",
151  );
152 
153  static const bool is_registered_Wilson_Isochemical = TestManager::RegisterTest(
154  "Mult.Wilson_Isochemical",
156  );
157 
158  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
159  // static const bool is_registered_Wilson_SF = TestManager::RegisterTest(
160  // "Mult.Wilson_SF",
161  // mult_Wilson_SF
162  // );
163 #endif
164  }
165 #endif
166 
167  //====================================================================
168  int mult(const std::string& filename_input)
169  {
170  // #### parameter setup ####
171  const int Nc = CommonParameters::Nc();
172  const int Nd = CommonParameters::Nd();
173  const int Ndim = CommonParameters::Ndim();
174  const int Nvol = CommonParameters::Nvol();
175 
176  const int NPE = CommonParameters::NPE();
178 
179  const Parameters params_all = ParameterManager::read(filename_input);
180 
181  const Parameters params_test = params_all.lookup("Test_Mult");
182  const Parameters params_fopr = params_all.lookup("Fopr");
183 
184  const string str_gconf_status = params_test.get_string("gauge_config_status");
185  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
186  const string readfile = params_test.get_string("config_filename_input");
187  const string str_rand_type = params_test.get_string("random_number_type");
188  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
189  const int Nmult = params_test.get_int("number_of_mult");
190  const string str_vlevel = params_test.get_string("verbose_level");
191 
192  const bool do_check = params_test.is_set("expected_result");
193  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
194  const double tolerance = params_test.get_double("tolerance");
195 
196  const string str_fopr_type = params_fopr.get_string("fermion_type");
197  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
198 
199  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
200 
201  //- print input parameters
202  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
203  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
204  vout.general(vl, " readfile = %s\n", readfile.c_str());
205  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
206  vout.general(vl, " seed = %lu\n", seed);
207  vout.general(vl, " Nmult = %d\n", Nmult);
208  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
209  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
210 
211  //- input parameter check
212  int err = 0;
213  err += ParameterCheck::non_NULL(str_gconf_status);
214 
215  if (err) {
216  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
217  exit(EXIT_FAILURE);
218  }
219 
220 
221  RandomNumberManager::initialize(str_rand_type, seed);
222 
223 
224  // #### Set up a gauge configuration ####
225  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
226 
227  if (str_gconf_status == "Continue") {
228  GaugeConfig(str_gconf_read).read(U, readfile);
229  } else if (str_gconf_status == "Cold_start") {
230  GaugeConfig("Unit").read(U);
231  } else if (str_gconf_status == "Hot_start") {
232  GaugeConfig("Random").read(U);
233  } else {
234  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
235  exit(EXIT_FAILURE);
236  }
237 
238 
239  // #### object setup #####
240  const unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
241 
242  const unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
243  fopr->set_parameters(params_fopr);
244  fopr->set_config(U);
245  fopr->set_mode("D");
246 
247  const unique_ptr<Timer> timer(new Timer(test_name));
248 
249  vout.general(vl, "\n");
250 
251 
252  // #### Execution main part ####
253  Field_F b, y;
254  b.set(1.0);
255 
256  double result = 0.0;
257 
258 
259  timer->start();
260 #ifdef FUJITSU_FX
261  //- profiler starts
262  // fapp_start("Mult",1,1);
263 #endif
264 
265 #pragma omp parallel
266  {
267  for (int i = 0; i < Nmult; ++i) {
268  fopr->mult(y, b);
269  }
270  result = y.norm();
271  }
272 
273 #ifdef FUJITSU_FX
274  //- profiler ends
275  // fapp_stop("Mult",1,1);
276 #endif
277  timer->stop();
278  const double elapse_sec = timer->elapsed_sec();
279 
280 
281  //- Flops counting in giga unit
282  const double gflops_mult = fopr->flop_count() * Nmult / (elapse_sec * NPE * Nthread);
283 
284  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
285  vout.general(vl, "\n");
286 
287 
289 
290 
291  if (do_check) {
292  return Test::verify(result, expected_result, tolerance);
293  } else {
294  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
295  return EXIT_SKIP;
296  }
297  }
298 } // namespace Test_Mult
#define EXIT_SKIP
Definition: test.h:17
BridgeIO vout
Definition: bridgeIO.cpp:503
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
void set(const int jin, const int site, const int jex, double v)
Definition: field.h:175
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
virtual void set_config(Field *)=0
setting pointer to the gauge configuration.
int mult_Wilson_Isochemical()
Definition: test_Mult.cpp:98
int get_int(const string &key) const
Definition: parameters.cpp:192
Class for parameters.
Definition: parameters.h:46
Wilson-type fermion field.
Definition: field_F.h:37
const std::string test_name
Definition: test_Mult.cpp:43
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
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 double flop_count()
returns the flop in giga unit
Definition: fopr.h:120
double norm() const
Definition: field.h:222
int mult_CloverGeneral()
Definition: test_Mult.cpp:60
virtual void set_parameters(const Parameters &)=0
int mult_WilsonGeneral()
Definition: test_Mult.cpp:92
static int get_num_threads_available()
returns number of threads (works outside of parallel region).
int mult_Clover_Isochemical()
Definition: test_Mult.cpp:66
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 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:78
Definition: timer.h:31
string get_string(const string &key) const
Definition: parameters.cpp:221
void stop()
Definition: timer.cpp:69
int mult_Clover()
Definition: test_Mult.cpp:54
int mult(const std::string &)
Definition: test_Mult.cpp:168
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131