Bridge++  Ver. 2.0.2
asolver_CGNR-tmpl.h
Go to the documentation of this file.
1 
11 using Bridge::vout;
12 
13 #ifdef USE_FACTORY_AUTOREGISTER
14 namespace {
15  bool init = ASolver_CGNR::register_factory();
16 }
17 #endif
18 
19 template<typename AFIELD>
20 const std::string ASolver_CGNR<AFIELD>::class_name = "ASolver_CGNR";
21 
22 //====================================================================
23 template<typename AFIELD>
25 {
26  int nin = m_fopr->field_nin();
27  int nvol = m_fopr->field_nvol();
28  int nex = m_fopr->field_nex();
29 
30  m_b2.reset(nin, nvol, nex);
31 }
32 
33 
34 //====================================================================
35 template<typename AFIELD>
37 {
38  std::string str_vlevel = params.get_string("verbose_level");
39  m_vl = vout.set_verbose_level(str_vlevel);
40 
41  vout.general(m_vl, "%s:\n", class_name.c_str());
42 
44 }
45 
46 
47 //====================================================================
48 template<typename AFIELD>
50  int& Nconv, real_t& diff)
51 {
52  int ith = ThreadManager::get_thread_id();
53 
54  const std::string mode_prev = m_fopr->get_mode();
55 
56  vout.detailed(m_vl, "%s: solver starts\n", class_name.c_str());
57 
58  if ((mode_prev == "DdagD") || (mode_prev == "DdagD_prec")) {
59  vout.detailed(m_vl, "%s: calling CG, mode=%s\n",
60  class_name.c_str(), mode_prev.c_str());
61  this->ASolver_CG<AFIELD>::solve(xq, b, Nconv, diff);
62  if (ith == 0) {
63  m_mode_fopr = mode_prev;
64  m_flop = this->ASolver_CG<AFIELD>::flop_count();
65  }
66 
67  return;
68  }
69 
70 #pragma omp barrier
71 
72  if ((mode_prev == "D") || (mode_prev == "Ddag") ||
73  (mode_prev == "D_prec") || (mode_prev == "Ddag_prec")) {
74  vout.detailed(m_vl, " mode_prev = %s\n", mode_prev.c_str());
75  } else {
76  vout.crucial(m_vl, "Error at %s: unsupported mode for fopr %s.",
77  class_name.c_str(), mode_prev.c_str());
78  exit(EXIT_FAILURE);
79  }
80 
81 #pragma omp barrier
82 
83  if (ith == 0) {
84  if ((m_b2.nin() != b.nin()) || (m_b2.nvol() != b.nvol()) ||
85  (m_b2.nex() != b.nex())) {
86  vout.detailed(m_vl, " b2 size is reset.\n");
87  m_b2.reset(b.nin(), b.nvol(), b.nex());
88  }
89  }
90 
91 #pragma omp barrier
92 
93  m_fopr->mult_dag(m_b2, b);
94 
95  if (ith == 0) {
96  m_flop = m_fopr->flop_count();
97  }
98 
99 #pragma omp barrier
100 
101  if (ith == 0) {
102  if (mode_prev == "D") {
103  m_mode_fopr = "DdagD";
104  } else if (mode_prev == "Ddag") {
105  m_mode_fopr = "DDdag";
106  } else if (mode_prev == "D_prec") {
107  m_mode_fopr = "DdagD_prec";
108  } else if (mode_prev == "Ddag_prec") {
109  m_mode_fopr = "DDdag_prec";
110  } else {
111  vout.crucial(m_vl, "%s: unknown mode for fopr: %s\n",
112  class_name.c_str(), mode_prev.c_str());
113  }
114  }
115 
116  m_fopr->set_mode(m_mode_fopr);
117 
118  this->ASolver_CG<AFIELD>::solve(xq, m_b2, Nconv, diff);
119  if (ith == 0) {
120  m_flop += this->ASolver_CG<AFIELD>::flop_count();
121  }
122 
123  m_fopr->set_mode(mode_prev);
124 
125  // #pragma omp barrier // set_mode has a barrier
126 }
127 
128 
129 //====================================================================
130 template<typename AFIELD>
132 {
133  double flop_fopr = m_fopr->flop_count();
134  if (flop_fopr < CommonParameters::epsilon_criterion()) {
135  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is"
136  "available, setting flop = 0\n", class_name.c_str());
137  return 0.0;
138  }
139 
140  return m_flop;
141 
142  /*
143  int NPE = CommonParameters::NPE();
144 
145  std::string mode_keep = this->ASolver_CG<AFIELD>::get_fopr()->get_mode();
146  this->ASolver_CG<AFIELD>::get_fopr()->set_mode(m_mode_fopr);
147 
148  double gflop_fopr = this->ASolver_CG<AFIELD>::get_fopr()->flop_count();
149  if (gflop_fopr < CommonParameters::epsilon_criterion()) {
150  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is"
151  "available, setting flop = 0\n", class_name.c_str());
152  return 0.0;
153  }
154 
155  double gflop_solver = this->ASolver_CG<AFIELD>::flop_count();
156  this->ASolver_CG<AFIELD>::get_fopr()->set_mode(mode_keep);
157 
158  double gflop = gflop_solver + gflop_fopr;
159 
160  return gflop;
161  */
162 }
163 
164 
165 //====================================================================
166 //============================================================END=====
ASolver_CGNR::solve
void solve(AFIELD &solution, const AFIELD &source, int &Nconv, real_t &diff)
solver main.
Definition: asolver_CGNR-tmpl.h:49
Parameters
Class for parameters.
Definition: parameters.h:46
ASolver_CG::set_parameters
void set_parameters(const Parameters &params)
setting parameters by a Parameter object.
Definition: asolver_CG-tmpl.h:35
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
ASolver_CG::solve
void solve(AFIELD &xq, const AFIELD &b, int &nconv, real_t &diff)
solver main.
Definition: asolver_CG-tmpl.h:110
Field::nex
int nex() const
Definition: field.h:128
ASolver_CGNR::init
void init()
Definition: asolver_CGNR-tmpl.h:24
Field::nin
int nin() const
Definition: field.h:126
ASolver_CGNR
CGNR solver.
Definition: asolver_CGNR.h:31
ASolver_CGNR::flop_count
double flop_count()
returns the floating point operation count.
Definition: asolver_CGNR-tmpl.h:131
ASolver_CGNR::set_parameters
void set_parameters(const Parameters &params)
setting parameters by a Parameter object.
Definition: asolver_CGNR-tmpl.h:36
Field::nvol
int nvol() const
Definition: field.h:127
ASolver_CG::flop_count
double flop_count()
returns the floating point operation count.
Definition: asolver_CG-tmpl.h:229
Bridge::BridgeIO::set_verbose_level
static VerboseLevel set_verbose_level(const std::string &str)
Definition: bridgeIO.cpp:133
asolver_CGNR.h
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
Field
Container of Field-type object.
Definition: field.h:46
ThreadManager::get_thread_id
static int get_thread_id()
returns thread id.
Definition: threadManager.cpp:253
Bridge::BridgeIO::general
void general(const char *format,...)
Definition: bridgeIO.cpp:200
ASolver::real_t
AFIELD::real_t real_t
Definition: asolver.h:29
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
CommonParameters::epsilon_criterion
static double epsilon_criterion()
Definition: commonParameters.h:119