CHROMA
inline_qpropadd_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline measurement of qpropadd
3  *
4  * Addition of props
5  */
6 
9 
11 
12 namespace Chroma
13 {
14  //! Propagator parameters
15  void read(XMLReader& xml, const std::string& path, InlineQpropAddEnv::Params::NamedObject_t& input)
16  {
17  XMLReader inputtop(xml, path);
18 
19  read(inputtop, "factorA", input.factorA);
20  read(inputtop, "propA", input.propA);
21  read(inputtop, "factorB", input.factorB);
22  read(inputtop, "propB", input.propB);
23  read(inputtop, "propApB", input.propApB);
24  }
25 
26  //! Propagator parameters
27  void write(XMLWriter& xml, const std::string& path, const InlineQpropAddEnv::Params::NamedObject_t& input)
28  {
29  push(xml, path);
30 
31  write(xml, "factorA", input.factorA);
32  write(xml, "propA", input.propA);
33  write(xml, "factorB", input.factorB);
34  write(xml, "propB", input.propB);
35  write(xml, "propApB", input.propApB);
36 
37  pop(xml);
38  }
39 
40 
41  namespace InlineQpropAddEnv
42  {
43  namespace
44  {
45  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
46  const std::string& path)
47  {
48  return new InlineMeas(Params(xml_in, path));
49  }
50 
51  //! Local registration flag
52  bool registered = false;
53  }
54 
55  const std::string name = "QPROPADD";
56 
57  //! Register all the factories
58  bool registerAll()
59  {
60  bool success = true;
61  if (! registered)
62  {
63  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
64  registered = true;
65  }
66  return success;
67  }
68 
69 
70  // Param stuff
72 
73  Params::Params(XMLReader& xml_in, const std::string& path)
74  {
75  try
76  {
77  XMLReader paramtop(xml_in, path);
78 
79  if (paramtop.count("Frequency") == 1)
80  read(paramtop, "Frequency", frequency);
81  else
82  frequency = 1;
83 
84  // Parameters for source construction
85  // Read in the output propagator/source configuration info
86  read(paramtop, "NamedObject", named_obj);
87  }
88  catch(const std::string& e)
89  {
90  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
91  QDP_abort(1);
92  }
93  }
94 
95 
96  void
97  Params::writeXML(XMLWriter& xml_out, const std::string& path)
98  {
99  push(xml_out, path);
100 
101  // Write out the output propagator/source configuration info
102  write(xml_out, "NamedObject", named_obj);
103 
104  pop(xml_out);
105  }
106 
107  //--------------------------------------------------------------
108 
109 
110  // Function call
111  void
112  InlineMeas::operator()(unsigned long update_no,
113  XMLWriter& xml_out)
114  {
115  START_CODE();
116 
117  push(xml_out, "qpropadd");
118  write(xml_out, "update_no", update_no);
119 
120  QDPIO::cout << "QPROPADD: propagator transformation utility" << std::endl;
121 
122  // Write out the input
123  params.writeXML(xml_out, "Input");
124 
125  //
126  // Read in the source along with relevant information.
127  //
128  XMLReader propA_file_xml, propA_record_xml;
129 
130  LatticePropagator propA ;
131  LatticePropagator propB ;
132  LatticePropagator propApB ;
133  QDPIO::cout << "Snarf the props from a named buffer" << std::endl;
134  try
135  {
136  // Try the cast to see if this is a valid source
137  propA = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.propA);
138 
139  TheNamedObjMap::Instance().get(params.named_obj.propA).getFileXML(propA_file_xml);
140  TheNamedObjMap::Instance().get(params.named_obj.propA).getRecordXML(propA_record_xml);
141 
142  propB = TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.propB);
143  }
144  catch (std::bad_cast)
145  {
146  QDPIO::cerr << name << ": caught dynamic cast error"
147  << std::endl;
148  QDP_abort(1);
149  }
150  catch (const std::string& e)
151  {
152  QDPIO::cerr << name << ": error extracting source_header: " << e << std::endl;
153  QDP_abort(1);
154  }
155 
156 
157  // Add the props with weights
158  propApB = params.named_obj.factorA*propA + params.named_obj.factorB*propB;
159 
160 
161  /*
162  * Write the a source out to a named buffer
163  */
164  try
165  {
166  QDPIO::cout << "Attempt to store sequential source" << std::endl;
167 
168 
169  // Store the seqsource
170  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.propApB);
171  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.propApB) = propApB ;
172  TheNamedObjMap::Instance().get(params.named_obj.propApB).setFileXML(propA_file_xml);
173  TheNamedObjMap::Instance().get(params.named_obj.propApB).setRecordXML(propA_record_xml);
174 
175  QDPIO::cout << "Propagator sum successfully stored" << std::endl;
176  }
177  catch (std::bad_cast)
178  {
179  QDPIO::cerr << name << ": dynamic cast error"
180  << std::endl;
181  QDP_abort(1);
182  }
183  catch (const std::string& e)
184  {
185  QDPIO::cerr << name << ": error storing seqsource: " << e << std::endl;
186  QDP_abort(1);
187  }
188 
189 
190  pop(xml_out); // qpropadd
191 
192  QDPIO::cout << "QpropAdd ran successfully" << std::endl;
193 
194  END_CODE();
195  }
196 
197  }
198 
199 }
Inline measurement factory.
Inline measurement of to add two props.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
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.
Inline measurement of qpropadd.
Named object function std::map.
static bool registered
Local registration flag.
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
pop(xml_out)
START_CODE()
::std::string string
Definition: gtest.h:1979
struct Chroma::InlineQpropAddEnv::Params::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)