Bridge++  Ver. 2.0.2
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 //====================================================================
34 {
35  return this->Solver_CG::get_parameters(params);
36 }
37 
38 
39 //====================================================================
40 void Solver_CGNE::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.",
54  class_name.c_str(), mode_prev.c_str());
55  exit(EXIT_FAILURE);
56  }
57 
58 #pragma omp barrier
59 #pragma omp master
60  {
61  if ((m_y.nin() != b.nin()) || (m_y.nvol() != b.nvol()) ||
62  (m_y.nex() != b.nex())) {
63  m_y.reset(b.nin(), b.nvol(), b.nex());
64  }
65  }
66 #pragma omp barrier
67 
68  // moved to outside the master region [21 Dec 2021 H.M.]
69  if (mode_prev == "D") {
70  fopr->set_mode("DDdag");
71  } else if (mode_prev == "Ddag") {
72  fopr->set_mode("DdagD");
73  }
74 
75  this->Solver_CG::solve(m_y, b, Nconv, diff);
76 
77 #pragma omp barrier
78 //#pragma omp master
79  {
80  fopr->set_mode(mode_prev);
81  }
82 #pragma omp barrier
83 
84  fopr->mult_dag(xq, m_y); // xq = fopr->mult_dag(y);
85 
86 #pragma omp barrier
87 }
88 
89 
90 //====================================================================
92 {
93  const int NPE = CommonParameters::NPE();
94 
95  const double gflop_fopr = this->Solver_CG::get_fopr()->flop_count();
96 
97  if (gflop_fopr < CommonParameters::epsilon_criterion()) {
98  vout.crucial(m_vl, "Warning at %s: no fopr->flop_count() is available, setting flop = 0\n", class_name.c_str());
99  return 0.0;
100  }
101 
102  const double gflop_solver = this->Solver_CG::flop_count();
103 
104  const double gflop = gflop_solver + gflop_fopr;
105 
106  return gflop;
107 }
108 
109 
110 //====================================================================
111 //============================================================END=====
AFopr< Field >
Solver_CG::m_vl
Bridge::VerboseLevel m_vl
Definition: solver_CG.h:44
Parameters
Class for parameters.
Definition: parameters.h:46
Bridge::BridgeIO::detailed
void detailed(const char *format,...)
Definition: bridgeIO.cpp:219
Field::nex
int nex() const
Definition: field.h:128
Solver_CGNE::solve
void solve(Field &solution, const Field &source, int &Nconv, double &diff)
Definition: solver_CGNE.cpp:40
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
Solver_CGNE::get_parameters
void get_parameters(Parameters &params) const
Definition: solver_CGNE.cpp:33
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_CGNE.h
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_CGNE::m_y
Field m_y
Definition: solver_CGNE.h:38
Solver_CG::get_fopr
Fopr * get_fopr()
Definition: solver_CG.h:91
Solver_CGNE::set_parameters
void set_parameters(const Parameters &params)
Definition: solver_CGNE.cpp:26
Solver_CGNE::class_name
static const std::string class_name
Definition: solver_CGNE.h:41
Solver_CGNE::flop_count
double flop_count()
Definition: solver_CGNE.cpp:91
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
Bridge::vout
BridgeIO vout
Definition: bridgeIO.cpp:512
CommonParameters::epsilon_criterion
static double epsilon_criterion()
Definition: commonParameters.h:119