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