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