CHROMA
inline_qprop_matmul_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline construction of QpropMatMul
3  *
4  * QpropMatMul calculations
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
11 #include "util/ft/sftmom.h"
12 #include "util/info/proginfo.h"
13 #include "util/info/unique_id.h"
17 
19 #include "util/ferm/transf.h"
20 
21 namespace Chroma
22 {
23  namespace InlineQpropMatMulEnv
24  {
25  namespace
26  {
27  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
28  const std::string& path)
29  {
30  return new InlineQpropMatMul(InlineQpropMatMulParams(xml_in, path));
31  }
32 
33  //! Local registration flag
34  bool registered = false;
35  }
36 
37  const std::string name = "QPROP_MAT_MUL_4D";
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  } // end namespace
52 
53 
54  //! QpropMatMul input
55  void read(XMLReader& xml, const std::string& path, InlineQpropMatMulParams::NamedObject_t& input)
56  {
57  XMLReader inputtop(xml, path);
58 
59  read(inputtop, "gauge_id", input.gauge_id);
60  read(inputtop, "header_id", input.header_id);
61  read(inputtop, "source_id", input.source_id);
62  read(inputtop, "result_id", input.result_id);
63  }
64 
65  //! QpropMatMul output
66  void write(XMLWriter& xml, const std::string& path, const InlineQpropMatMulParams::NamedObject_t& input)
67  {
68  push(xml, path);
69 
70  write(xml, "gauge_id", input.gauge_id);
71  write(xml, "header_id", input.header_id);
72  write(xml, "source_id", input.source_id);
73  write(xml, "result_id", input.result_id);
74 
75  pop(xml);
76  }
77 
78 
79  // Param stuff
81 
83  {
84  try
85  {
86  XMLReader paramtop(xml_in, path);
87 
88  if (paramtop.count("Frequency") == 1)
89  read(paramtop, "Frequency", frequency);
90  else
91  frequency = 1;
92 
93  // Parameters for source construction
94  fermact = readXMLGroup(paramtop, "FermionAction", "FermAct");
95  // Read in the output QpropMatMul/source configuration info
96  read(paramtop, "NamedObject", named_obj);
97 
98  // Possible alternate XML file pattern
99  if (paramtop.count("xml_file") != 0)
100  {
101  read(paramtop, "xml_file", xml_file);
102  }
103  }
104  catch(const std::string& e)
105  {
106  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
107  QDP_abort(1);
108  }
109  }
110 
111 
112  void
113  InlineQpropMatMulParams::writeXML(XMLWriter& xml_out, const std::string& path)
114  {
115  push(xml_out, path);
116 
117  push(xml_out, "FermionAction");
118  xml_out << fermact.xml;
119  pop(xml_out);
120  write(xml_out, "NamedObject", named_obj);
121 
122  pop(xml_out);
123  }
124 
125 
126  // Function call
127  void
128  InlineQpropMatMul::operator()(unsigned long update_no,
129  XMLWriter& xml_out)
130  {
131 
132  func(update_no, xml_out);
133  }
134 
135 
136  // Real work done here
137  void
138  InlineQpropMatMul::func(unsigned long update_no,
139  XMLWriter& xml_out)
140  {
141  START_CODE();
142 
143  QDPIO::cout << InlineQpropMatMulEnv::name << ": QpropMatMul calculation" << std::endl;
144 
145  StopWatch snoop;
146  snoop.reset();
147  snoop.start();
148 
149  // Test and grab a reference to the gauge field
150  XMLBufferWriter gauge_xml;
151  try
152  {
153  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
154  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
155  }
156  catch( std::bad_cast )
157  {
158  QDPIO::cerr << InlineQpropMatMulEnv::name << ": caught dynamic cast error"
159  << std::endl;
160  QDP_abort(1);
161  }
162  catch (const std::string& e)
163  {
164  QDPIO::cerr << InlineQpropMatMulEnv::name << ": std::map call failed: " << e
165  << std::endl;
166  QDP_abort(1);
167  }
168  const multi1d<LatticeColorMatrix>& u =
169  TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
170 
171  push(xml_out, "QpropMatMul");
172  write(xml_out, "update_no", update_no);
173 
174  //
175  // Read in the source along with relevant information.
176  //
177  XMLReader source_file_xml, source_record_xml;
178 
179 
180  QDPIO::cout << "Snarf the source from a named buffer" << std::endl;
181  try
182  {
183  QDPIO::cout << "Getting prop from named obj:"<< params.named_obj.source_id << std::endl;
184  // Try the cast to see if this is a valid source
185  LatticePropagator& source_tmp =
186  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.source_id);
187 
188  QDPIO::cout << "Getting headers from named obj:" << params.named_obj.header_id << std::endl;
189  // Snarf the source info. This is will throw if the source_id is not there
190  TheNamedObjMap::Instance().get(params.named_obj.header_id).getFileXML(source_file_xml);
191  TheNamedObjMap::Instance().get(params.named_obj.header_id).getRecordXML(source_record_xml);
192 
193  // Write out the source header
194  write(xml_out, "Source_file_info", source_file_xml);
195  write(xml_out, "Source_record_info", source_record_xml);
196  }
197  catch (std::bad_cast)
198  {
199  QDPIO::cerr << InlineQpropMatMulEnv::name << ": caught dynamic cast error"
200  << std::endl;
201  QDP_abort(1);
202  }
203  catch (const std::string& e)
204  {
205  QDPIO::cerr << InlineQpropMatMulEnv::name << ": error extracting source_header: " << e << std::endl;
206  QDP_abort(1);
207  }
208 
209  // Should be a valid cast now
210  const LatticePropagator& quark_prop_source =
211  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.source_id);
212 
213  QDPIO::cout << "Source successfully read and parsed" << std::endl;
214 
215 
216  //
217  // Loop over the source color and spin, creating the source
218  // and calling the relevant QpropMatMul routines. The QDP
219  // terminology is that a QpropMatMul is a matrix in color
220  // and spin space
221  //
222  try
223  {
224  TheNamedObjMap::Instance().create<LatticePropagator>(params.named_obj.result_id);
225  }
226  catch (std::bad_cast)
227  {
228  QDPIO::cerr << InlineQpropMatMulEnv::name << ": caught dynamic cast error"
229  << std::endl;
230  QDP_abort(1);
231  }
232  catch (const std::string& e)
233  {
234  QDPIO::cerr << InlineQpropMatMulEnv::name << ": error creating prop: " << e << std::endl;
235  QDP_abort(1);
236  }
237 
238  // Cast should be valid now
239  LatticePropagator& quark_propagator =
240  TheNamedObjMap::Instance().getData<LatticePropagator>(params.named_obj.result_id);
241 
242  //
243  // Initialize fermion action
244  //
245  std::istringstream xml_s(params.fermact.xml);
246  XMLReader fermacttop(xml_s);
247  QDPIO::cout << "FermAct = " << params.fermact.id << std::endl;
248 
249  try {
250  StopWatch swatch;
251  swatch.reset();
252 
253  // Typedefs to save typing
254  typedef LatticeFermion T;
255  typedef multi1d<LatticeColorMatrix> P;
256  typedef multi1d<LatticeColorMatrix> Q;
257 
258  // Generic Wilson-Type stuff
259 
260 
261  Handle<FermAct4D<T,P,Q> > S4(nullptr);
262  try {
263  S4=dynamic_cast<FermAct4D<T,P,Q>*>(TheFermionActionFactory::Instance().createObject(params.fermact.id,
264  fermacttop,
265  params.fermact.path));
266  }
267  catch(...) {
268  QDPIO::cout << "Cast to 4D fermact failed" << std::endl;
269  QDP_abort(1);
270  }
271  QDPIO::cout << "Creating Ferm State" << std::endl;
272  Handle< FermState<T,P,Q> > state(S4->createState(u));
273 
274  QDPIO::cout << "Creating Linear Operator" <<std::endl;
275 
276 
277  Handle< LinearOperator<T> > M = S4->linOp(state);
278 
279  for(int spin=0; spin < Ns; ++spin ) {
280  for(int color=0; color < Nc; ++color ) {
281  QDPIO::cout << "color= " <<color <<" spin="<<spin<< "... ";
282  LatticeFermion src, res;
283  QDPIO::cout <<" extracting component...";
284  PropToFerm(quark_prop_source, src, color, spin);
285  QDPIO::cout <<" applying linop ... ";
286  (*M)(res,src,PLUS);
287  QDPIO::cout << " storing";
288  FermToProp(res,quark_propagator, color,spin);
289  QDPIO::cout << std::endl;
290 
291  }
292  }
293 
294 
295  // Write the QpropMatMul xml info
296  TheNamedObjMap::Instance().get(params.named_obj.result_id).setFileXML(source_file_xml);
297  TheNamedObjMap::Instance().get(params.named_obj.result_id).setRecordXML(source_record_xml);
298 
299  QDPIO::cout << "QpropMatMul successfully updated" << std::endl;
300  }
301  catch (std::bad_cast)
302  {
303  QDPIO::cerr << InlineQpropMatMulEnv::name << ": caught dynamic cast error"
304  << std::endl;
305  QDP_abort(1);
306  }
307  catch (const std::string& e)
308  {
309  QDPIO::cerr << InlineQpropMatMulEnv::name << ": error extracting prop_header: " << e << std::endl;
310  QDP_abort(1);
311  }
312 
313  pop(xml_out); // QpropMatMul
314 
315  snoop.stop();
316  QDPIO::cout << InlineQpropMatMulEnv::name << ": total time = "
317  << snoop.getTimeInSeconds()
318  << " secs" << std::endl;
319 
320  QDPIO::cout << InlineQpropMatMulEnv::name << ": ran successfully" << std::endl;
321 
322  END_CODE();
323  }
324 
325 }
326 
Inline measurement factory.
Base class for quadratic matter actions (e.g., fermions)
Definition: fermact.h:176
Class for counted reference semantics.
Definition: handle.h:33
Inline QpropMatMul calculation.
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.
InlineQpropMatMulParams params
static T & Instance()
Definition: singleton.h:432
Class structure for fermion actions.
Fermion action factories.
All Wilson-type fermion actions.
void PropToFerm(const LatticePropagatorF &b, LatticeFermionF &a, int color_index, int spin_index)
Extract a LatticeFermion from a LatticePropagator.
Definition: transf.cc:226
void FermToProp(const LatticeFermionF &a, LatticePropagatorF &b, int color_index, int spin_index)
Insert a LatticeFermion into a LatticePropagator.
Definition: transf.cc:98
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Inline construction of QpropMatMul.
Make xml file writer.
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
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
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
@ PLUS
Definition: chromabase.h:45
pop(xml_out)
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
::std::string string
Definition: gtest.h:1979
Print out basic info about this program.
Fourier transform phase factor support.
struct Chroma::InlineQpropMatMulParams::NamedObject_t named_obj
void writeXML(XMLWriter &xml_out, const std::string &path)
Generate a unique id.