Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
solver_CGNR.cpp
Go to the documentation of this file.
1 
14 #include "solver_CGNR.h"
15 using Bridge::vout;
16 
17 #ifdef USE_FACTORY_AUTOREGISTER
18 namespace {
19  bool init = Solver_CGNR::register_factory();
20 }
21 #endif
22 
23 const std::string Solver_CGNR::class_name = "Solver_CGNR";
24 
25 //====================================================================
27 {
28  return this->Solver_CG::set_parameters(params);
29 }
30 
31 
32 //====================================================================
33 void Solver_CGNR::solve(Field& xq, const Field& b, int& Nconv, double& diff)
34 {
35  Fopr *fopr = this->Solver_CG::get_fopr();
36  const std::string mode_prev = fopr->get_mode();
37 
38  vout.detailed(m_vl, "%s: solver starts\n", class_name.c_str());
39 
40  if (mode_prev == "DdagD") {
41  this->Solver_CG::solve(xq, b, Nconv, diff); // fallback to CG solver
42  return;
43  }
44 
45  if (!((mode_prev == "D") || (mode_prev == "Ddag"))) {
46  vout.crucial(m_vl, "Error at %s: unsupported mode for fopr %s.", class_name.c_str(), mode_prev.c_str());
47  exit(EXIT_FAILURE);
48  }
49 
50 #pragma omp barrier
51 #pragma omp master
52  {
53  if ((m_b2.nin() != b.nin()) || (m_b2.nvol() != b.nvol()) ||
54  (m_b2.nex() != b.nex())) {
55  m_b2.reset(b.nin(), b.nvol(), b.nex());
56  }
57  }
58 #pragma omp barrier
59 
60  fopr->mult_dag(m_b2, b); // b2 = fopr->mult_dag(b);
61 
62 #pragma omp barrier
63 #pragma omp master
64  {
65  if (mode_prev == "D") {
66  fopr->set_mode("DdagD");
67  } else if (mode_prev == "Ddag") {
68  fopr->set_mode("DDdag");
69  }
70  }
71 #pragma omp barrier
72 
73  this->Solver_CG::solve(xq, m_b2, Nconv, diff);
74 
75 #pragma omp barrier
76 #pragma omp master
77  {
78  fopr->set_mode(mode_prev);
79  }
80 #pragma omp barrier
81 }
82 
83 
84 //====================================================================
86 {
87  const int NPE = CommonParameters::NPE();
88 
89  const double gflop_fopr = this->Solver_CG::get_fopr()->flop_count();
90 
91  if (gflop_fopr < CommonParameters::epsilon_criterion()) {
92  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is available, setting flop = 0\n", class_name.c_str());
93  return 0.0;
94  }
95 
96  const double gflop_solver = this->Solver_CG::flop_count();
97 
98  const double gflop = gflop_solver + gflop_fopr;
99 
100  return gflop;
101 }
102 
103 
104 //====================================================================
105 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
Fopr * get_fopr()
Definition: solver_CG.h:83
void detailed(const char *format,...)
Definition: bridgeIO.cpp:216
static double epsilon_criterion()
virtual void set_mode(const std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: fopr.h:94
Field m_b2
Definition: solver_CGNR.h:38
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CG.cpp:112
Container of Field-type object.
Definition: field.h:45
int nvol() const
Definition: field.h:127
void set_parameters(const Parameters &params)
Definition: solver_CGNR.cpp:26
Class for parameters.
Definition: parameters.h:46
int nin() const
Definition: field.h:126
void set_parameters(const Parameters &params)
Definition: solver_CG.cpp:25
static const std::string class_name
Definition: solver_CGNR.h:41
virtual double flop_count()
returns the flop in giga unit
Definition: fopr.h:120
virtual std::string get_mode() const
only for Fopr_Overlap
Definition: fopr.h:104
int nex() const
Definition: field.h:128
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CGNR.cpp:33
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=Element_type::COMPLEX)
Definition: field.h:95
void crucial(const char *format,...)
Definition: bridgeIO.cpp:178
double flop_count()
Definition: solver_CGNR.cpp:85
virtual void mult_dag(Field &, const Field &)
hermitian conjugate of mult(Field&, const Field&).
Definition: fopr.h:73
Base class of fermion operator family.
Definition: fopr.h:46
double flop_count()
Definition: solver_CG.cpp:258
Bridge::VerboseLevel m_vl
Definition: solver.h:63