CHROMA
t_invert3_precwilson.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 
20 struct Params_t {
21  multi1d<int> nrow;
22  multi1d<int> boundary;
24 };
25 
26 
27 int main(int argc, char **argv)
28 {
29  // Put the machine into a known state
30  Chroma::initialize(&argc, &argv);
31 
33 
34  // Read params
36 
37  std::string stype;
38  try {
39  read(reader, "/t_invert/params/nrow", params.nrow);
40  read(reader, "/t_invert/params/gauge_start_type", stype);
41  }
42  catch(const std::string &error) {
43  QDPIO::cerr << "Error : " << error << std::endl;
44  throw;
45  }
46  reader.close();
47 
48  if( stype == "HOT_START" ) {
49  params.gauge_start_type = HOT_START;
50  }
51  else if( stype == "COLD_START" ) {
52  params.gauge_start_type = COLD_START;
53  }
54 
55  QDPIO::cout << "Gauge start type " ;
56  switch (params.gauge_start_type) {
57  case HOT_START:
58  QDPIO::cout << "hot start" << std::endl;
59  break;
60  case COLD_START:
61  QDPIO::cout << "cold start" << std::endl;
62  break;
63  default:
64  QDPIO::cout << std::endl;
65  QDPIO::cerr << "Unknown gauge start type " << std::endl;
66  }
67 
68  params.boundary.resize(4);
69  params.boundary[0] = 1;
70  params.boundary[1] = 1;
71  params.boundary[2] = 1;
72  params.boundary[3] = 1;
73 
74 
75  // Setup the lattice
76  const multi1d<int>& msize = Layout::logicalSize();
77  Layout::setLattSize(params.nrow);
78  Layout::create();
79 
80  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
81  push(xml,"t_invert");
82  proginfo(xml); // Print out basic program info
83  push(xml,"params");
84  write(xml, "nrow", params.nrow);
85  write(xml, "boundary", params.boundary);
86  write(xml, "gauge_start_type", stype);
87  pop(xml); // Params
88 
89  // Create a FermBC
91 
92  // The Gauge Field
93  multi1d<LatticeColorMatrix> u(Nd);
94 
95  switch ((GaugeStartType)params.gauge_start_type) {
96  case COLD_START:
97  for(int j = 0; j < Nd; j++) {
98  u(j) = Real(1);
99  }
100  break;
101  case HOT_START:
102  // Hot (disordered) start
103  for(int j=0; j < Nd; j++) {
104  random(u(j));
105  reunit(u(j));
106  }
107  break;
108  default:
109  std::ostringstream startup_error;
110  startup_error << "Unknown start type " << params.gauge_start_type <<std::endl;
111  throw startup_error.str();
112  }
113 
114 
115  // Measure the plaquette on the gauge
116  MesPlq(xml, "Observables", u);
117  xml.flush();
118 
119  //! Wilsoniums;
120  // Put this puppy into a handle to allow Zolo to copy it around as a **BASE** class
121  // WARNING: the handle now owns the data. The use of a bare S_w below is legal,
122  // but just don't delete it.
123  EvenOddPrecWilsonFermAct S_w(fbc, Real(0));
124 
125  Handle<const ConnectState> connect_state(S_w.createState(u));
126 
127 
128  // Make me a linop (this callls the initialise function)
129  Handle<const EvenOddPrecWilsonLinOp > D_op( dynamic_cast<const EvenOddPrecWilsonLinOp *> (S_w.linOp(connect_state)) );
130 
131 
132  LatticeFermion chi;
133  LatticeFermion psi;
134  StopWatch swatch;
135  Double mydt;
136  int iter;
137 
138  LatticeFermion bchi,bpsi;
139  gaussian(bchi);
140  gaussian(bpsi);
141 
142  mydt=Double(0);
143  int j;
144  for(iter =1; ; iter <<= 1) {
145  gaussian(bpsi);
146  QDPIO::cout << "Applying PrecWilsonLinOp " <<iter << " times" << std::endl;
147  swatch.reset();
148  swatch.start();
149  for(j=0 ; j < iter; j++) {
150  (*D_op)(bchi,bpsi,PLUS);
151  }
152  swatch.stop();
153  mydt = swatch.getTimeInSeconds();
154  QDPInternal::globalSum(mydt);
155  mydt /= Double(Layout::numNodes());
156 
157  if( toBool(mydt > Double(1)) ) break;
158  }
159 
160  // Now mydt holds the time for 1 cpu for iter iterations.
161  // get time for 1 iter
162  mydt /= Double(iter);
163 
164  // mydt now holds the time for 1 iter on 1cpu in seconds
165  mydt *= Double(1.0e6);
166 
167  // mydt now holds the time for 1 iter on 1 cpu in microsecs.
168  Double flops_cpu_iter = Double(2*1320+3*24)*Layout::sitesOnNode()/Double(2);
169  Double linop_flops_in_mflops = flops_cpu_iter / mydt;
170 
171  QDPIO::cout << "PrecWilsonOp perf: " << linop_flops_in_mflops << " Mflop/s/node" << std::endl;
172  push(xml, "TimeLinOp");
173  write(xml, "time", mydt);
174  write(xml, "mflops", linop_flops_in_mflops);
175  pop(xml);
176 
177  for(iter=1; ; iter <<= 1)
178  {
179  psi = zero;
180  QDPIO::cout << "Let 0 action inverter iterate "<< iter << " times" << std::endl;
181 
182  gaussian(chi);
183  swatch.reset();
184  swatch.start();
185 
186  InvCG2_timing_hacks(*D_op,
187  chi,
188  psi,
189  Real(1.0e-7),
190  100000,
191  iter);
192 
193  swatch.stop();
194 
195  mydt=Double(swatch.getTimeInSeconds());
196  QDPInternal::globalSum(mydt);
197  mydt /= Double(Layout::numNodes());
198 
199  QDPIO::cout << "Time was " << mydt << " seconds" << std::endl;
200 
201  if ( toBool(mydt > Double(1) ) )
202  break;
203  }
204 
205 
206  // Snarfed from SZIN
207  int N_dslash = 1320;
208  int N_mpsi = 3*24 + 2*N_dslash;
209  int Nflops_c = (24 + 2*N_mpsi) + (48);
210  int Nflops_s = (2*N_mpsi + (2*48+2*24));
211  Double Nflops;
212 
213  multi1d<Double> mflops(10);
214  multi1d<Double> mydt_a(10);
215 
216  for (j=0; j < 10; ++j)
217  {
218  psi = zero;
219 
220  swatch.reset();
221  swatch.start();
222 
223  InvCG2_timing_hacks(*D_op,
224  chi,
225  psi,
226  Real(1.0e-7),
227  100000,
228  iter);
229 
230  swatch.stop();
231  mydt=Double(swatch.getTimeInSeconds());
232 
233  QDPInternal::globalSum(mydt);
234 
235  mydt /= Double(Layout::numNodes());
236 
237  mydt_a[j] = Double(1.0e6)*mydt/(Double(Layout::sitesOnNode())/Double(2));
238 
239  // Flop count for inverter
240  Nflops = Double(Nflops_c) + Double(iter*Nflops_s);
241  mflops[j] = Nflops / mydt_a[j];
242  }
243 
244  mydt=1.0e6f*mydt/((Double)(Layout::sitesOnNode())/Double(2));
245 
246  push(xml, "TimeCG2");
247  write(xml, "iter", iter);
248  write(xml, "N_dslash", N_dslash);
249  write(xml, "N_mpsi", N_mpsi);
250  write(xml, "Nflops", Nflops);
251  write(xml, "mydt_a", mydt_a);
252  write(xml, "mflops_a", mflops);
253  pop(xml);
254 
255  pop(xml);
256  xml.close();
257 
259 
260  exit(0);
261 }
Primary include file for CHROMA in application codes.
Even-odd preconditioned Wilson fermion action.
EvenOddPrecConstDetLinearOperator< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Produce a linear operator for this action.
Even-odd preconditioned Wilson-Dirac operator.
virtual FermState< T, P, Q > * createState(const Q &q) const
Given links (coordinates Q) create the state needed for the linear operators.
Definition: fermact.h:59
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 write(XMLWriter &xml, const std::string &path, const AsqtadFermActParams &param)
Writer parameters.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
Params params
Conjugate-Gradient algorithm for a generic Linear Operator.
unsigned j
Definition: ldumul_w.cc:35
Nd
Definition: meslate.cc:74
Handle< FermBC< LatticeStaggeredFermion, multi1d< LatticeColorMatrix >, multi1d< LatticeColorMatrix > > > reader(XMLReader &xml_in, const std::string &path)
Helper function for the FermionAction readers.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
static multi1d< LatticeColorMatrix > u
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
multi1d< LatticeFermion > chi(Ncb)
void reunit(LatticeColorMatrixF3 &xa)
Definition: reunit.cc:467
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
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
::std::string string
Definition: gtest.h:1979
GaugeStartType gauge_start_type
multi1d< int > boundary
GaugeStartType
int main(int argc, char **argv)
@ COLD_START