CHROMA
t_invborici.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 
16 
17 using namespace Chroma;
18 
19 struct App_input_t {
20  Zolotarev4DFermActParams* zolo4D;
21  Zolotarev5DFermActParams* zolo5D;
22  multi1d<int> nrow;
23  multi1d<int> boundary;
24  InvertParam_t invParam;
25  Cfg_t cfg;
26 };
27 
28 // Reader for input parameters
29 void read(XMLReader& xml, const std::string& path, App_input_t& input)
30 {
31  XMLReader inputtop(xml, path);
32 
33  // Read the input
34  try
35  {
36  read(inputtop, "nrow", input.nrow);
37  read(inputtop, "boundary", input.boundary);
38  input.zolo4D = dynamic_cast<Zolotarev4DFermActParams*>(read(inputtop, "Zolo4D"));
39  input.zolo5D = dynamic_cast<Zolotarev5DFermActParams*>(read(inputtop, "Zolo5D"));
40  read(inputtop, "InvertParam", input.invParam);
41  read(inputtop, "Cfg", input.cfg);
42  }
43  catch (const std::string& e)
44  {
45  QDPIO::cerr << "Error reading data: " << e << std::endl;
46  throw;
47  }
48 }
49 
50 
51 int main(int argc, char **argv)
52 {
53  // Put the machine into a known state
54  Chroma::initialize(&argc, &argv);
55 
56  App_input_t input;
57  XMLReader xml_in(Chroma::getXMLInputFileName());
58 
59  try {
60  read(xml_in, "/BoriciTest", input);
61  }
62  catch( const std::string& e) {
63  QDPIO::cerr << "Caught Exception : " << e << std::endl;
64  QDP_abort(1);
65  }
66 
67 
68  // Setup the lattice
69  Layout::setLattSize(input.nrow);
70  Layout::create();
71 
72  multi1d<LatticeColorMatrix> u(Nd);
73  XMLReader gauge_file_xml, gauge_xml;
74  gaugeStartup(gauge_file_xml, gauge_xml, u, input.cfg);
75 
76  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
77  push(xml_out,"t_borici");
78 
79 
80  // Measure the plaquette on the gauge
81  MesPlq(xml_out, "Observables", u);
82  xml_out.flush();
83 
84  // Create a 4D FermBC
86 
87  // Create a 5D FermBC
88  Handle< FermBC<multi1d<LatticeFermion> > > fbc_a(new SimpleFermBC<multi1d<LatticeFermion> >(input.boundary));
89 
90 
91  // Make the Actions
92  Zolotarev5DFermActArray S5(fbc_a, fbc, *(input.zolo5D), xml_out);
93  Zolotarev4DFermAct S4(fbc, *(input.zolo4D), xml_out);
94 
95 
96  // Make the connect state(s)
97  Handle<const ConnectState> state_4(S4.createState(u, input.zolo4D->StateInfo, xml_out, input.zolo4D->AuxFermActHandle->getMass()));
98 
99  Handle<const ConnectState> state_5(S5.createState(u, input.zolo5D->StateInfo, xml_out, input.zolo5D->AuxFermActHandle->getMass()));
100 
101 
102  // Make the LinOps
103  Handle<const LinearOperator<LatticeFermion> > D_4(S4.linOp(state_4));
104  Handle<const LinearOperator< multi1d<LatticeFermion> > > D_5(S5.linOp(state_5));
105  Handle<const LinearOperator< multi1d<LatticeFermion> > > D_dag_D_5(S5.lMdagM(state_5));
106 
107  LatticeFermion b;
108  // Solve on chiral point source
109  multi1d<int> coord(4);
110  coord[0] = 0;
111  coord[1] = 0;
112  coord[2] = 0;
113  coord[3] = 0;
114  b=zero;
115  srcfil(b, coord, 0, 0);
116 
117  LatticeFermion x = zero;
118 
119  int n_iters;
120  QDP::StopWatch swatch;
121  swatch.reset();
122  swatch.start();
123 
124  InvBorici(*D_4,
125  *D_5,
126  *D_dag_D_5,
127  b,
128  x,
129  input.invParam.RsdCG,
130  input.invParam.RsdCGPrec,
131  input.invParam.MaxCG,
132  input.invParam.MaxCGPrec,
133  input.zolo5D->AuxFermActHandle->getMass(),
134  n_iters);
135 
136  swatch.stop();
137 
138  QDPIO::cout << "InvBorici: " << n_iters << " iterations " << std::endl;
139 
140  LatticeFermion tmp;
141  (*D_4)(tmp, x, PLUS);
142  tmp -= b;
143  Double tmpnorm = sqrt(norm2(tmp)/norm2(b));
144  QDPIO::cout << "Final residue: " << tmpnorm << std::endl;
145  QDPIO::cout << "Time: " << swatch.getTimeInSeconds() << " s" << std::endl;
146 
147  x = zero;
148 
149  swatch.reset();
150  swatch.start();
151 
152  S4.qprop(x, state_4, b, REL_GMRESR_SUMR_INVERTER,
153  input.invParam.RsdCG,
154  input.invParam.RsdCGPrec,
155  input.invParam.MaxCG,
156  input.invParam.MaxCGPrec,
157  n_iters);
158 
159  swatch.stop();
160  QDPIO::cout << "Time: " << swatch.getTimeInSeconds() << " s" << std::endl;
161 
162  pop(xml_out);
164 
165  exit(0);
166 }
Primary include file for CHROMA in application codes.
Class for counted reference semantics.
Definition: handle.h:33
Concrete class for all gauge actions with simple boundary conditions.
Definition: simple_fermbc.h:42
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.
void srcfil(LatticeFermion &a, const multi1d< int > &coord, int color_index, int spin_index)
Fill a specific color and spin index with 1.0.
Definition: srcfil.cc:23
multi1d< int > coord(Nd)
int x
Definition: meslate.cc:34
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
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
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
void InvBorici(const LinearOperator< LatticeFermion > &D_4, const LinearOperatorArray< LatticeFermion > &D_5, const LinearOperatorArray< LatticeFermion > &D_dag_D_5, const LatticeFermion &b, LatticeFermion &x, const Real &tol, const Real &tol_1, const int MaxIter, const int MaxIter5D, const Real &m, int &n_iters)
Complex b
Definition: invbicg.cc:96
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
Zolotarev4DFermActParams * zolo4D
Definition: t_invborici.cc:20
InvertParam_t invParam
Definition: t_invborici.cc:24
multi1d< int > boundary
Definition: t_invborici.cc:23
multi1d< int > nrow
Definition: t_invborici.cc:22
Zolotarev5DFermActParams * zolo5D
Definition: t_invborici.cc:21
Gauge configuration structure.
Definition: cfgtype_io.h:16
int main(int argc, char **argv)
Definition: t_invborici.cc:51