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