CHROMA
t_minvert_quda.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <sstream>
4 #include <iomanip>
5 #include <string>
6 
7 #include <cstdio>
8 
9 #include <stdlib.h>
10 #include <sys/time.h>
11 #include <math.h>
12 
13 #include "chroma.h"
14 
15 #include "io/xml_group_reader.h"
18 #include <string>
19 
25 using namespace Chroma;
26 
27 struct AppParams {
28  multi1d<int> nrow;
29  Cfg_t inputCfg;
30  GroupXML_t fermact;
32 };
33 
34 
35 
36 void checkInverter(const AppParams& p, multi1d<LatticeColorMatrix>& u)
37 {
38 
39  typedef LatticeFermion T;
40  typedef multi1d<LatticeColorMatrix> Q;
41  typedef multi1d<LatticeColorMatrix> P;
42 
43  typedef LatticeFermionF TF;
44  typedef multi1d<LatticeColorMatrixF> QF;
45  typedef multi1d<LatticeColorMatrixF> PF;
46 
47  std::istringstream is(p.fermact.xml);
48  XMLReader fermact_xml(is);
49  Handle< WilsonTypeFermAct<T,P,Q> > S_f ( TheWilsonTypeFermActFactory::Instance().createObject(p.fermact.id, fermact_xml, p.fermact.path) );
50 
51 
52  //S_f(
53  // new EvenOddPrecCloverFermAct(CreateFermStateEnv::reader(fermact_xml, p.fermact.path), CloverFermActParams(fermact_xml, p.fermact.path)));
54 
55 
56  Handle< FermState<T,P,Q> > connect_state( S_f->createState(u) );
57  Handle< LinearOperator<LatticeFermion> > D_op( S_f->linOp(connect_state) );
58 
59 
60 
61  int n_shifts=12;
62  multi1d<Real> shifts(n_shifts);
63  shifts[0] = 0.00005;
64  shifts[1] = 0.000165259114300968 ;
65  shifts[2] = 0.000661184012887753 ;
66  shifts[3] = 0.00214955953261573 ;
67  shifts[4] = 0.00657190811374048 ;
68  shifts[5] = 0.0197043312297316 ;
69  shifts[6] = 0.0587640674448055 ;
70  shifts[7] = 0.175534749714768 ;
71  shifts[8] = 0.529999019144126 ;
72  shifts[9] = 1.6565878795396 ;
73  shifts[10] = 5.78532483906374 ;
74  shifts[11] = 30.6835527589452 ;
75 
76  multi1d<Real> RsdCG(n_shifts);
77  for(int i=0; i < n_shifts;i++) {
78  RsdCG[i] = p.invParam.RsdTarget[i];
79  }
80 
81 
82 
83  MdagMMultiSysSolverCGQudaClover mprec(D_op, connect_state, p.invParam);
84 
85 
86  LatticeFermion chi;
87  gaussian(chi, D_op->subset());
88 
89  // Initialized psi
90  multi1d<LatticeFermion> psi(n_shifts);
91  for(int i=0; i < n_shifts; i++){
92  psi[i] = zero;
93  }
94 
95 
97  StopWatch swatch;
98  swatch.reset();
99  swatch.start();
100  MInvCG2(*D_op, chi, psi, shifts, RsdCG, p.invParam.MaxIter, res.n_count);
101  swatch.stop();
102 
103  // Check solutions
104  for(int i=0; i < n_shifts; i++) {
105  LatticeFermion r;
106  r[D_op->subset()]= chi;
107  LatticeFermion tmp1,tmp2;
108  (*D_op)(tmp1, psi[i], PLUS);
109  (*D_op)(tmp2, tmp1, MINUS);
110  tmp2[D_op->subset()] += shifts[i]*psi[i];
111  r[D_op->subset()] -= tmp2;
112  Double norm = norm2(r, D_op->subset())/norm2(chi, D_op->subset());
113 
114  QDPIO::cout << "soln "<< i <<" : RsdCG=" << RsdCG[i] << " r=" << sqrt(norm) << std::endl;
115  }
116  QDPIO::cout << "MinvCG: n_count = " << res.n_count << " Time=" << swatch.getTimeInSeconds() << std::endl;
117 
118  swatch.reset();
119  swatch.start();
120 
121  SystemSolverResults_t res2 = mprec(psi, shifts, chi);
122 
123  swatch.stop();
124  for(int i=0; i < n_shifts; i++) {
125  LatticeFermion r;
126  r[D_op->subset()]= chi;
127  LatticeFermion tmp1,tmp2;
128  (*D_op)(tmp1, psi[i], PLUS);
129  (*D_op)(tmp2, tmp1, MINUS);
130  tmp2[D_op->subset()] += shifts[i]*psi[i];
131  r[D_op->subset()] -= tmp2;
132  Double norm = norm2(r, D_op->subset())/norm2(chi, D_op->subset());
133 
134  QDPIO::cout << "soln "<< i <<" : RsdCG=" << RsdCG[i] << " r=" << sqrt(norm) << std::endl;
135  }
136  QDPIO::cout << "Chrono: n_count = " << res2.n_count << " Time=" << swatch.getTimeInSeconds() << std::endl;
137 
138 }
139 
140 
141 void read(XMLReader& r, const std::string path, AppParams& p)
142 {
143  read(r, "nrow", p.nrow);
144  read(r, "Cfg", p.inputCfg);
145  p.fermact = readXMLGroup(r, "FermionAction", "FermAct");
146  read(r, "InvertParam", p.invParam);
147 
148 }
149 
150 bool linkageHack(void)
151 {
152  bool foo = true;
153 
154  // Inline Measurements
156  foo &= GaugeInitEnv::registerAll();
157 
158  return foo;
159 }
160 
161 int main(int argc, char **argv)
162 {
163  // Put the machine into a known state
164  Chroma::initialize(&argc, &argv);
165  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
166 
167 
169 
170  XMLReader xml_in;
171  try
172  {
173  xml_in.open(Chroma::getXMLInputFileName());
174  read(xml_in, "/Param", params);
175  }
176  catch(const std::string& e)
177  {
178  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
179  QDP_abort(1);
180  }
181  Layout::setLattSize(params.nrow);
182  Layout::create();
183 
184  multi1d<LatticeColorMatrix> u(Nd);
185  XMLReader gauge_file_xml, gauge_xml;
186  gaugeStartup(gauge_file_xml, gauge_xml, u, params.inputCfg);
187  unitarityCheck(u);
188 
189  // Setup the lattice
190 
191  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
192  push(xml_out,"t_invert");
193  push(xml_out,"params");
194  write(xml_out, "nrow", params.nrow);
195  pop(xml_out); // Params
196 
197  // Measure the plaquette on the gauge
198  MesPlq(xml_out, "Observables", u);
199  xml_out.flush();
200 
202 
203  pop(xml_out);
204  xml_out.close();
205 
207 
208  exit(0);
209 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
Parameters for Clover fermion action.
Even-odd preconditioned Clover fermion linear operator.
All ferm create-state method.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void unitarityCheck(const multi1d< LatticeColorMatrixF3 > &u)
Check the unitarity of color matrix in SU(N)
Definition: unit_check.cc:20
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void MInvCG2(const LinearOperator< LatticeFermionF > &M, const LatticeFermionF &chi, multi1d< LatticeFermionF > &psi, const multi1d< RealF > &shifts, const multi1d< RealF > &RsdCG, int MaxCG, int &n_count)
Definition: minvcg2.cc:376
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Params params
Nd
Definition: meslate.cc:74
Double tmp2
Definition: mesq.cc:30
Multishift Conjugate-Gradient algorithm for a Linear Operator.
Solve a MdagM*psi=chi linear system by CG2 using CG.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< LatticeColorMatrix > P
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > const multi1d< Real > enum InvType invType const multi1d< Real > & RsdCG
Definition: pbg5p_w.cc:30
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ MINUS
Definition: chromabase.h:45
@ PLUS
Definition: chromabase.h:45
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
multi1d< LatticeFermion > chi(Ncb)
bool linkageHack(void)
Definition: const_hmc.cc:660
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
int norm
Definition: qtopcor.cc:35
MultiSysSolverQUDACloverParams invParam
Gauge configuration structure.
Definition: cfgtype_io.h:16
Hold group xml and type id.
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Factory for solving M*psi=chi where M is not hermitian or pos. def.
std::string fermact_xml
void checkInverter(const AppParams &p, multi1d< LatticeColorMatrix > &u)
int main(int argc, char **argv)
multi1d< LatticeColorMatrixF > QF
Definition: t_quda_tprec.cc:19
multi1d< LatticeColorMatrixF > PF
Definition: t_quda_tprec.cc:20
LatticeFermionF TF
Definition: t_quda_tprec.cc:17
Read an XML group as a std::string.