CHROMA
chroma.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Main program to run all measurement codes.
3  */
4 
5 #include "chroma.h"
6 
7 using namespace Chroma;
8 extern "C" {
9  void _mcleanup();
10 }
11 
12 /*
13  * Input
14  */
15 struct Params_t
16 {
17  multi1d<int> nrow;
19 };
20 
22 {
25  QDP::Seed rng_seed;
26 };
27 
28 
29 void read(XMLReader& xml, const std::string& path, Params_t& p)
30 {
31  XMLReader paramtop(xml, path);
32  read(paramtop, "nrow", p.nrow);
33 
34  XMLReader measurements_xml(paramtop, "InlineMeasurements");
35  std::ostringstream inline_os;
36  measurements_xml.print(inline_os);
37  p.inline_measurement_xml = inline_os.str();
38  QDPIO::cout << "InlineMeasurements are: " << std::endl;
39  QDPIO::cout << p.inline_measurement_xml << std::endl;
40 }
41 
42 
43 void read(XMLReader& xml, const std::string& path, Inline_input_t& p)
44 {
45  try {
46  XMLReader paramtop(xml, path);
47 
48  read(paramtop, "Param", p.param);
49  p.cfg = readXMLGroup(paramtop, "Cfg", "cfg_type");
50 
51  if (paramtop.count("RNG") > 0)
52  read(paramtop, "RNG", p.rng_seed);
53  else
54  p.rng_seed = 11; // default seed
55  }
56  catch( const std::string& e )
57  {
58  QDPIO::cerr << "Error reading XML : " << e << std::endl;
59  QDP_abort(1);
60  }
61 }
62 
63 
64 
65 bool linkageHack(void)
66 {
67  bool foo = true;
68 
69  // Inline Measurements
72 
73  return foo;
74 }
75 
76 //! Main program to run all measurement codes
77 /*! \defgroup chromamain Main program to run all measurement codes.
78  * \ingroup main
79  *
80  * Main program to run all measurement codes.
81  */
82 
83 int main(int argc, char *argv[])
84 {
85  // Chroma Init stuff
86  Chroma::initialize(&argc, &argv);
87 
88  START_CODE();
89 
90  QDPIO::cout << "Linkage = " << linkageHack() << std::endl;
91 
92  StopWatch snoop;
93  snoop.reset();
94  snoop.start();
95 
96  XMLReader xml_in;
97 
98  // Input parameter structure
99  Inline_input_t input;
100  try
101  {
102  xml_in.open(Chroma::getXMLInputFileName());
103  read(xml_in, "/chroma", input);
104  }
105  catch(const std::string& e)
106  {
107  QDPIO::cerr << "CHROMA: Caught Exception reading XML: " << e << std::endl;
108  QDP_abort(1);
109  }
110  catch(std::exception& e)
111  {
112  QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << std::endl;
113  QDP_abort(1);
114  }
115  catch(...)
116  {
117  QDPIO::cerr << "CHROMA: caught generic exception reading XML" << std::endl;
118  QDP_abort(1);
119  }
120 
121  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
122  push(xml_out, "chroma");
123 
124  // Write out the input
125  write(xml_out, "Input", xml_in);
126 
127  Layout::setLattSize(input.param.nrow);
128  Layout::create();
129 
130  proginfo(xml_out); // Print out basic program info
131 
132  // Initialise the RNG
133  QDP::RNG::setrn(input.rng_seed);
134  write(xml_out,"RNG", input.rng_seed);
135 
136  // Start up the config
137  StopWatch swatch;
138  swatch.reset();
139  multi1d<LatticeColorMatrix> u(Nd);
140  XMLReader gauge_file_xml, gauge_xml;
141 
142  // Start up the gauge field
143  QDPIO::cout << "CHROMA: Attempt to read gauge field" << std::endl;
144  swatch.start();
145  try
146  {
147  std::istringstream xml_c(input.cfg.xml);
148  XMLReader cfgtop(xml_c);
149  QDPIO::cout << "CHROMA: Gauge initialization: cfg_type = " << input.cfg.id << std::endl;
150 
152  gaugeInit(TheGaugeInitFactory::Instance().createObject(input.cfg.id,
153  cfgtop,
154  input.cfg.path));
155  (*gaugeInit)(gauge_file_xml, gauge_xml, u);
156  }
157  catch(std::bad_cast)
158  {
159  QDPIO::cerr << "CHROMA: caught cast error" << std::endl;
160  QDP_abort(1);
161  }
162  catch(std::bad_alloc)
163  {
164  // This might happen on any node, so report it
165  std::cerr << "CHROMA: caught bad memory allocation" << std::endl;
166  QDP_abort(1);
167  }
168  catch(const std::string& e)
169  {
170  QDPIO::cerr << "CHROMA: Caught Exception: " << e << std::endl;
171  QDP_abort(1);
172  }
173  catch(std::exception& e)
174  {
175  QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << std::endl;
176  QDP_abort(1);
177  }
178  catch(...)
179  {
180  // This might happen on any node, so report it
181  std::cerr << "CHROMA: caught generic exception during gaugeInit" << std::endl;
182  //QDP_abort(1);
183  throw;
184  }
185  swatch.stop();
186 
187  QDPIO::cout << "CHROMA: Gauge field successfully read: time= "
188  << swatch.getTimeInSeconds()
189  << " secs" << std::endl;
190 
191  XMLBufferWriter config_xml;
192  config_xml << gauge_xml;
193 
194  // Write out the config header
195  write(xml_out, "Config_info", gauge_xml);
196 
197  swatch.reset();
198  swatch.start();
199 
200  // Calculate some gauge invariant observables
201  MesPlq(xml_out, "Observables", u);
202  swatch.stop();
203  QDPIO::cout << "CHROMA: initial plaquette measurement time=" << swatch.getTimeInSeconds() << " secs" << std::endl;
204 
205 
206 
207  // Get the measurements
208  try
209  {
210  swatch.reset();
211  swatch.start();
212  std::istringstream Measurements_is(input.param.inline_measurement_xml);
213  XMLReader MeasXML(Measurements_is);
214  multi1d < Handle< AbsInlineMeasurement > > the_measurements;
215  read(MeasXML, "/InlineMeasurements", the_measurements);
216 
217  QDPIO::cout << "CHROMA: There are " << the_measurements.size() << " measurements " << std::endl;
218 
219  // Reset and set the default gauge field
221  InlineDefaultGaugeField::set(u, config_xml);
222 
223  // Measure inline observables
224  push(xml_out, "InlineObservables");
225  xml_out.flush();
226 
227  swatch.stop();
228  QDPIO::cout << "CHROMA: parsing inline measurements time=" << swatch.getTimeInSeconds() << " secs" << std::endl;
229  QDPIO::cout << "CHROMA: Doing " << the_measurements.size()
230  <<" measurements" << std::endl;
231  swatch.reset();
232  swatch.start();
233  unsigned long cur_update = 0;
234  for(int m=0; m < the_measurements.size(); m++)
235  {
236  AbsInlineMeasurement& the_meas = *(the_measurements[m]);
237  if( cur_update % the_meas.getFrequency() == 0 )
238  {
239  // Caller writes elem rule
240  push(xml_out, "elem");
241  the_meas(cur_update, xml_out);
242  pop(xml_out);
243 
244  xml_out.flush();
245  }
246  }
247  swatch.stop();
248 
249  QDPIO::cout << "CHROMA: measurements: time= "
250  << swatch.getTimeInSeconds()
251  << " secs" << std::endl;
252 
253 
254  pop(xml_out); // pop("InlineObservables");
255 
256  // Reset the default gauge field
258  }
259  catch(std::bad_cast)
260  {
261  QDPIO::cerr << "CHROMA: caught cast error" << std::endl;
262  QDP_abort(1);
263  }
264  catch(std::bad_alloc)
265  {
266  // This might happen on any node, so report it
267  std::cerr << "CHROMA: caught bad memory allocation" << std::endl;
268  QDP_abort(1);
269  }
270  catch(const std::string& e)
271  {
272  QDPIO::cerr << "CHROMA: Caught Exception: " << e << std::endl;
273  QDP_abort(1);
274  }
275  catch(const char* e)
276  {
277  QDPIO::cout << "CHROMA: Caught const char * exception: " << e << std::endl;
278  QDP_abort(1);
279  }
280  catch(std::exception& e)
281  {
282  QDPIO::cerr << "CHROMA: Caught standard library exception: " << e.what() << std::endl;
283  QDP_abort(1);
284  }
285  catch(...)
286  {
287  // This might happen on any node, so report it
288  std::cerr << "CHROMA: caught generic exception during measurement" << std::endl;
289  std::cerr << "Rethrowing" << std::endl;
290  throw;
291  }
292  pop(xml_out);
293 
294  snoop.stop();
295  QDPIO::cout << "CHROMA: total time = "
296  << snoop.getTimeInSeconds()
297  << " secs" << std::endl;
298 
299  QDPIO::cout << "CHROMA: ran successfully" << std::endl;
300 
301  END_CODE();
302 
304  exit(0);
305 }
306 
int main(int argc, char *argv[])
Definition: chroma.cc:83
void _mcleanup()
Primary include file for CHROMA in application codes.
virtual unsigned long getFrequency(void) const =0
Tell me how often I should measure this beastie.
Class for counted reference semantics.
Definition: handle.h:33
static T & Instance()
Definition: singleton.h:432
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
void reset()
Reset the default gauge field state.
void set(const multi1d< LatticeColorMatrix > &u, XMLBufferWriter &record_xml)
Set the default gauge field.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
void setrn(int iseed[4])
Definition: make_seeds.cc:38
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.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
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
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
START_CODE()
XMLFileWriter & getXMLOutputInstance()
Get xml output instance.
Definition: chroma_init.cc:359
::std::string string
Definition: gtest.h:1979
Hold group xml and type id.
Params_t param
Definition: chroma.cc:23
GroupXML_t cfg
Definition: chroma.cc:24
QDP::Seed rng_seed
Definition: chroma.cc:25
std::string inline_measurement_xml
Definition: chroma.cc:18
multi1d< int > nrow
Definition: chroma.cc:17