CHROMA
t_minvert.cc
Go to the documentation of this file.
1 
2 #include "chroma.h"
3 #include <iostream>
4 #include <sstream>
5 #include <iomanip>
6 #include <string>
7 
8 #include <cstdio>
9 
10 #include <stdlib.h>
11 #include <sys/time.h>
12 #include <math.h>
13 
14 
15 #include "io/xml_group_reader.h"
18 #include <string>
19 
24 using namespace Chroma;
25 
26 struct AppParams {
27  multi1d<int> nrow;
28  Cfg_t inputCfg;
29  GroupXML_t fermact;
31 };
32 
33 
34 
35 void checkInverter(const AppParams& p, multi1d<LatticeColorMatrix>& u)
36 {
37 
38  typedef LatticeFermion T;
39  typedef multi1d<LatticeColorMatrix> Q;
40  typedef multi1d<LatticeColorMatrix> P;
41 
42  typedef LatticeFermionF TF;
43  typedef multi1d<LatticeColorMatrixF> QF;
44  typedef multi1d<LatticeColorMatrixF> PF;
45 
46  std::istringstream is(p.fermact.xml);
47  XMLReader fermact_xml(is);
48  Handle< WilsonTypeFermAct<T,P,Q> > S_f ( TheWilsonTypeFermActFactory::Instance().createObject(p.fermact.id, fermact_xml, p.fermact.path) );
49 
50 
51  //S_f(
52  // new EvenOddPrecCloverFermAct(CreateFermStateEnv::reader(fermact_xml, p.fermact.path), CloverFermActParams(fermact_xml, p.fermact.path)));
53 
54 
55  Handle< FermState<T,P,Q> > connect_state( S_f->createState(u) );
56  Handle< LinearOperator<LatticeFermion> > D_op( S_f->linOp(connect_state) );
57 
58 
59  MdagMMultiSysSolverCGChronoClover mprec(D_op, connect_state, p.invParam);
60 
61  int n_shifts=12;
62  multi1d<Real> shifts(n_shifts);
63  shifts[0] = 1.51480322230288e-05 ;
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(shifts.size());
77  if (p.invParam.RsdTarget.size() == 1) {
78  RsdCG = p.invParam.RsdTarget[0];
79  }
80  else if (p.invParam.RsdTarget.size() == RsdCG.size()) {
81 
82  RsdCG = p.invParam.RsdTarget;
83  }
84  else {
85 
86  QDPIO::cerr << "MdagMMultiSysSolverCGChronoClover: shifts incompatible" << std::endl;
87  QDP_abort(1);
88  }
89 
90 
91 
92  LatticeFermion chi;
93  gaussian(chi, D_op->subset());
94 
95  // Initialized psi
96  multi1d<LatticeFermion> psi(n_shifts);
97  for(int i=0; i < n_shifts; i++){
98  psi[i] = zero;
99  }
100 
102  StopWatch swatch;
103  swatch.reset();
104  swatch.start();
105  MInvCG2(*D_op, chi, psi, shifts, RsdCG, p.invParam.MaxIter, res.n_count);
106  swatch.stop();
107 
108  // Check solutions
109  for(int i=0; i < n_shifts; i++) {
110  LatticeFermion r;
111  r[D_op->subset()]= chi;
112  LatticeFermion tmp1,tmp2;
113  (*D_op)(tmp1, psi[i], PLUS);
114  (*D_op)(tmp2, tmp1, MINUS);
115  tmp2[D_op->subset()] += shifts[i]*psi[i];
116  r[D_op->subset()] -= tmp2;
117  Double norm = norm2(r, D_op->subset())/norm2(chi, D_op->subset());
118 
119  QDPIO::cout << "soln "<< i <<" : RsdCG=" << RsdCG[i] << " r=" << sqrt(norm) << std::endl;
120  }
121  QDPIO::cout << "MinvCG: n_count = " << res.n_count << " Time=" << swatch.getTimeInSeconds() << std::endl;
122 
123  swatch.reset();
124  swatch.start();
125 
126  SystemSolverResults_t res2 = mprec(psi, shifts, chi);
127 
128  swatch.stop();
129  for(int i=0; i < n_shifts; i++) {
130  LatticeFermion r;
131  r[D_op->subset()]= chi;
132  LatticeFermion tmp1,tmp2;
133  (*D_op)(tmp1, psi[i], PLUS);
134  (*D_op)(tmp2, tmp1, MINUS);
135  tmp2[D_op->subset()] += shifts[i]*psi[i];
136  r[D_op->subset()] -= tmp2;
137  Double norm = norm2(r, D_op->subset())/norm2(chi, D_op->subset());
138 
139  QDPIO::cout << "soln "<< i <<" : RsdCG=" << RsdCG[i] << " r=" << sqrt(norm) << std::endl;
140  }
141  QDPIO::cout << "Chrono: n_count = " << res2.n_count << " Time=" << swatch.getTimeInSeconds() << std::endl;
142 
143 }
144 
145 
146 void read(XMLReader& r, const std::string path, AppParams& p)
147 {
148  read(r, "nrow", p.nrow);
149  read(r, "Cfg", p.inputCfg);
150  p.fermact = readXMLGroup(r, "FermionAction", "FermAct");
151  read(r, "InvertParam", p.invParam);
152 
153 }
154 
155 bool linkageHack(void)
156 {
157  bool foo = true;
158 
159  // Inline Measurements
161  foo &= GaugeInitEnv::registerAll();
162 
163  return foo;
164 }
165 
166 int main(int argc, char **argv)
167 {
168  // Put the machine into a known state
169  Chroma::initialize(&argc, &argv);
170  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
171 
172 
174 
175  XMLReader xml_in;
176  try
177  {
178  xml_in.open(Chroma::getXMLInputFileName());
179  read(xml_in, "/Param", params);
180  }
181  catch(const std::string& e)
182  {
183  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
184  QDP_abort(1);
185  }
186  Layout::setLattSize(params.nrow);
187  Layout::create();
188 
189  multi1d<LatticeColorMatrix> u(Nd);
190  XMLReader gauge_file_xml, gauge_xml;
191  gaugeStartup(gauge_file_xml, gauge_xml, u, params.inputCfg);
192  unitarityCheck(u);
193 
194  // Setup the lattice
195 
196  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
197  push(xml_out,"t_invert");
198  push(xml_out,"params");
199  write(xml_out, "nrow", params.nrow);
200  pop(xml_out); // Params
201 
202  // Measure the plaquette on the gauge
203  MesPlq(xml_out, "Observables", u);
204  xml_out.flush();
205 
207 
208  pop(xml_out);
209  xml_out.close();
210 
212 
213  exit(0);
214 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Solve a CG2 system. Here, the operator is NOT assumed to be hermitian.
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
MultiSysSolverCGChronoCloverParams invParam
Definition: t_minvert.cc:30
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)
Definition: t_minvert.cc:35
int main(int argc, char **argv)
Definition: t_minvert.cc:166
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.