CHROMA
t_mgproto.cc
Go to the documentation of this file.
1 // $Id: t_invert4_precwilson.cc,v 3.4 2009-10-09 13:59:46 bjoo Exp $
2 
3 #include "chroma.h"
4 #include <iostream>
5 #include <sstream>
6 #include <iomanip>
7 #include <string>
8 
9 #include <cstdio>
10 
11 #include <stdlib.h>
12 #include <sys/time.h>
13 #include <math.h>
14 
15 
16 #include "io/xml_group_reader.h"
19 #include <string>
20 
25 
28 
29 #include "lattice/fine_qdpxx/wilson_clover_linear_operator.h"
30 
31 using namespace Chroma;
32 
33 struct AppParams {
34  multi1d<int> nrow;
35  Cfg_t inputCfg;
36  GroupXML_t fermact;
38 };
39 
40 
41 
42 void checkInverter(const AppParams& p, multi1d<LatticeColorMatrix>& u)
43 {
44 
45  typedef LatticeFermion T;
46  typedef multi1d<LatticeColorMatrix> Q;
47  typedef multi1d<LatticeColorMatrix> P;
48 
49  typedef LatticeFermionF TF;
50  typedef multi1d<LatticeColorMatrixF> QF;
51  typedef multi1d<LatticeColorMatrixF> PF;
52 
53  std::istringstream is(p.fermact.xml);
54  XMLReader fermact_xml(is);
55  Handle< WilsonTypeFermAct<T,P,Q> > S_f ( TheWilsonTypeFermActFactory::Instance().createObject(p.fermact.id, fermact_xml, p.fermact.path) );
56 
57 
58  //S_f(
59  // new EvenOddPrecCloverFermAct(CreateFermStateEnv::reader(fermact_xml, p.fermact.path), CloverFermActParams(fermact_xml, p.fermact.path)));
60 
61 
62  Handle< FermState<T,P,Q> > connect_state( S_f->createState(u) );
63  Handle< Chroma::LinearOperator<LatticeFermion> > D_op( S_f->linOp(connect_state) );
64 
65 
66  XMLBufferWriter xml_buf;
67  write(xml_buf, "MGProtoParams", p.mgproto_params);
68  QDPIO::cout << xml_buf.str() << std::endl;
69 
70 
71  // Check the FineM against the linear operator.
72  QDPIO::cout << "Testing MGProto Fine Linear Operator: " << std::endl;
73  {
74  LatticeFermion psi; LatticeFermion chi1; LatticeFermion chi2;
75  gaussian(psi);
76  chi1=zero;
77  chi2=zero;
78 
79 
80  QDPIO::cout << "Applying Chroma UnprecCloverLinop" <<std::endl;
81  (*D_op)(chi1,psi,PLUS);
82 
83 
84  std::shared_ptr<const MG::QDPWilsonCloverLinearOperator> D_op_mg = MGProtoHelpers::createFineLinOp(p.mgproto_params,
85  connect_state->getLinks());
86 
87  QDPIO::cout << "Applying MG QDPWilsonCloverLinearOperator " << std::endl;
88  (*D_op_mg)(chi2,psi,MG::LINOP_OP);
89 
90  LatticeFermion diff=chi2-chi1;
91  Double n2_diff = sqrt(norm2(diff));
92  QDPIO::cout << "Diff Norm = " << n2_diff << std::endl;
93  QDPIO::cout << "Diff Norm/norm2psi = " << n2_diff /sqrt(norm2(psi)) << std::endl;
94  QDPIO::cout << "Diff Norm / d.o.f = " << n2_diff / toDouble(Layout::vol()*Nc*Ns) << std::endl;
95  }
96 
97  // Try and create the solver object:
98 
99  {
100  LinOpSysSolverMGProtoClover the_solver(D_op, connect_state, p.mgproto_params);
101  LatticeFermion psi, chi;
102  gaussian(chi);
103  psi=zero;
104 
105  the_solver(psi,chi);
106 
107  LatticeFermion diff;
108  diff=zero;
109 
110  (*D_op)(diff,psi, PLUS); // Diff = Ax
111  diff -= chi; // Diff = Ax - b = -( b - Ax )
112  Double n2diff = norm2(diff);
113  Double reln2diff = n2diff/norm2(chi);
114  QDPIO::cout << " || b - A x || = " << sqrt(n2diff) << std::endl;
115  QDPIO::cout << " || b - A x || / || b || = " << sqrt(reln2diff) << std::endl;
116 
117  }
118 
119  // Now do it again. This time one should fine the solver object
120  {
121  LinOpSysSolverMGProtoClover the_solver(D_op, connect_state, p.mgproto_params);
122  LatticeFermion psi, chi;
123  gaussian(chi);
124  psi=zero;
125 
126  the_solver(psi,chi);
127 
128  LatticeFermion diff;
129  diff=zero;
130  (*D_op)(diff,psi, PLUS); // Diff = Ax
131  diff -= chi; // Diff = Ax - b = -( b - Ax )
132  Double n2diff = norm2(diff);
133  Double reln2diff = n2diff/norm2(chi);
134  QDPIO::cout << " || b - A x || = " << sqrt(n2diff) << std::endl;
135  QDPIO::cout << " || b - A x || / || b || = " << sqrt(reln2diff) << std::endl;
136 
137  }
138 
139  // Delete the MG Stuff
140  MGProtoHelpers::deleteMGPreconditioner(p.mgproto_params.SubspaceId);
141 
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, "MGProtoParams", p.mgproto_params);
152 }
153 
154 bool linkageHack(void)
155 {
156  bool foo = true;
157 
158  // Inline Measurements
160  foo &= GaugeInitEnv::registerAll();
161 
162  return foo;
163 }
164 
165 int main(int argc, char **argv)
166 {
167  // Put the machine into a known state
168  Chroma::initialize(&argc, &argv);
169  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
170 
171 
173 
174  XMLReader xml_in;
175  try
176  {
177  xml_in.open(Chroma::getXMLInputFileName());
178  read(xml_in, "/Param", params);
179  }
180  catch(const std::string& e)
181  {
182  QDPIO::cerr << "Caught Exception reading XML: " << e << std::endl;
183  QDP_abort(1);
184  }
185  Layout::setLattSize(params.nrow);
186  Layout::create();
187 
188  multi1d<LatticeColorMatrix> u(Nd);
189  XMLReader gauge_file_xml, gauge_xml;
190  gaugeStartup(gauge_file_xml, gauge_xml, u, params.inputCfg);
191  unitarityCheck(u);
192 
193  // Setup the lattice
194 
195  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
196  push(xml_out,"t_invert");
197  push(xml_out,"params");
198  write(xml_out, "nrow", params.nrow);
199  pop(xml_out); // Params
200 
201  // Measure the plaquette on the gauge
202  MesPlq(xml_out, "Observables", u);
203  xml_out.flush();
204 
206 
207  pop(xml_out);
208  xml_out.close();
209 
211 
212  exit(0);
213 }
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.
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
Multishift Conjugate-Gradient algorithm for a Linear Operator.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< LatticeColorMatrix > P
shared_ptr< const MG::QDPWilsonCloverLinearOperator > createFineLinOp(const MGProtoSolverParams &params, const multi1d< LatticeColorMatrix > &u)
void deleteMGPreconditioner(const std::string &subspaceId)
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
void initialize(int *argc, char ***argv)
Chroma initialisation routine.
Definition: chroma_init.cc:114
@ 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
MGProtoSolverParams mgproto_params
Definition: t_mgproto.cc:37
Gauge configuration structure.
Definition: cfgtype_io.h:16
Hold group xml and type id.
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_mgproto.cc:42
int main(int argc, char **argv)
Definition: t_mgproto.cc:165
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.