Bridge++  Version 1.5.4
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
solver_CGNE.cpp
Go to the documentation of this file.
1 
14 #include "solver_CGNE.h"
15 using Bridge::vout;
16 
17 #ifdef USE_FACTORY_AUTOREGISTER
18 namespace {
19  bool init = Solver_CGNE::register_factory();
20 }
21 #endif
22 
23 const std::string Solver_CGNE::class_name = "Solver_CGNE";
24 
25 //====================================================================
27 {
28  return this->Solver_CG::set_parameters(params);
29 }
30 
31 
32 //====================================================================
33 void Solver_CGNE::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.",
47  class_name.c_str(), mode_prev.c_str());
48  exit(EXIT_FAILURE);
49  }
50 
51 #pragma omp barrier
52 #pragma omp master
53  {
54  if ((m_y.nin() != b.nin()) || (m_y.nvol() != b.nvol()) ||
55  (m_y.nex() != b.nex())) {
56  m_y.reset(b.nin(), b.nvol(), b.nex());
57  }
58 
59  if (mode_prev == "D") {
60  fopr->set_mode("DDdag");
61  } else if (mode_prev == "Ddag") {
62  fopr->set_mode("DdagD");
63  }
64  }
65 #pragma omp barrier
66 
67  this->Solver_CG::solve(m_y, b, Nconv, diff);
68 
69 #pragma omp barrier
70 #pragma omp master
71  {
72  fopr->set_mode(mode_prev);
73  }
74 #pragma omp barrier
75 
76  fopr->mult_dag(xq, m_y); // xq = fopr->mult_dag(y);
77 
78 #pragma omp barrier
79 }
80 
81 
82 //====================================================================
84 {
85  const int NPE = CommonParameters::NPE();
86 
87  const double gflop_fopr = this->Solver_CG::get_fopr()->flop_count();
88 
89  if (gflop_fopr < CommonParameters::epsilon_criterion()) {
90  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is available, setting flop = 0\n", class_name.c_str());
91  return 0.0;
92  }
93 
94  const double gflop_solver = this->Solver_CG::flop_count();
95 
96  const double gflop = gflop_solver + gflop_fopr;
97 
98  return gflop;
99 }
100 
101 
102 //====================================================================
103 //============================================================END=====
BridgeIO vout
Definition: bridgeIO.cpp:503
Fopr * get_fopr()
Definition: solver_CG.h:83
static const std::string class_name
Definition: solver_CGNE.h:41
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
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
Class for parameters.
Definition: parameters.h:46
int nin() const
Definition: field.h:126
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CGNE.cpp:33
void set_parameters(const Parameters &params)
Definition: solver_CGNE.cpp:26
void set_parameters(const Parameters &params)
Definition: solver_CG.cpp:25
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
double flop_count()
Definition: solver_CGNE.cpp:83
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
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