CHROMA
t_lwldslash_pab.cc
Go to the documentation of this file.
1 
2 
3 #include "chroma.h"
4 
5 using namespace Chroma;
6 
7 
8 int main(int argc, char **argv)
9 {
10  // Put the machine into a known state
11  Chroma::initialize(&argc, &argv);
12 
13  // Read parameters
14  XMLReader xml_in(Chroma::getXMLInputFileName());
15 
16  // Lattice Size
17  multi1d<int> nrow(Nd);
18  read(xml_in, "/param/nrow", nrow);
19 
20  xml_in.close();
21 
22  // Setup the layout
23  Layout::setLattSize(nrow);
24  Layout::create();
25 
26  XMLFileWriter xml(Chroma::getXMLOutputFileName());
27 
28  push(xml,"t_lwldslash_pab");
29 
30  push(xml,"lattis");
31  write(xml,"latt_size",nrow);
32  write(xml,"logical_size",Layout::logicalSize());
33  write(xml,"subgrid_size",Layout::subgridLattSize());
34  pop(xml);
35 
36  // Make up a random gauge field.
37  multi1d<LatticeColorMatrix> u(Nd);
38  for(int m=0; m < u.size(); ++m)
39  gaussian(u[m]);
40 
41 
42  // Make up a gaussian source and a zero result std::vector
43  LatticeFermion psi, chi, chi2;
44  gaussian(psi);
45  chi = zero;
46 
47  //! Create a linear operator
48  QDPIO::cout << "Constructing naive QDPWilsonDslash" << std::endl;
49 
50  Handle< FermState<LatticeFermion,
51  multi1d<LatticeColorMatrix>,
52  multi1d<LatticeColorMatrix> > > state(new PeriodicFermState<LatticeFermion,
53  multi1d<LatticeColorMatrix>,
54  multi1d<LatticeColorMatrix> >(u));
55 
56  // Naive Dslash
58 
59  QDPIO::cout << "Done" << std::endl;
60 
61  StopWatch swatch;
62 
63 
64  int isign, cb, loop, iter=1;
65  bool first = true;
66  for(isign = 1; isign >= -1; isign -= 2) {
67  for(cb = 0; cb < 2; ++cb) {
68 
69  double mydt=0;
70 
71  if (first)
72  {
73  for(iter=1; ; iter <<= 1)
74  {
75  QDPIO::cout << "Applying D " << iter << " times" << std::endl;
76  swatch.reset();
77  swatch.start();
78  for(int i=iter; i-- > 0; ) {
79  D.apply(chi, psi, (isign == 1 ? PLUS : MINUS), cb);
80  }
81  swatch.stop();
82 
83  mydt=swatch.getTimeInSeconds();
84  QDPInternal::globalSum(mydt);
85  mydt /= Layout::numNodes();
86 
87  if (mydt > 1) {
88  first = false;
89  break;
90  }
91  }
92  }
93 
94  QDPIO::cout << "Applying D for timings" << std::endl;
95 
96  swatch.reset();
97  swatch.start();
98  for(int i=iter; i-- > 0; ) {
99  D.apply(chi, psi, (isign == 1 ? PLUS : MINUS), cb);
100  }
101  swatch.stop();
102 
103  mydt=swatch.getTimeInSeconds();
104  QDPInternal::globalSum(mydt);
105  mydt /= Layout::numNodes();
106 
107  mydt=1.0e6*mydt/double(iter*(Layout::sitesOnNode()/2));
108 
109  QDPIO::cout << "cb = " << cb << " isign = " << isign << std::endl;
110  QDPIO::cout << "The time per lattice point is "<< mydt
111  << " micro sec (" << double(1320.0f/mydt) << ") Mflops " << std::endl;
112  }
113  }
114 
115  //! Create a linear operator
116  QDPIO::cout << "Constructing (possibly optimized) WilsonDslash" << std::endl;
117 
118  WilsonDslash D_opt(state);
119 
120  QDPIO::cout << "Done" << std::endl;
121 
122  first = true;
123 
124  for(isign = 1; isign >= -1; isign -= 2) {
125  for(cb = 0; cb < 2; ++cb) {
126 
127  double mydt=0;
128 
129  if (first)
130  {
131  for(iter=1; ; iter <<= 1)
132  {
133  QDPIO::cout << "Applying D " << iter << " times" << std::endl;
134  swatch.reset();
135  swatch.start();
136  for(int i=iter; i-- > 0; ) {
137  D_opt.apply(chi, psi, (isign == 1 ? PLUS : MINUS ) , cb); // NOTE: for timings throw away return value
138  }
139  swatch.stop();
140 
141  mydt=swatch.getTimeInSeconds();
142  QDPInternal::globalSum(mydt);
143  mydt /= Layout::numNodes();
144 
145  if (mydt > 1) {
146  first = false;
147  break;
148  }
149  }
150  }
151 
152  QDPIO::cout << "Applying D for timings" << std::endl;
153 
154  swatch.reset();
155  swatch.start();
156  for(int i=iter; i-- > 0; ) {
157  D_opt.apply(chi, psi, (isign == 1 ? PLUS : MINUS ) , cb); // NOTE: for timings throw away return value
158  }
159  swatch.stop();
160 
161  mydt=swatch.getTimeInSeconds();
162  QDPInternal::globalSum(mydt);
163  mydt /= Layout::numNodes();
164  mydt=1.0e6*mydt/double(iter*(Layout::sitesOnNode()/2));
165 
166  QDPIO::cout << "cb = " << cb << " isign = " << isign << std::endl;
167  QDPIO::cout << "After " << iter << " calls, the time per lattice point is "<< mydt
168  << " micro sec (" << double(1320.0f/mydt) << ") Mflops " << std::endl;
169  }
170  }
171 
172 
173  LatticeFermion chi3;
174  Double n2;
175 
176  gaussian(chi3);
177  gaussian(psi);
178  for(cb = 0; cb < 2; cb++) {
179  for(isign = 1; isign >= -1; isign -= 2) {
180 
181  chi = chi3;
182  chi2 = chi3;
183  D.apply(chi, psi, (isign > 0 ? PLUS : MINUS), cb);
184  D.apply(chi2, psi, (isign > 0 ? PLUS : MINUS), cb);
185 
186  LatticeFermion r;
187  r = chi2 - chi;
188  n2 = norm2( r );
189 
190  QDPIO::cout << "Paranoia test: || D(psi, "
191  << (isign > 0 ? "+, " : "-, ") << cb
192  << ") - D(psi, "
193  << (isign > 0 ? "+, " : "-, ") << cb << " ) || = " << n2
194  << std::endl;
195  }
196  }
197 
198  gaussian(chi3);
199  gaussian(psi);
200  for(cb = 0; cb < 2; cb++) {
201  for(isign = 1; isign >= -1; isign -= 2) {
202 
203  chi = chi3;
204  chi2 = chi3;
205  D.apply(chi, psi, (isign > 0 ? PLUS : MINUS), cb);
206  D_opt.apply(chi2, psi, (isign > 0 ? PLUS : MINUS), cb);
207 
208  LatticeFermion r;
209  r = chi2 - chi;
210  n2 = norm2( r );
211 
212  QDPIO::cout << "OPT test: || D(psi, "
213  << (isign > 0 ? "+, " : "-, ") << cb
214  << ") - D_opt(psi, "
215  << (isign > 0 ? "+, " : "-, ") << cb << " ) || = " << n2
216  << std::endl;
217 
218  QDPIO::cout << std::flush;
219  QDPIO::cout << std::endl << std::flush;
220 
221  push(xml,"OPT test");
222  write(xml,"isign", isign);
223  write(xml,"cb", cb);
224  write(xml,"norm2_diff",n2);
225  pop(xml);
226  }
227  }
228 
229  pop(xml);
230 
231  {
232  WilsonDslash D1;
233  WilsonDslash D2;
234  WilsonDslash D3;
235  }
236 
237 
238  // Time to bolt
240 
241  exit(0);
242 }
Primary include file for CHROMA in application codes.
Support class for fermion actions and linear operators.
Definition: state.h:94
Class for counted reference semantics.
Definition: handle.h:33
Periodic version of FermState.
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:48
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 apply(T &chi, const T &psi, enum PlusMinus isign, int cb) const
General Wilson-Dirac dslash.
Definition: lwldslash_w.h:228
static int m[4]
Definition: make_seeds.cc:16
Nd
Definition: meslate.cc:74
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
std::string getXMLOutputFileName()
Get output file name.
Definition: chroma_init.cc:91
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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)
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
LatticeFermion psi
Definition: mespbg5p_w.cc:35
pop(xml_out)
int cb
Definition: invbicg.cc:120
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
Double zero
Definition: invbicg.cc:106
FloatingPoint< double > Double
Definition: gtest.h:7351
int main(int argc, char **argv)