CHROMA
inline_make_source_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of make_source
3  *
4  * Construct source for propagator calculations
5  */
6 
7 #include "handle.h"
10 #include "meas/glue/mesplq.h"
13 
14 #include "util/ft/sftmom.h"
15 #include "util/info/proginfo.h"
16 #include "util/info/unique_id.h"
18 
20 
21 namespace Chroma
22 {
23  namespace InlineMakeSourceEnv
24  {
25  namespace
26  {
27  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
28  const std::string& path)
29  {
30  return new InlineMakeSource(InlineMakeSourceParams(xml_in, path));
31  }
32 
33  //! Local registration flag
34  bool registered = false;
35  }
36 
37  const std::string name = "MAKE_SOURCE";
38 
39  //! Register all the factories
40  bool registerAll()
41  {
42  bool success = true;
43  if (! registered)
44  {
46  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
47  registered = true;
48  }
49  return success;
50  }
51  }
52 
53 
54  //! MakeSource input
55  void read(XMLReader& xml, const std::string& path, InlineMakeSourceParams::NamedObject_t& input)
56  {
57  XMLReader inputtop(xml, path);
58 
59  read(inputtop, "gauge_id", input.gauge_id);
60  read(inputtop, "source_id", input.source_id);
61  }
62 
63  //! MakeSource output
64  void write(XMLWriter& xml, const std::string& path, const InlineMakeSourceParams::NamedObject_t& input)
65  {
66  push(xml, path);
67 
68  write(xml, "gauge_id", input.gauge_id);
69  write(xml, "source_id", input.source_id);
70 
71  pop(xml);
72  }
73 
74 
75  // Param stuff
77 
79  {
80  try
81  {
82  XMLReader paramtop(xml_in, path);
83 
84  if (paramtop.count("Frequency") == 1)
85  read(paramtop, "Frequency", frequency);
86  else
87  frequency = 1;
88 
89  // Parameters for source construction
90  read(paramtop, "Param", param);
91 
92  // Named object output location
93  read(paramtop, "NamedObject", named_obj);
94 
95  // Possible alternate XML file pattern
96  if (paramtop.count("xml_file") != 0)
97  {
98  read(paramtop, "xml_file", xml_file);
99  }
100  }
101  catch(const std::string& e)
102  {
103  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
104  QDP_abort(1);
105  }
106  }
107 
108 
109  // Writer
110  void
111  InlineMakeSourceParams::write(XMLWriter& xml_out, const std::string& path)
112  {
113  push(xml_out, path);
114 
115  // Parameters for source construction
116  Chroma::write(xml_out, "Param", param);
117 
118  // Write out the buffer ids
119  Chroma::write(xml_out, "NamedObject", named_obj);
120 
121  pop(xml_out);
122  }
123 
124 
125  // Function call
126  void
127  InlineMakeSource::operator()(unsigned long update_no,
128  XMLWriter& xml_out)
129  {
130  // If xml file not empty, then use alternate
131  if (params.xml_file != "")
132  {
133  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
134 
135  push(xml_out, "make_source");
136  write(xml_out, "update_no", update_no);
137  write(xml_out, "xml_file", xml_file);
138  pop(xml_out);
139 
140  XMLFileWriter xml(xml_file);
141  func(update_no, xml);
142  }
143  else
144  {
145  func(update_no, xml_out);
146  }
147  }
148 
149 
150  // Real work done here
151  void
152  InlineMakeSource::func(unsigned long update_no,
153  XMLWriter& xml_out)
154  {
155  START_CODE();
156 
157  QDPIO::cout << InlineMakeSourceEnv::name << ": propagator source constructor" << std::endl;
158 
159  StopWatch snoop;
160  snoop.reset();
161  snoop.start();
162 
163  // Test and grab a reference to the gauge field
164  XMLBufferWriter gauge_xml;
165  multi1d<LatticeColorMatrix> u;
166  try
167  {
168  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
169  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
170  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
171  }
172  catch( std::bad_cast )
173  {
174  QDPIO::cerr << InlineMakeSourceEnv::name << ": caught dynamic cast error"
175  << std::endl;
176  QDP_abort(1);
177  }
178  catch (const std::string& e)
179  {
180  QDPIO::cerr << InlineMakeSourceEnv::name << ": error extracting gauge field: " << e
181  << std::endl;
182  QDP_abort(1);
183  }
184 
185  // Save the initial state of the RNG
186  QDP::Seed ran_seed;
187  QDP::RNG::savern(ran_seed);
188 
189  push(xml_out, "make_source");
190  write(xml_out, "update_no", update_no);
191 
192  proginfo(xml_out); // Print out basic program info
193 
194  // Current state of the seed
195  write(xml_out, "RNG", ran_seed);
196 
197  // Write out the input
198  params.write(xml_out, "Input");
199 
200  // Write out the config header
201  write(xml_out, "Config_info", gauge_xml);
202 
203  // Calculate some gauge invariant observables just for info.
204  MesPlq(xml_out, "Observables", u);
205 
206  //
207  // Initialize source
208  //
209  LatticePropagator quark_source;
210 
211  try
212  {
213  std::istringstream xml_s(params.param.source.xml);
214  XMLReader sourcetop(xml_s);
215  QDPIO::cout << "Source = " << params.param.source.id << std::endl;
216 
218  sourceConstruction(ThePropSourceConstructionFactory::Instance().createObject(params.param.source.id,
219  sourcetop,
221  quark_source = (*sourceConstruction)(u);
222  }
223  catch(const std::string& e)
224  {
225  QDPIO::cerr << InlineMakeSourceEnv::name << ": Caught Exception creating source: " << e << std::endl;
226  QDP_abort(1);
227  }
228 
229 
230  // Sanity check - write out the norm2 of the source in the Nd-1 direction.
231  // Use this for any possible verification.
232  {
233  // Initialize the slow Fourier transform phases
234  SftMom phases(0, true, Nd-1);
235 
236  multi1d<Double> source_corr = sumMulti(localNorm2(quark_source),
237  phases.getSet());
238 
239  push(xml_out, "Source_correlator");
240  write(xml_out, "source_corr", source_corr);
241  pop(xml_out);
242  }
243 
244 
245  // Now write the source
246  try
247  {
248  QDPIO::cout << "Attempt to update source" << std::endl;
249 
250  XMLBufferWriter file_xml;
251  push(file_xml, "make_source");
252  write(file_xml, "id", uniqueId()); // NOTE: new ID form
253  pop(file_xml);
254 
255  XMLBufferWriter record_xml;
256 
257  // Construct the appropriate header
258  {
260  prop_header.source_header = params.param;
261  prop_header.gauge_header = gauge_xml.printCurrentContext();
262  write(record_xml, "MakeSource", prop_header);
263  }
264 
265  // Store the source
266  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.source_id);
267  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.source_id) = quark_source;
268  TheNamedObjMap::Instance().get(params.named_obj.source_id).setFileXML(file_xml);
269  TheNamedObjMap::Instance().get(params.named_obj.source_id).setRecordXML(record_xml);
270 
271  QDPIO::cout << "Source successfully update" << std::endl;
272  }
273  catch (std::bad_cast)
274  {
275  QDPIO::cerr << InlineMakeSourceEnv::name << ": dynamic cast error"
276  << std::endl;
277  QDP_abort(1);
278  }
279  catch (const std::string& e)
280  {
281  QDPIO::cerr << InlineMakeSourceEnv::name << ": error message: " << e << std::endl;
282  QDP_abort(1);
283  }
284 
285  pop(xml_out); // make_source
286 
287 // // Reset the seed
288 // QDP::RNG::setrn(ran_seed);
289 
290  snoop.stop();
291  QDPIO::cout << InlineMakeSourceEnv::name << ": total time = "
292  << snoop.getTimeInSeconds()
293  << " secs" << std::endl;
294 
295  QDPIO::cout << InlineMakeSourceEnv::name << ": ran successfully" << std::endl;
296 
297  END_CODE();
298  }
299 
300 }
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
Inline task creating sources for quark inversion.
InlineMakeSourceParams params
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
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.
std::string uniqueId()
Return a unique id.
Definition: unique_id.cc:18
void proginfo(XMLWriter &xml)
Print out basic information about this program.
Definition: proginfo.cc:24
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
Class for counted reference semantics.
ForwardProp_t prop_header
Inline construction of make_source.
void savern(int iseed[4])
Definition: make_seeds.cc:46
Make xml file writer.
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
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")
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
All make source constructors.
Factory for producing quark prop sources.
struct Chroma::InlineMakeSourceParams::NamedObject_t named_obj
void write(XMLWriter &xml_out, const std::string &path)
Mega structure holding a propagator source.
Definition: qprop_io.h:103
Generate a unique id.