CHROMA
t_precdwf.cc
Go to the documentation of this file.
1 
2 #include <iostream>
3 #include <cstdio>
4 
5 #include <stdlib.h>
6 #include <sys/time.h>
7 
8 #include "chroma.h"
9 
10 using namespace Chroma;
11 
12 typedef multi1d<LatticeFermion> MLF;
13 typedef multi1d<LatticeColorMatrix> LCM;
14 
15 typedef void (EvenOddPrecLinearOperator< MLF, LCM >::* EO_mem)(MLF&, const MLF&, enum PlusMinus) const;
16 
17 enum func { EE, EO, OE, OO, EEI, TOT };
18 
20  MLF& chi, const MLF& psi,
21  enum PlusMinus isign)
22 {
23  clock_t myt1, myt2;
24  double mydt;
25  int iter = 1;
26 
27  for(iter=1; ; iter <<= 1)
28  {
29  QDPIO::cout << "Applying D " << iter << " times" << std::endl;
30 
31  switch ( which ) {
32  case EE:
33  {
34  myt1=clock();
35  for(int i=iter; i-- > 0; ) {
36  p.evenEvenLinOp(chi, psi, isign);
37  }
38  myt2=clock();
39  }
40  break;
41  case EO:
42  {
43  myt1=clock();
44  for(int i=iter; i-- > 0; ) {
45  p.evenOddLinOp(chi, psi, isign);
46  }
47  myt2=clock();
48  }
49  break;
50 
51  case OE:
52  {
53  myt1=clock();
54  for(int i=iter; i-- > 0; ) {
55  p.oddEvenLinOp(chi, psi, isign);
56  }
57  myt2=clock();
58  }
59  break;
60 
61  case OO:
62  {
63  myt1=clock();
64  for(int i=iter; i-- > 0; ) {
65  p.oddOddLinOp(chi, psi, isign);
66  }
67  myt2=clock();
68  }
69  break;
70 
71  case EEI:
72  {
73  myt1=clock();
74  for(int i=iter; i-- > 0; ) {
75  p.evenEvenInvLinOp(chi, psi, isign);
76  }
77  myt2=clock();
78  }
79  break;
80 
81  case TOT:
82  {
83  myt1=clock();
84  for(int i=iter; i-- > 0; ) {
85  p(chi, psi, isign);
86  }
87  myt2=clock();
88  }
89  break;
90 
91  default:
92  break;
93  }
94 
95  mydt=double(myt2-myt1)/double(CLOCKS_PER_SEC);
96  QDPInternal::globalSum(mydt);
97  mydt /= Layout::numNodes();
98 
99  if (mydt > 1)
100  break;
101  }
102 
103  switch ( which ) {
104  case EE:
105  {
106  myt1=clock();
107  for(int i=iter; i-- > 0; ) {
108  p.evenEvenLinOp(chi, psi, isign);
109  }
110  myt2=clock();
111  }
112  break;
113  case EO:
114  {
115  myt1=clock();
116  for(int i=iter; i-- > 0; ) {
117  p.evenOddLinOp(chi, psi, isign);
118  }
119  myt2=clock();
120  }
121  break;
122 
123  case OE:
124  {
125  myt1=clock();
126  for(int i=iter; i-- > 0; ) {
127  p.oddEvenLinOp(chi, psi, isign);
128  }
129  myt2=clock();
130  }
131  break;
132 
133  case OO:
134  {
135  myt1=clock();
136  for(int i=iter; i-- > 0; ) {
137  p.oddOddLinOp(chi, psi, isign);
138  }
139  myt2=clock();
140  }
141  break;
142 
143  case EEI:
144  {
145  myt1=clock();
146  for(int i=iter; i-- > 0; ) {
147  p.evenEvenInvLinOp(chi, psi, isign);
148  }
149  myt2=clock();
150  }
151  break;
152  case TOT:
153  {
154  myt1=clock();
155  for(int i=iter; i-- > 0; ) {
156  p(chi, psi, isign);
157  }
158  myt2=clock();
159  }
160  break;
161 
162  default:
163  break;
164  }
165 
166 
167  mydt = (double)(myt2-myt1)/((double)(CLOCKS_PER_SEC));
168  mydt *= 1.0e6/((double)(iter*(Layout::sitesOnNode()/2)));
169  QDPInternal::globalSum(mydt);
170  mydt /= Layout::numNodes();
171  return mydt;
172 }
173 
174 
175 int main(int argc, char **argv)
176 {
177  // Put the machine into a known state
178  Chroma::initialize(&argc, &argv);
179 
180  // Setup the layout
181  const int foo[] = {8,8,16,8};
182  multi1d<int> nrow(Nd);
183  nrow = foo; // Use only Nd elements
184  Layout::setLattSize(nrow);
185 
186  Layout::create();
187 
188  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
189 
190 
191  //! Test out dslash
192  multi1d<LatticeColorMatrix> u(Nd);
193  QDPIO::cout << "1" << std::endl << std::flush;
194  for(int m=0; m < u.size(); ++m)
195  gaussian(u[m]);
196 
197  QDPIO::cout << "2" << std::endl << std::flush;
198 
199  //! Create a linear operator
200  QDPIO::cout << "Constructing DWDslash" << std::endl;
201 
202  // Create a FermBC with only periodic BC. Note the handle is on an abstract type.
204 
205  // DWDslash class can be optimised
206  int N5 = 26;
207  Real WilsonMass = 1.5;
208  Real m_q = 0.01;
209 
210 #if 1
211  EvenOddPrecDWFermActArray S_pdwf(fbc_a,WilsonMass,m_q,N5);
212 #else
214  params.OverMass = WilsonMass;
215  params.Mass = m_q;
216  params.b5 = 1.0;
217  params.c5 = 0.0;
218  params.N5 = N5;
219  params.approximation_type = COEFF_TYPE_TANH_UNSCALED;
220  params.ApproxMin = 0.0;
221  params.ApproxMax = 0.0;
223 #endif
224 
226  const EvenOddPrecLinearOperator< MLF, LCM >* D_pdwf = S_pdwf.linOp(state);
227 
228  QDPIO::cout << "Done" << std::endl;
229 
230  MLF psi(S_pdwf.size()), chi(S_pdwf.size());
231  psi.moveToFastMemoryHint();
232  chi.moveToFastMemoryHint();
233 
234  for(int n=0; n < S_pdwf.size(); ++n)
235  random(psi[n]);
236  chi = zero;
237 
238  for(int isign = 1; isign >= -1; isign -= 2)
239  {
240  QDPIO::cout << "Applying D" << std::endl;
241  QDPIO::cout << " isign = " << isign << std::endl;
242 
243  PlusMinus is = (isign == 1 ? PLUS : MINUS);
244  clock_t myt1;
245  clock_t myt2;
246  double mydt;
247 
248 // int Ndiag = (N5-2)*(5*24) + 2*(8*24);
249  // int Ndiag = N5*(4*24) + (N5-1)*(8*24) + 3*24; // this is what I get counting flops in code
250  int Ndiag = (4*N5+2)*Nc*Ns; // This is my count with the blas / chiral proj ops
251  int NdiagInv = (10*N5-8)*Nc*Ns;
252  int Neo = N5*(1320+24);
253  int Nflops = 2*Ndiag + 2*Neo + N5*24;
254 
255 
256  // even-even-inv piece
257  mydt = time_func(*D_pdwf, EEI, chi, psi, is);
258  QDPIO::cout << "EvenEvenInv: The time per lattice point is "<< mydt << " micro sec"
259  << " (" << ((double)(NdiagInv)/mydt) << ") Mflops " << std::endl;
260 
261  mydt = time_func(*D_pdwf, EE, chi, psi, is);
262  QDPIO::cout << "EvenEven: The time per lattice point is "<< mydt << " micro sec"
263  << " (" << ((double)(Ndiag)/mydt) << ") Mflops " << std::endl;
264 
265  // odd-odd piece
266  mydt = time_func(*D_pdwf, OO, chi, psi, is);
267  QDPIO::cout << "OddOdd: The time per lattice point is "<< mydt << " micro sec"
268  << " (" << ((double)(Ndiag)/mydt) << ") Mflops " << std::endl;
269 
270 
271  // even-odd
272  mydt = time_func(*D_pdwf, EO, chi, psi, is);
273  QDPIO::cout << "EvenOdd: The time per lattice point is "<< mydt << " micro sec"
274  << " (" << ((double)(Neo)/mydt) << ") Mflops " << std::endl;
275  // odd-even
276  mydt = time_func(*D_pdwf, OE, chi, psi, is);
277  QDPIO::cout << "Odd-Even: The time per lattice point is "<< mydt << " micro sec"
278  << " (" << ((double)(Neo)/mydt) << ") Mflops " << std::endl;
279 
280  // Total thing
281  mydt = time_func(*D_pdwf, TOT, chi, psi, is);
282  QDPIO::cout << "Total: The time per lattice point is "<< mydt << " micro sec"
283  << " (" << ((double)(Nflops)/mydt) << ") Mflops " << std::endl;
284  }
285 
286  {
287  clock_t myt1, myt2;
288  double mydt;
289  int iter = 1;
290  int isign=1;
291 
292  for(iter=1; ; iter <<= 1) {
293  QDPIO::cout << "Applying D " << iter << " times" << std::endl;
294 
295  myt1=clock();
296  for(int i=iter; i-- > 0; )
297  (*D_pdwf)(chi, psi, PLUS);
298  myt2=clock();
299 
300  mydt=double(myt2-myt1)/double(CLOCKS_PER_SEC);
301  QDPInternal::globalSum(mydt);
302  mydt /= Layout::numNodes();
303 
304  if (mydt > 1)
305  break;
306  }
307 
308  StopWatch swatch;
309  FlopCounter flopcount;
310  swatch.reset(); flopcount.reset();
311  swatch.start();
312  for(int i=iter; i-- > 0; ) {
313  (*D_pdwf)(chi, psi, PLUS);
314  }
315  swatch.stop();
316  flopcount.addFlops(D_pdwf->nFlops()*iter);
317 
318  flopcount.report("PrecDWF total", swatch.getTimeInSeconds());
319  }
320 
321  delete D_pdwf;
322 
323  // Time to bolt
325 
326  exit(0);
327 }
Primary include file for CHROMA in application codes.
4D style even-odd preconditioned domain-wall fermion action
int size() const
Length of DW flavor index/space.
virtual EvenOddPrecDWLikeLinOpBaseArray< T, P, Q > * linOp(Handle< FermState< T, P, Q > > state) const
Override to produce a DWF-link even-odd prec. linear operator for this action.
Even-odd preconditioned linear operator.
Definition: eoprec_linop.h:92
virtual unsigned long nFlops() const
Return flops performed by the operator()
Definition: eoprec_linop.h:235
EvenOddPreconditioned NEF fermion action.
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 fermionic actions with trivial boundary conditions.
@ COEFF_TYPE_TANH_UNSCALED
Params params
unsigned n
Definition: ldumul_w.cc:36
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)
static multi1d< LatticeColorMatrix > u
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)
LatticeFermion psi
Definition: mespbg5p_w.cc:35
multi1d< LatticeColorMatrix > LCM
Definition: asqtad_qprop.cc:20
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
Double zero
Definition: invbicg.cc:106
multi1d< LatticeFermion > MLF
Definition: t_preccfz.cc:12
func
Definition: t_preccfz.cc:17
multi1d< LatticeFermion > MLF
Definition: t_precdwf.cc:12
@ OE
Definition: t_precdwf.cc:17
@ OO
Definition: t_precdwf.cc:17
@ TOT
Definition: t_precdwf.cc:17
@ EEI
Definition: t_precdwf.cc:17
@ EO
Definition: t_precdwf.cc:17
@ EE
Definition: t_precdwf.cc:17
int main(int argc, char **argv)
Definition: t_precdwf.cc:175
double time_func(const EvenOddPrecLinearOperator< MLF, LCM > &p, func which, MLF &chi, const MLF &psi, enum PlusMinus isign)
Definition: t_precdwf.cc:19
void(EvenOddPrecLinearOperator< MLF, LCM >::* EO_mem)(MLF &, const MLF &, enum PlusMinus) const
Definition: t_precdwf.cc:15