Bridge++  Ver. 1.3.x
test_Mult_eo.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_eo.h"
20 #include "gammaMatrixSet.h"
21 
22 //- profiler of fx10
23 //#include "fj_tool/fapp.h"
24 
25 //====================================================================
27 
34 namespace Test_Mult_eo {
35  const std::string test_name = "Mult";
36 
37  //- test-private parameters
38  namespace {
39  // const std::string filename_input = "test_Mult_eo.yaml";
40  const std::string filename_output = "stdout";
41 
42  class Parameters_Test_Mult_eo : public Parameters {
43  public:
44  Parameters_Test_Mult_eo()
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_eo.yaml");
66  }
67 
68 
70  {
71  return mult("test_Mult_Wilson_eo.yaml");
72  }
73 
74 
75 #ifdef USE_TESTMANAGER_AUTOREGISTER
76  namespace {
77 #if defined(USE_GROUP_SU2)
78  // Nc=2 is not available.
79 #else
80  static const bool is_registered_Clover_eo = TestManager::RegisterTest(
81  "Mult.Clover_eo",
83  );
84 
85  static const bool is_registered_Wilson_eo = TestManager::RegisterTest(
86  "Mult.Wilson_eo",
88  );
89 #endif
90  }
91 #endif
92 
93  //====================================================================
94  int mult(const std::string& filename_input)
95  {
96  // #### parameter setup ####
97  int Nc = CommonParameters::Nc();
98  int Nd = CommonParameters::Nd();
99  int Ndim = CommonParameters::Ndim();
100  int Nvol = CommonParameters::Nvol();
101 
102  int Lvol = CommonParameters::Lvol();
103  int NPE = CommonParameters::NPE();
105 
106  unique_ptr<Parameters> params_test(new Parameters_Test_Mult_eo);
107  unique_ptr<Parameters> params_fopr(ParametersFactory::New("Fopr"));
108  unique_ptr<Parameters> params_all(new Parameters);
109 
110  params_all->Register_Parameters("Test_Mult", params_test);
111  params_all->Register_Parameters("Fopr", params_fopr);
112 
113  ParameterManager::read(filename_input, params_all);
114 
115  const string str_gconf_status = params_test->get_string("gauge_config_status");
116  const string str_gconf_read = params_test->get_string("gauge_config_type_input");
117  const string readfile = params_test->get_string("config_filename_input");
118  const int Nmult = params_test->get_int("number_of_mult");
119  const string str_vlevel = params_test->get_string("verbose_level");
120 
121  const bool do_check = params_test->is_set("expected_result");
122  const double expected_result = do_check ? params_test->get_double("expected_result") : 0.0;
123 
124  const string str_fopr_type = params_fopr->get_string("fermion_type");
125  const string str_gmset_type = params_fopr->get_string("gamma_matrix_type");
126 
128 
129  //- print input parameters
130  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
131  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
132  vout.general(vl, " readfile = %s\n", readfile.c_str());
133  vout.general(vl, " Nmult = %d\n", Nmult);
134  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
135  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
136 
137  //- input parameter check
138  int err = 0;
139  err += ParameterCheck::non_NULL(str_gconf_status);
140 
141  if (err) {
142  vout.crucial(vl, "%s: Input parameters have not been set.\n", test_name.c_str());
143  exit(EXIT_FAILURE);
144  }
145 
146 
147  // #### Set up a gauge configuration ####
148  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
149  unique_ptr<GaugeConfig> gconf_read(new GaugeConfig(str_gconf_read));
150 
151  if (str_gconf_status == "Continue") {
152  gconf_read->read_file(U, readfile);
153  } else if (str_gconf_status == "Cold_start") {
154  U->set_unit();
155  } else if (str_gconf_status == "Hot_start") {
156  int i_seed_noise = 1234567;
157  unique_ptr<RandomNumbers> rand(new RandomNumbers_Mseries(i_seed_noise));
158  U->set_random(rand);
159  } else {
160  vout.crucial(vl, "%s: unsupported gconf status \"%s\".\n", test_name.c_str(), str_gconf_status.c_str());
161  exit(EXIT_FAILURE);
162  }
163 
164 
165  // #### object setup #####
166  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
167 
168  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
169  fopr->set_parameters(*params_fopr);
170  fopr->set_config(U);
171  fopr->set_mode("D");
172 
173  unique_ptr<Timer> timer(new Timer(test_name));
174 
175  vout.general(vl, "\n");
176 
177 
178  // #### Execution main part ####
179  Field_F b;
180  int Nin = b.nin();
181  // int Nvol = b.nvol();
182  int Nex = b.nex();
183 
184  Field be(Nin, Nvol / 2, Nex);
185  Field ye(Nin, Nvol / 2, Nex);
186  //be = 1.0;
187  be.set(1.0);
188 
189  double result = 0.0;
190 
191  timer->start();
192  //- profiler of fx10 starts
193  // fapp_start("Mult_eo",1,1);
194 
195 #pragma omp parallel
196  {
197  for (int i = 0; i < Nmult; ++i) {
198  fopr->mult(ye, be);
199  }
200  result = ye.norm();
201  }
202 
203 #ifdef DEBUG
204  //- additional verify for Nthread > 1
205  if (Nthread > 1) {
206  double epsilon = CommonParameters::epsilon_criterion();
207 
208  fopr->mult(ye, be);
209  double result_single = ye.norm();
210 
211  if (Test::verify(abs(result - result_single), 0.0, epsilon)) {
212  vout.crucial("%s: result(multithread) not equal to result(single thread)\n", test_name.c_str());
213  vout.crucial("%s: result(multithread) = %22.14e\n", test_name.c_str(), result);
214  vout.crucial("%s: result(single thread) = %22.14e\n", test_name.c_str(), result_single);
215  return EXIT_FAILURE;
216  }
217  }
218 #endif
219 
220  //- profiler of fx10 ends
221  // fapp_stop("Mult_eo",1,1);
222  timer->stop();
223  double elapse_sec = timer->elapsed_sec();
224 
225 
226  //- Flops counting
227  double gflo_mult = fopr->flop_count() / 1.0e+9;
228  double gflops_mult = gflo_mult * Nmult / (elapse_sec * NPE * Nthread);
229 
230  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
231  vout.general(vl, "\n");
232 
233 
234  if (do_check) {
235  return Test::verify(result, expected_result);
236  } else {
237  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
238  return EXIT_SKIP;
239  }
240  }
241 } // namespace Test_Mult_eo
#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
int mult(const std::string &)
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.
Container of Field-type object.
Definition: field.h:39
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
void set_random(RandomNumbers *rand)
Definition: field_G_imp.cpp:62
Wilson-type fermion field.
Definition: field_F.h:37
void set_unit()
Definition: field_G_imp.cpp:39
int nin() const
Definition: field.h:115
static bool RegisterTest(const std::string &key, const Test_function func)
Definition: testManager.h:80
Test of Mult with even-odd preconditioning.
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
int mult_Clover_eo()
virtual double flop_count()
returns the flops per site.
Definition: fopr.h:110
double norm() const
Definition: field.h:240
int nex() const
Definition: field.h:117
const std::string test_name
virtual void set_parameters(const Parameters &)=0
static int get_num_threads_available()
returns number of threads (works outside of parallel region).
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)
int mult_Wilson_eo()
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
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:28
static int NPE()