Bridge++  Version 1.4.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
test_Mult_eo.cpp
Go to the documentation of this file.
1 
14 #include "Tests/test.h"
15 
16 #include "Fopr/fopr_eo.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_eo {
36  const std::string test_name = "Mult";
37 
38  //- test-private parameters
39  namespace {
40  // const std::string filename_input = "test_Mult_eo.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_eo.yaml");
50  }
51 
52 
54  {
55  return mult("test_Mult_Wilson_eo.yaml");
56  }
57 
58 
59 #ifdef USE_TESTMANAGER_AUTOREGISTER
60  namespace {
61 #if defined(USE_GROUP_SU2)
62  // Nc=2 is not available.
63 #else
64  static const bool is_registered_Clover_eo = TestManager::RegisterTest(
65  "Mult.Clover_eo",
67  );
68 
69  static const bool is_registered_Wilson_eo = TestManager::RegisterTest(
70  "Mult.Wilson_eo",
72  );
73 #endif
74  }
75 #endif
76 
77  //====================================================================
78  int mult(const std::string& filename_input)
79  {
80  // #### parameter setup ####
81  int Nc = CommonParameters::Nc();
82  int Nd = CommonParameters::Nd();
83  int Ndim = CommonParameters::Ndim();
84  int Nvol = CommonParameters::Nvol();
85 
86  int Lvol = CommonParameters::Lvol();
87  int NPE = CommonParameters::NPE();
89 
90  Parameters params_all = ParameterManager::read(filename_input);
91 
92  Parameters params_test = params_all.lookup("Test_Mult");
93  Parameters params_fopr = params_all.lookup("Fopr");
94 
95  const string str_gconf_status = params_test.get_string("gauge_config_status");
96  const string str_gconf_read = params_test.get_string("gauge_config_type_input");
97  const string readfile = params_test.get_string("config_filename_input");
98  const string str_rand_type = params_test.get_string("random_number_type");
99  const unsigned long seed = params_test.get_unsigned_long("seed_for_random_number");
100  const int Nmult = params_test.get_int("number_of_mult");
101  const string str_vlevel = params_test.get_string("verbose_level");
102 
103  const bool do_check = params_test.is_set("expected_result");
104  const double expected_result = do_check ? params_test.get_double("expected_result") : 0.0;
105  const double tolerance = params_test.get_double("tolerance");
106 
107  const string str_fopr_type = params_fopr.get_string("fermion_type");
108  const string str_gmset_type = params_fopr.get_string("gamma_matrix_type");
109 
111 
112  //- print input parameters
113  vout.general(vl, " gconf_status = %s\n", str_gconf_status.c_str());
114  vout.general(vl, " gconf_read = %s\n", str_gconf_read.c_str());
115  vout.general(vl, " readfile = %s\n", readfile.c_str());
116  vout.general(vl, " rand_type = %s\n", str_rand_type.c_str());
117  vout.general(vl, " seed = %lu\n", seed);
118  vout.general(vl, " Nmult = %d\n", Nmult);
119  vout.general(vl, " vlevel = %s\n", str_vlevel.c_str());
120  vout.general(vl, " gmset_type = %s\n", str_gmset_type.c_str());
121 
122  //- input parameter check
123  int err = 0;
124  err += ParameterCheck::non_NULL(str_gconf_status);
125 
126  if (err) {
127  vout.crucial(vl, "Error at %s: input parameters have not been set\n", test_name.c_str());
128  exit(EXIT_FAILURE);
129  }
130 
131 
132  RandomNumberManager::initialize(str_rand_type, seed);
133 
134 
135  // #### Set up a gauge configuration ####
136  unique_ptr<Field_G> U(new Field_G(Nvol, Ndim));
137 
138  if (str_gconf_status == "Continue") {
139  GaugeConfig(str_gconf_read).read(U, readfile);
140  } else if (str_gconf_status == "Cold_start") {
141  GaugeConfig("Unit").read(U);
142  } else if (str_gconf_status == "Hot_start") {
143  GaugeConfig("Random").read(U);
144  } else {
145  vout.crucial(vl, "Error at %s: unsupported gconf status \"%s\"\n", test_name.c_str(), str_gconf_status.c_str());
146  exit(EXIT_FAILURE);
147  }
148 
149 
150  // #### object setup #####
151  unique_ptr<GammaMatrixSet> gmset(GammaMatrixSet::New(str_gmset_type));
152 
153  unique_ptr<Fopr> fopr(Fopr::New(str_fopr_type, str_gmset_type));
154  fopr->set_parameters(params_fopr);
155  fopr->set_config(U);
156  fopr->set_mode("D");
157 
158  unique_ptr<Timer> timer(new Timer(test_name));
159 
160  vout.general(vl, "\n");
161 
162 
163  // #### Execution main part ####
164  Field_F b;
165  int Nin = b.nin();
166  // int Nvol = b.nvol();
167  int Nex = b.nex();
168 
169  Field be(Nin, Nvol / 2, Nex);
170  Field ye(Nin, Nvol / 2, Nex);
171  //be = 1.0;
172  be.set(1.0);
173 
174  double result = 0.0;
175 
176  timer->start();
177  //- profiler of fx10 starts
178  // fapp_start("Mult_eo",1,1);
179 
180 #pragma omp parallel
181  {
182  for (int i = 0; i < Nmult; ++i) {
183  fopr->mult(ye, be);
184  }
185  result = ye.norm();
186  }
187 
188  //- profiler of fx10 ends
189  // fapp_stop("Mult_eo",1,1);
190  timer->stop();
191  double elapse_sec = timer->elapsed_sec();
192 
193 
194  //- additional verify for Nthread > 1
195  int thread_test = 0;
196 
197  if (Nthread > 1) {
198  double result_single = 0.0;
199 
200  fopr->mult(ye, be);
201  result_single = ye.norm();
202 
203  if (Test::verify(result, result_single, tolerance)) {
204  vout.crucial("%s: result(multithread) not equal to result(single thread)\n", test_name.c_str());
205  vout.crucial("%s: result(multithread) = %22.14e\n", test_name.c_str(), result);
206  vout.crucial("%s: result(single thread) = %22.14e\n", test_name.c_str(), result_single);
207 
208  thread_test = 1; // test failed.
209  }
210  }
211 
212 
213  //- Flops counting
214  double gflo_mult = fopr->flop_count() / 1.0e+9;
215  double gflops_mult = gflo_mult * Nmult / (elapse_sec * NPE * Nthread);
216 
217  vout.general(vl, "%s: %12.4e GFlops / core\n", test_name.c_str(), gflops_mult);
218  vout.general(vl, "\n");
219 
220 
222 
223 
224  if (do_check) {
225  int verify_test = Test::verify(result, expected_result, tolerance);
226 
227  if ((thread_test == 0) && (verify_test == 0)) {
228  return EXIT_SUCCESS;
229  } else {
230  return EXIT_FAILURE;
231  }
232  } else {
233  vout.detailed(vl, "check skipped: expected_result not set.\n\n");
234  return EXIT_SKIP;
235  }
236  }
237 } // namespace Test_Mult_eo
#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
int mult(const std::string &)
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.
Container of Field-type object.
Definition: field.h:39
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
int nin() const
Definition: field.h:115
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
int mult_Clover_eo()
virtual double flop_count()
returns the flops per site.
Definition: fopr.h:121
double norm() const
Definition: field.h:211
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
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
int mult_Wilson_eo()
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
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:131
static int NPE()