CHROMA
t_bicgstab.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"
15 
16 using namespace Chroma;
17 
18 struct App_input_t {
21 };
22 
23 // Reader for input parameters
24 void read(XMLReader& xml, const std::string& path, App_input_t& input)
25 {
26  XMLReader inputtop(xml, path);
27 
28  // Read the input
29  try
30  {
31  // The parameters holds the version number
32  read(inputtop, "Param", input.param);
33 
34  // Read in the gauge configuration info
35  read(inputtop, "Cfg", input.cfg);
36  }
37  catch (const std::string& e)
38  {
39  QDPIO::cerr << "Error reading data: " << e << std::endl;
40  throw;
41  }
42 }
43 
44 
45 int main(int argc, char **argv)
46 {
47  // Put the machine into a known state
48  Chroma::initialize(&argc, &argv);
49 
50  App_input_t input;
51  XMLReader xml_in(Chroma::getXMLInputFileName());
52 
53  try {
54  read(xml_in, "/BiCGStabTest", input);
55  }
56  catch( const std::string& e) {
57  QDPIO::cerr << "Caught Exception : " << e << std::endl;
58  QDP_abort(1);
59  }
60 
61 
62  // Setup the lattice
63  Layout::setLattSize(input.param.nrow);
64  Layout::create();
65 
66  multi1d<LatticeColorMatrix> u(Nd);
67  XMLReader gauge_file_xml, gauge_xml;
68  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
69 
70  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
71  push(xml_out,"BiCGStabTest");
72 
73 
74  // Measure the plaquette on the gauge
75  MesPlq(xml_out, "Observables", u);
76  xml_out.flush();
77 
78  // Typedefs to save typing
79  typedef LatticeFermion T;
80  typedef multi1d<LatticeColorMatrix> P;
81  typedef multi1d<LatticeColorMatrix> Q;
82 
83  // Create a FermBC
84  Handle<FermBC<T,P,Q> > fbc(new SimpleFermBC<T,P,Q>(input.param.boundary));
85 
86  // Initialize fermion action
87  //
88  FermionAction<LatticeFermion>* S_f_ptr = 0;
90 
91  switch (input.param.FermActHandle->getFermActType() ) {
92  case FERM_ACT_WILSON:
93  {
94  const WilsonFermActParams& wils = dynamic_cast<const WilsonFermActParams&>(*(input.param.FermActHandle));
95 
96  QDPIO::cout << "FERM_ACT_WILSON" << std::endl;
97  S_f_ptr = new EvenOddPrecWilsonFermAct(fbc, wils.Mass,
98  wils.anisoParam);
99  }
100  break;
101 
102  case FERM_ACT_UNPRECONDITIONED_WILSON:
103  {
104  const WilsonFermActParams& wils = dynamic_cast<const WilsonFermActParams&>(*(input.param.FermActHandle));
105 
106  QDPIO::cout << "FERM_ACT_UNPRECONDITIONED_WILSON" << std::endl;
107  S_f_ptr = new UnprecWilsonFermAct(fbc, wils.Mass);
108  }
109  break;
110 
111  case FERM_ACT_ZOLOTAREV_4D:
112  {
113  QDPIO::cout << "FERM_ACT_ZOLOTAREV_4D" << std::endl;
114  const Zolotarev4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
115 
116  // Construct Fermact -- now uses constructor from the zolo4d params
117  // struct
118  S_f_ptr = new Zolotarev4DFermAct(fbc, zolo4d, xml_out);
119  }
120  break;
121 
122  case FERM_ACT_ZOLOTAREV_5D:
123  {
124  QDPIO::cout << "FERM_ACT_ZOLOTAREV_5D" << std::endl;
125  const Zolotarev5DFermActParams& zolo5d = dynamic_cast<const Zolotarev5DFermActParams& > (*(input.param.FermActHandle));
126 
127  // Construct Fermact -- now uses constructor from the zolo4d params
128  // struct
129  S_f_a_ptr = new Zolotarev5DFermActArray(fbc, fbc, zolo5d, xml_out);
130  }
131  break;
132 
133  case FERM_ACT_DWF:
134  {
135  const DWFFermActParams& dwf = dynamic_cast<const DWFFermActParams&>(*(input.param.FermActHandle));
136 
137  QDPIO::cout << "FERM_ACT_DWF" << std::endl;
138  S_f_a_ptr = new EvenOddPrecDWFermActArray(fbc,
139  dwf.chiralParam.OverMass,
140  dwf.Mass,
141  dwf.chiralParam.N5);
142  }
143  break;
144 
145  case FERM_ACT_UNPRECONDITIONED_DWF:
146  {
147  const DWFFermActParams& dwf = dynamic_cast<const DWFFermActParams&>(*(input.param.FermActHandle));
148 
149  QDPIO::cout << "FERM_ACT_UNPRECONDITONED_DWF" << std::endl;
150  S_f_a_ptr = new UnprecDWFermActArray(fbc,
151  dwf.chiralParam.OverMass,
152  dwf.Mass,
153  dwf.chiralParam.N5);
154  }
155  break;
156  default:
157  QDPIO::cerr << "Unsupported fermion action" << std::endl;
158  QDP_abort(1);
159  }
160 
161  QDPIO::cout << "Ferm Act Created " << std::endl;
162 
163  // Create a useable handle on the action
164  // The handle now owns the pointer
166  Handle< FermionAction<T,P,Q> > S_f_a(S_f_a_ptr);
167 
168  // FIrst we have to set up the state -- this is fermact dependent
169  const FermState< *state_ptr;
170 
171  switch(input.param.FermActHandle->getFermActType()) {
172  case FERM_ACT_WILSON:
173  state_ptr = S_f->createState(u);
174  break;
175  case FERM_ACT_UNPRECONDITIONED_WILSON:
176  state_ptr = S_f->createState(u);
177  break;
178  case FERM_ACT_DWF:
179  state_ptr = S_f_a->createState(u);
180  break;
181  case FERM_ACT_UNPRECONDITIONED_DWF:
182  state_ptr = S_f_a->createState(u);
183  break;
184 
185  case FERM_ACT_ZOLOTAREV_4D:
186  {
187  const Zolotarev4DFermActParams& zolo4d = dynamic_cast<const Zolotarev4DFermActParams& > (*(input.param.FermActHandle));
188  const Zolotarev4DFermAct& S_zolo4 = dynamic_cast<const Zolotarev4DFermAct&>(*S_f);
189 
190  state_ptr = S_zolo4.createState(u, zolo4d.StateInfo, xml_out,zolo4d.AuxFermActHandle->getMass());
191 
192  }
193  break;
194  case FERM_ACT_ZOLOTAREV_5D:
195  {
196  const Zolotarev5DFermActParams& zolo5d = dynamic_cast<const Zolotarev5DFermActParams& > (*(input.param.FermActHandle));
197  const Zolotarev5DFermActArray& S_zolo5 = dynamic_cast<const Zolotarev5DFermActArray&>(*S_f_a);
198 
199 
200  state_ptr = S_zolo5.createState(u, zolo5d.StateInfo, xml_out, zolo5d.AuxFermActHandle->getMass());
201  }
202  break;
203 
204  default:
205  QDPIO::cerr << "Unsupported fermion action (state creation)" << std::endl;
206  QDP_abort(1);
207  }
208 
209  // Now do the quarkprop here again depending on which of the
210  // action pointers is not null
211  Handle<const ConnectState> state(state_ptr); // inserts any BC
212 
213  QDPIO::cout << "ConnectState Created" << std::endl;
214 
215  switch(input.param.FermActHandle->getFermActType()) {
216  case FERM_ACT_WILSON:
217  case FERM_ACT_UNPRECONDITIONED_WILSON:
218  case FERM_ACT_ZOLOTAREV_4D:
219  {
220  // 4D BiCGStab test
222 
223  const Subset& s = D->subset();
224 
225  LatticeFermion psi, chi;
226  psi[s] = zero;
227  chi[s] = zero;
228 
229  gaussian(chi[s]);
230  Double chi_norm = sqrt(norm2(chi,s));
231 
232  chi[s] /= chi_norm;
233  psi[s] = zero;
234 
235  int n_count=0;
236  InvBiCGStab( *D, chi, psi, input.param.invParam.RsdCG,
237  input.param.invParam.MaxCG,n_count);
238 
239  // Check back solution
240  LatticeFermion r;
241  (*D)(r, psi, PLUS);
242  r[s] -= chi;
243 
244  QDPIO::cout << " || chi - D psi || / || chi || = " << sqrt(norm2(r,s))/chi_norm << std::endl;
245  }
246  break;
247  case FERM_ACT_DWF:
248  case FERM_ACT_UNPRECONDITIONED_DWF:
249  case FERM_ACT_ZOLOTAREV_5D:
250  {
251  // 4D BiCGStab test
253 
254  const Subset& s = (*D).subset();
255  int N = (*D).size();
256 
257 
258  multi1d<LatticeFermion> psi(N);
259  multi1d<LatticeFermion> chi(N);
260 
261  for(int n=0; n < N; n++) {
262  psi[n][s] = zero;
263  chi[n][s] = zero;
264  }
265 
266  gaussian(chi[N-1][s]);
267  Double chi_norm = sqrt(norm2(chi[N-1],s));
268 
269  chi[N-1][s] /= chi_norm;
270 
271 
272  int n_count=0;
273  InvBiCGStab( *D, chi, psi, input.param.invParam.RsdCG,
274  input.param.invParam.MaxCG,n_count);
275 
276  // Check back solution
277  multi1d<LatticeFermion> r(N);
278  (*D)(r, psi, PLUS);
279 
280  for(int n=0; n < N; n++) {
281  r[n][s] -= chi[n];
282  }
283 
284  QDPIO::cout << " || chi - D psi || / || chi || = " << sqrt(norm2(r,s))/chi_norm << std::endl;
285 
286  }
287  break;
288  default:
289  QDPIO::cerr << "Unsupported fermion action (state creation)" << std::endl;
290  QDP_abort(1);
291  }
292 
293 
294 
295  pop(xml_out);
297 
298  exit(0);
299 }
Primary include file for CHROMA in application codes.
4D style even-odd preconditioned domain-wall fermion action
Even-odd preconditioned Wilson fermion action.
Support class for fermion actions and linear operators.
Definition: state.h:94
Base class for quadratic matter actions (e.g., fermions)
Definition: fermact.h:53
Class for counted reference semantics.
Definition: handle.h:33
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
Unpreconditioned domain-wall fermion action.
Unpreconditioned Wilson fermion action.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
Conjugate-Gradient algorithm for a generic Linear Operator.
unsigned n
Definition: ldumul_w.cc:36
Nd
Definition: meslate.cc:74
multi1d< LatticeColorMatrix > P
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
int n_count
Definition: invbicg.cc:78
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
SystemSolverResults_t InvBiCGStab(const LinearOperator< LatticeFermionF > &A, const LatticeFermionF &chi, LatticeFermionF &psi, const Real &RsdBiCGStab, int MaxBiCGStab, enum PlusMinus isign)
Definition: invbicgstab.cc:222
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)
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
Double chi_norm
Definition: invbicg.cc:79
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
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
multi1d< LatticeFermion > s(Ncb)
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
ChromaProp_t param
Definition: t_bicgstab.cc:19
Gauge configuration structure.
Definition: cfgtype_io.h:16
Propagator parameters.
Definition: qprop_io.h:75
GroupXML_t invParam
Definition: qprop_io.h:84
Params for wilson ferm acts.
int main(int argc, char **argv)
Definition: t_bicgstab.cc:45