Bridge++  Version 1.6.1
 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  //- NB. test_Mult_Wilson is implemented separately for beginners
80  // int mult_Wilson()
81  // {
82  // return mult("test_Mult_Wilson.yaml");
83  // }
84 
85 
87  {
88  return mult("test_Mult_WilsonGeneral.yaml");
89  }
90 
91 
93  {
94  return mult("test_Mult_Wilson_Isochemical.yaml");
95  }
96 
97 
98  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
99  // int mult_Wilson_SF()
100  // {
101  // return mult("test_Mult_Wilson_SF.yaml");
102  // }
103 
104 
105 #ifdef USE_TESTMANAGER_AUTOREGISTER
106  namespace {
107 #if defined(USE_GROUP_SU2)
108  // Nc=2 is not available.
109 #else
110  static const bool is_registered_Clover = TestManager::RegisterTest(
111  "Mult.Clover",
113  );
114 
115  static const bool is_registered_CloverGeneral = TestManager::RegisterTest(
116  "Mult.CloverGeneral",
118  );
119 
120  static const bool is_registered_Clover_Isochemical = TestManager::RegisterTest(
121  "Mult.Clover_Isochemical",
123  );
124 
125  //- NB. Fopr_Clover_SF is implemented only in Chiral rep.
126  // static const bool is_registered_Clover_SF = TestManager::RegisterTest(
127  // "Mult.Clover_SF",
128  // mult_Clover_SF
129  // );
130 
131  //- NB. test_Mult_Wilson is implemented separately for beginners
132  // static const bool is_registered_Wilson = TestManager::RegisterTest(
133  // "Mult.Wilson",
134  // mult_Wilson
135  // );
136 
137  static const bool is_registered_WilsonGeneral = TestManager::RegisterTest(
138  "Mult.WilsonGeneral",
140  );
141 
142  static const bool is_registered_Wilson_Isochemical = TestManager::RegisterTest(
143  "Mult.Wilson_Isochemical",
145  );
146 
147  //- NB. Fopr_Wilson_SF is implemented only in Chiral rep.
148  // static const bool is_registered_Wilson_SF = TestManager::RegisterTest(
149  // "Mult.Wilson_SF",
150  // mult_Wilson_SF
151  // );
152 #endif
153  }
154 #endif
155 
156  //====================================================================
157  int mult(const std::string& filename_input)
158  {
159  // #### parameter setup ####
160  const int Nc = CommonParameters::Nc();
161  const int Nd = CommonParameters::Nd();
162  const int Ndim = CommonParameters::Ndim();
163  const int Nvol = CommonParameters::Nvol();
164 
165  const int NPE = CommonParameters::NPE();
167 
168  const Parameters params_all = ParameterManager::read(filename_input);
169 
170  const Parameters params_test = params_all.lookup("Test_Mult");
171  const Parameters params_fopr = params_all.lookup("Fopr");
172 
173  const string str_gconf_status = params_test.get_string("gauge_config_status");
174  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
175  const string readfile = params_test.get_string("config_filename_input");
176  const string str_rand_type = params_test.get_string("random_number_type");
177  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
178  const int Nmult = params_test.get_int("number_of_mult");
179  const string str_vlevel = params_test.get_string("verbose_level");
180 
181  const bool do_check = params_test.is_set("expected_result");
182  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
183  const double tolerance = params_test.get_double("tolerance");
184 
185  const string str_fopr_type = params_fopr.get_string("fermion_type");
186  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
187 
188  const Bridge::VerboseLevel vl = vout.set_verbose_level(str_vlevel);
189 
190  //- print input parameters
191  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
192  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
193  vout.general(vl, " readfile = %s\n", readfile.c_str());
194  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
195  vout.general(vl, " seed = %lu\n", seed);
196  vout.general(vl, " Nmult = %d\n", Nmult);
197  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
198  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
199 
200  //- input parameter check
201  int err = 0;
202  err += ParameterCheck::non_NULL(str_gconf_status);
203 
204  if (err) {
205  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
206  exit(EXIT_FAILURE);
207  }
208 
209 
210  RandomNumberManager::initialize(str_rand_type, seed);
211 
212 
213  // #### Set up a gauge configuration ####
214  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
215 
216  if (str_gconf_status == "Continue") {
217  GaugeConfig(str_gconf_read).read(U, readfile);
218  } else if (str_gconf_status == "Cold_start") {
219  GaugeConfig("Unit").read(U);
220  } else if (str_gconf_status == "Hot_start") {
221  GaugeConfig("Random").read(U);
222  } else {
223  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
224  exit(EXIT_FAILURE);
225  }
226 
227 
228  // #### object setup #####
229  const unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
230 
231  const unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
232  fopr->set_parameters(params_fopr);
233  fopr->set_config(U);
234  fopr->set_mode("D");
235 
236  const unique_ptr<Timer> timer(new Timer(test_name));
237 
238  vout.general(vl, "\n");
239 
240 
241  // #### Execution main part ####
242  Field_F b, y;
243  b.set(1.0);
244 
245  double result = 0.0;
246 
247 
248  timer->start();
249 #ifdef FUJITSU_FX
250  //- profiler starts
251  // fapp_start("Mult",1,1);
252 #endif
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 #ifdef FUJITSU_FX
263  //- profiler ends
264  // fapp_stop("Mult",1,1);
265 #endif
266  timer->stop();
267  const double elapse_sec = timer->elapsed_sec();
268 
269 
270  //- Flops counting in giga unit
271  const double gflops_mult = fopr->flop_count() * Nmult / (elapse_sec * NPE * Nthread);
272 
273  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
274  vout.general(vl, "\n");
275 
276 
278 
279 
280  if (do_check) {
281  return Test::verify(result, expected_result, tolerance);
282  } else {
283  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
284  return EXIT_SKIP;
285  }
286  }
287 } // 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:176
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:92
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:227
int mult_CloverGeneral()
Definition: test_Mult.cpp:60
virtual void set_parameters(const Parameters &)=0
int mult_WilsonGeneral()
Definition: test_Mult.cpp:86
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:79
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:157
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131