Bridge++  Ver. 2.0.2
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 //====================================================================
34 {
35  return this->Solver_CG::get_parameters(params);
36 }
37 
38 
39 //====================================================================
40 void Solver_CGNR::solve(Field& xq, const Field& b, int& Nconv, double& diff)
41 {
42  Fopr *fopr = this->Solver_CG::get_fopr();
43  const std::string mode_prev = fopr->get_mode();
44 
45  vout.detailed(m_vl, "%s: solver starts\n", class_name.c_str());
46 
47  if (mode_prev == "DdagD") {
48  this->Solver_CG::solve(xq, b, Nconv, diff); // fallback to CG solver
49  return;
50  }
51 
52  if (!((mode_prev == "D") || (mode_prev == "Ddag"))) {
53  vout.crucial(m_vl, "Error at %s: unsupported mode for fopr %s.", class_name.c_str(), mode_prev.c_str());
54  exit(EXIT_FAILURE);
55  }
56 
57 #pragma omp barrier
58 #pragma omp master
59  {
60  if ((m_b2.nin() != b.nin()) || (m_b2.nvol() != b.nvol()) ||
61  (m_b2.nex() != b.nex())) {
62  m_b2.reset(b.nin(), b.nvol(), b.nex());
63  }
64  }
65 #pragma omp barrier
66 
67  fopr->mult_dag(m_b2, b); // b2 = fopr->mult_dag(b);
68 
69 #pragma omp barrier
70 //#pragma omp master
71  {
72  if (mode_prev == "D") {
73  fopr->set_mode("DdagD");
74  } else if (mode_prev == "Ddag") {
75  fopr->set_mode("DDdag");
76  }
77  }
78 #pragma omp barrier
79 
80  this->Solver_CG::solve(xq, m_b2, Nconv, diff);
81 
82 #pragma omp barrier
83 //#pragma omp master
84  {
85  fopr->set_mode(mode_prev);
86  }
87 #pragma omp barrier
88 }
89 
90 
91 //====================================================================
93 {
94  const int NPE = CommonParameters::NPE();
95 
96  const double gflop_fopr = this->Solver_CG::get_fopr()->flop_count();
97 
98  if (gflop_fopr < CommonParameters::epsilon_criterion()) {
99  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is available, setting flop = 0\n", class_name.c_str());
100  return 0.0;
101  }
102 
103  const double gflop_solver = this->Solver_CG::flop_count();
104 
105  const double gflop = gflop_solver + gflop_fopr;
106 
107  return gflop;
108 }
109 
110 
111 //====================================================================
112 //============================================================END=====
Solver_CGNR::flop_count
double flop_count()
Definition: solver_CGNR.cpp:92
AFopr< Field >
Solver_CG::m_vl
Bridge::VerboseLevel m_vl
Definition: solver_CG.h:44
Parameters
Class for parameters.
Definition: parameters.h:46
Solver_CGNR::solve
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CGNR.cpp:40
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
Field::nex
int nex() const
Definition: field.h:128
Solver_CGNR::class_name
static const std::string class_name
Definition: solver_CGNR.h:41
Solver_CG::get_parameters
void get_parameters(Parameters &params) const
Definition: solver_CG.cpp:53
Solver_CG::solve
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CG.cpp:125
AFopr::set_mode
virtual void set_mode(std::string mode)
setting the mode of multiplication if necessary. Default implementation here is just to avoid irrelev...
Definition: afopr.h:81
Field::nin
int nin() const
Definition: field.h:126
AFopr::get_mode
virtual std::string get_mode() const
returns the current mult mode.
Definition: afopr.h:88
AFopr::mult_dag
virtual void mult_dag(AFIELD &, const AFIELD &)
hermitian conjugate of mult.
Definition: afopr.h:102
AFopr::flop_count
virtual double flop_count()
returns the number of floating point operations.
Definition: afopr.h:160
Solver_CGNR::get_parameters
void get_parameters(Parameters &params) const
Definition: solver_CGNR.cpp:33
Field::nvol
int nvol() const
Definition: field.h:127
CommonParameters::NPE
static int NPE()
Definition: commonParameters.h:101
Field::reset
void reset(const int Nin, const int Nvol, const int Nex, const element_type cmpl=Element_type::COMPLEX)
Definition: field.h:95
Solver_CG::get_fopr
Fopr * get_fopr()
Definition: solver_CG.h:91
Solver_CGNR::m_b2
Field m_b2
Definition: solver_CGNR.h:38
Solver_CGNR::set_parameters
void set_parameters(const Parameters &params)
Definition: solver_CGNR.cpp:26
Solver_CG::set_parameters
void set_parameters(const Parameters &params)
Definition: solver_CG.cpp:25
Bridge::BridgeIO::crucial
void crucial(const char *format,...)
Definition: bridgeIO.cpp:180
Field
Container of Field-type object.
Definition: field.h:46
Solver_CG::flop_count
double flop_count()
Definition: solver_CG.cpp:271
solver_CGNR.h
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
CommonParameters::epsilon_criterion
static double epsilon_criterion()
Definition: commonParameters.h:119