CHROMA
t_monomial_force.cc
Go to the documentation of this file.
1 
2 #include "chroma.h"
3 #include "chroma_config.h"
4 #include <string>
8 
9 // Specials
11 
12 using namespace Chroma;
13 
14 #ifdef CHROMA_USE_ITTNOTIFY
15 #include "ittnotify.h"
16 #endif
17 
18 //! To insure linking of code, place the registered code flags here
19 /*! This is the bit of code that dictates what fermacts are in use */
20 bool linkageHack(void)
21 {
22  bool foo = true;
23 
24  // Gauge Monomials
26 
27  // Ferm Monomials
29 
30  // MD Integrators
32 
33  // Chrono predictor
35 
36  // Inline Measurements
38 
39  return foo;
40 }
41 
42 int main(int argc, char *argv[])
43 {
44  Chroma::initialize(&argc, &argv);
45 
46  START_CODE();
47 
48  // Chroma Init stuff -- Open DATA and XMLDAT
49  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
50 
51  // Snarf it all
52  XMLReader param_in(Chroma::getXMLInputFileName());
53  XMLReader paramtop(param_in, "/MonomialTests");
54 
55  multi1d<int> nrow(Nd);
56 
57  try {
58  read(paramtop, "nrow", nrow);
59  }
60  catch(const std::string& e) {
61  QDPIO::cerr << "Unable to read nrow from XML: " << e << std::endl;
62  QDP_abort(1);
63  }
64 
65  Layout::setLattSize(nrow);
66  Layout::create();
67 
68  QDPIO::cout << " HELLLOOOO!!!!!!!!" << std::endl;
69  // Dump output
70  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
71  XMLFileWriter& xml_log = Chroma::getXMLLogInstance();
72  push(xml_out, "MonomialTimings");
73  push(xml_log, "MonomialTimings");
74 
75  // Read Parameters
76  multi1d<int> boundary(Nd); // Ferm BC's
77  std::string monomial_name; // String for Factory
78 
79 
80  Cfg_t cfg;
81  try {
82  read(paramtop, "./GaugeStartup", cfg);
83  }
84  catch( const std::string& e ) {
85  QDPIO::cerr << " Error reading XML " << e << std::endl;
86  QDP_abort(1);
87  }
88 
89  multi1d<LatticeColorMatrix> u(Nd);
90  {
91  XMLReader file_xml;
92  XMLReader config_xml;
93 
94  gaugeStartup(file_xml, config_xml, u, cfg);
95  }
96 
97  // Try and create an array of monomials:
98  try {
99  readNamedMonomialArray(paramtop, "./Monomials");
100  }
101  catch(const std::string& e) {
102  QDPIO::cout << "Failed to read monomials " << std::endl;
103  QDP_abort(1);
104  }
105  QDPIO::cout << "ALL MONOMIALS READ " << std::endl << std::flush;
106 
107  // Read the list of monomials to test.
108  multi1d<std::string> monomial_test_ids;
109  multi1d<int> n_iters;
110  try {
111  read(paramtop, "//MonomialTestIds", monomial_test_ids);
112  }
113  catch( ... ) {
114  QDPIO::cout << "Caught exception: reading monomial_test_ids" <<std::endl;
115  QDP_abort(1);
116  }
117 
118  QDPIO::cout << "MONOMIAL TEST IDS READ " << std::endl << std::flush;
119 
120  try {
121  read(paramtop, "//n_iters", n_iters);
122  }
123  catch( const std::string e) {
124  QDPIO::cout << "Couldnt read n_iters. Caught exception: "<< e << std::endl;
125  QDP_abort(1);
126  }
127 
128  QDPIO::cout << "ALL parameters read " << std::endl;
129  if ( n_iters.size() != monomial_test_ids.size()) {
130  if( n_iters.size() == 1 ) {
131  QDPIO::cout << "Using same value of n_iters for all monomials" << std::endl;
132  int n_iters_val = n_iters[0];
133  n_iters.resize( monomial_test_ids.size());
134  for(int i=0; i < monomial_test_ids.size(); ++i) {
135  n_iters[i]=n_iters_val;
136  }
137  }
138  else {
139  QDPIO::cout <<" There are " << monomial_test_ids.size()
140  <<" monomials but " << n_iters.size()
141  <<" values for n_iters" << std::endl;
142  QDP_abort(1);
143  }
144  }
145 
146  QDPIO::cout << "STARTING MOMENTA " << std::endl << std::flush ;
147  // Fictitious momenta for now
148  multi1d<LatticeColorMatrix> p(Nd);
149 
150  // Get some noise into the momenta...
151  for(int mu=0; mu<Nd; mu++) {
152  gaussian(p[mu]);
153  p[mu] *= sqrt(0.5);
154  taproj(p[mu]);
155  }
156 
157  QDPIO::cout << "create state" << std::endl;
158 
159  // Create a field state
160  GaugeFieldState gauge_state(p,u);
161 
162  QDPIO::cout << "There are " << monomial_test_ids.size() << " monomials to test" << std::endl;
163  typedef multi1d<LatticeColorMatrix> P;
164  typedef multi1d<LatticeColorMatrix> Q;
165  QDPIO::cout << "Binding Monomials" << std::endl;
166 
167  multi1d< Chroma::IntegratorShared::MonomialPair > mon_pairs(monomial_test_ids.size());
168  try {
169  Chroma::IntegratorShared::bindMonomials( monomial_test_ids, mon_pairs );
170  }
171  catch( const std::string& err ) {
172  QDPIO::cout << "Caught exception string:" << err << std::endl;
173  }
174  StopWatch swatch;
175  double seconds;
176  P F;
177 
178  for( int m = 0; m < monomial_test_ids.size(); m++) {
179  // Get a monomial
180  Monomial<P,Q>& the_mon = *( mon_pairs[m].mon );
181  std::string& mon_name = mon_pairs[m].id;
182  QDPIO::cout << "Timing monomial force: " << mon_name << std::endl;
183  QDPIO::cout << "Refreshing internal fields: " << std::endl;
184 
185  the_mon.refreshInternalFields(gauge_state);
186 
187  QDPIO::cout << "Single Application in case one is JIT-ing" << std::endl;
188  {
189 
190  swatch.reset();
191  swatch.start();
192 
193  the_mon.dsdq(F,gauge_state);
194 
195  swatch.stop();
196  seconds = swatch.getTimeInSeconds();
197  QDPInternal::globalSum(seconds);
198  seconds /= (double)Layout::numNodes();
199  QDPIO::cout << "First application took: " << seconds <<" (s) "<< std::endl << std::flush;
200  }
201 
202  {
203  int hits = n_iters[m];
204  QDPIO::cout << "Timing monomial force: " << mon_name << " with " << hits << " hits " << std::endl;
205  swatch.reset();
206  swatch.start();
207 #ifdef CHROMA_USE_ITTNOTIFY
208  __itt_resume();
209 #endif
210  for(int i=0; i < hits; i++) {
211  the_mon.dsdq(F,gauge_state);
212  }
213 #ifdef CHROMA_USE_ITTNOTIFY
214  __itt_pause();
215 #endif
216  swatch.stop();
217  seconds = swatch.getTimeInSeconds();
218  QDPInternal::globalSum(seconds);
219  seconds /= (double)Layout::numNodes();
220 
221  QDPIO::cout << "monomial_id = " << mon_name
222  << ", Nhits = " << hits
223  << ", Time = " << seconds << "(s)"
224  << ", Time per hit = " << seconds/(double)hits << "(s)"<< std::endl;
225 
226  push(xml_out, "ForceTiming");
227  write(xml_out, "monomial_id", mon_name);
228  write(xml_out, "nhits", hits);
229  write(xml_out, "time", seconds);
230  write(xml_out, "time_per_hit", (seconds/(double)hits));
231  pop(xml_out);
232  }
233  }
234 #if 0
235  // Time taproj
236  seconds = 0;
237  hits = 1;
238  QDPIO::cout << "Timing taproj()" << std::endl;
239  QDPIO::cout << "Calibrating";
240  while( seconds < 10 ) {
241  hits *= 2;
242  swatch.reset();
243  swatch.start();
244  for(int i=0; i < hits; i++) {
245  for(int mu=0; mu < Nd; mu++) {
246  taproj(gauge_state.getP()[mu]);
247  }
248  }
249  swatch.stop();
250  seconds = swatch.getTimeInSeconds();
251  QDPInternal::globalSum(seconds);
252  seconds /= (double)Layout::numNodes();
253  QDPIO::cout << "." << std::flush;
254  }
255 
256  QDPIO::cout << " " << seconds << "(s)"<< std::endl;
257 
258 
259  QDPIO::cout << "Timing taproj with " << hits << " hits " << std::endl;
260  swatch.reset();
261  swatch.start();
262  for(int i=0; i < hits; i++) {
263  for(int mu=0; mu < Nd; mu++) {
264  taproj(gauge_state.getP()[mu]);
265  }
266  }
267  swatch.stop();
268  seconds = swatch.getTimeInSeconds();
269  QDPInternal::globalSum(seconds);
270  seconds /= (double)Layout::numNodes();
271 
272  QDPIO::cout << "taproj"
273  << ", Nhits = " << hits
274  << ", Time = " << seconds << "(s)"
275  << ", Time per hit = " << seconds/(double)hits << "(s)" << std::endl;
276 
277  push(xml_out, "TaprojTiming");
278  write(xml_out, "nhits", hits);
279  write(xml_out, "time", seconds);
280  write(xml_out, "time_per_hit", (seconds/(double)hits));
281  pop(xml_out);
282 
283  // Time expmat
284  seconds = 0;
285  hits = 1;
286  QDPIO::cout << "Timing expmat()" << std::endl;
287  QDPIO::cout << "Calibrating";
288 
289  while( seconds < 10 ) {
290  hits *= 2;
291  swatch.reset();
292  swatch.start();
293  for(int i=0; i < hits; i++) {
294  for(int mu=0; mu < Nd; mu++) {
295  expmat(gauge_state.getP()[mu], EXP_EXACT);
296  }
297  }
298  swatch.stop();
299  seconds = swatch.getTimeInSeconds();
300  QDPInternal::globalSum(seconds);
301  seconds /= (double)Layout::numNodes();
302 
303  QDPIO::cout << "." << std::flush;
304  }
305  QDPIO::cout << " " << seconds << "(s)"<< std::endl;
306 
307  QDPIO::cout << "Timing expmat with " << hits << " hits " << std::endl;
308  swatch.reset();
309  swatch.start();
310  for(int i=0; i < hits; i++) {
311  for(int mu=0; mu < Nd; mu++) {
312  expmat(gauge_state.getP()[mu], EXP_EXACT);
313  }
314  }
315  swatch.stop();
316  seconds = swatch.getTimeInSeconds();
317  QDPInternal::globalSum(seconds);
318  seconds /= (double)Layout::numNodes();
319 
320  QDPIO::cout << "expmat"
321  << ", Nhits = " << hits
322  << ", Time = " << seconds << "(s)"
323  << ", Time per hit = " << seconds/(double)hits << "(s)" << std::endl;
324 
325  push(xml_out, "ExpmatTiming");
326  write(xml_out, "nhits", hits);
327  write(xml_out, "time", seconds);
328  write(xml_out, "time_per_hit", (seconds/(double)hits));
329  pop(xml_out);
330 
331  // Time reunit
332  seconds = 0;
333  hits = 1;
334  int numbad;
335  QDPIO::cout << "Timing reunit()" << std::endl;
336  QDPIO::cout << "Calibrating";
337 
338  while( seconds < 10 ) {
339  hits *= 2;
340  swatch.reset();
341  swatch.start();
342  for(int i=0; i < hits; i++) {
343  for(int mu=0; mu < Nd; mu++) {
344  reunit((gauge_state.getQ())[mu], numbad, REUNITARIZE_ERROR);
345  }
346  }
347  swatch.stop();
348  seconds = swatch.getTimeInSeconds();
349  QDPInternal::globalSum(seconds);
350  seconds /= (double)Layout::numNodes();
351 
352  QDPIO::cout << "." << std::flush;
353  }
354  QDPIO::cout << " " << seconds << "(s)"<< std::endl;
355 
356  QDPIO::cout << "Timing reunit with " << hits << " hits " << std::endl;
357  swatch.reset();
358  swatch.start();
359  for(int i=0; i < hits; i++) {
360  for(int mu=0; mu < Nd; mu++) {
361  reunit((gauge_state.getQ())[mu], numbad, REUNITARIZE_ERROR);
362  }
363  }
364  swatch.stop();
365  seconds = swatch.getTimeInSeconds();
366  QDPInternal::globalSum(seconds);
367  seconds /= (double)Layout::numNodes();
368 
369  QDPIO::cout << "reunit"
370  << ", Nhits = " << hits
371  << ", Time = " << seconds << "(s)"
372  << ", Time per hit = " << seconds/(double)hits << "(s)" << std::endl;
373 
374  push(xml_out, "ReunitTiming");
375  write(xml_out, "nhits", hits);
376  write(xml_out, "time", seconds);
377  write(xml_out, "time_per_hit", (seconds/(double)hits));
378  pop(xml_out);
379 
380 #endif
381 
382  pop(xml_log); // t_leapfrog
383  pop(xml_out); // t_leapfrog
384 
385  END_CODE();
386 
387  // Finish
389  exit(0);
390  }
Primary include file for CHROMA in application codes.
Pure gauge field state.
Definition: field_state.h:83
const multi1d< LatticeColorMatrix > & getP(void) const
Accessors.
Definition: field_state.h:117
const multi1d< LatticeColorMatrix > & getQ(void) const
Definition: field_state.h:118
An abstract monomial class, for inexact algorithms.
Definition: abs_monomial.h:43
virtual void dsdq(P &F, const AbsFieldState< P, Q > &s)=0
Compute dsdq for the system...
virtual void refreshInternalFields(const AbsFieldState< P, Q > &field_state)=0
Refresh pseudofermion fields if any.
int numbad
Definition: cool.cc:28
int mu
Definition: cool.cc:24
Exact Hamiltonians.
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 taproj(LatticeColorMatrix &a)
Take the traceless antihermitian projection of a color matrix.
Definition: taproj.cc:31
void expmat(LatticeColorMatrix &a, enum ExpMat_t opt)
Exponentiate a SU(n) lie algebra element by some method.
Definition: expmat.cc:39
void gaugeStartup(XMLReader &gauge_file_xml, XMLReader &gauge_xml, multi1d< LatticeColorMatrix > &u, Cfg_t &cfg)
Initialize the gauge fields.
void readNamedMonomialArray(XMLReader &xml, const std::string &path)
Read an array of named monomials from an XML reader. use factory to create the monomials and put them...
Definition: monomial_io.cc:106
static int m[4]
Definition: make_seeds.cc:16
Nd
Definition: meslate.cc:74
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
bool registerAll()
Register all the factories.
multi1d< LatticeColorMatrix > P
void bindMonomials(const multi1d< std::string > &monomial_ids, multi1d< MonomialPair > &monomials)
A routine to bind Monomial IDs to an array of Monomial Handles.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
gaussian(aux)
XMLFileWriter & getXMLLogInstance()
Get xml log instance.
Definition: chroma_init.cc:378
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
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
void finalize(void)
Chroma finalization routine.
Definition: chroma_init.cc:308
bool linkageHack(void)
Definition: const_hmc.cc:660
void reunit(LatticeColorMatrixF3 &xa)
Definition: reunit.cc:467
@ REUNITARIZE_ERROR
Definition: reunit.h:29
std::string getXMLInputFileName()
Get input file name.
Definition: chroma_init.cc:88
pop(xml_out)
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
@ EXP_EXACT
Definition: expmat.h:11
::std::string string
Definition: gtest.h:1979
Rectangle gauge action.
Gauge configuration structure.
Definition: cfgtype_io.h:16
multi1d< LatticeColorMatrix > P
Definition: t_clover.cc:13
int main(int argc, char *argv[])
static INTERNAL_PRECISION F