CHROMA
qpropadd.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Add two quark propagators
3  *
4  * Simple program for adding two quark props
5  */
6 
7 #include "chroma.h"
8 
9 using namespace Chroma;
10 
11 
12 /*
13  * Input
14  */
15 //! Parameters for running program
16 struct Param_t
17 {
18  multi1d<int> nrow;
19 };
20 
21 //! Propagators
22 struct Prop_t
23 {
24  std::string prop_file1; // The files is expected to be in SciDAC format!
25  std::string prop_file2; // The files is expected to be in SciDAC format!
26 
27  std::string prop_file; // The files is expected to be in SciDAC format!
28  QDP_volfmt_t prop_volfmt;
29 };
30 
31 
32 //! Mega-structure of all input
34 {
37 };
38 
39 
40 //! Propagator parameters
41 void read(XMLReader& xml, const std::string& path, Prop_t& input)
42 {
43  XMLReader inputtop(xml, path);
44 
45  read(inputtop, "prop_file1", input.prop_file1);
46  read(inputtop, "prop_file2", input.prop_file2);
47  read(inputtop, "prop_file", input.prop_file);
48  read(inputtop, "prop_volfmt", input.prop_volfmt); // singlefile or multifile
49 }
50 
51 
52 // Reader for input parameters
53 void read(XMLReader& xml, const std::string& path, Param_t& param)
54 {
55  XMLReader paramtop(xml, path);
56 
57  int version;
58  read(paramtop, "version", version);
59 
60  switch (version)
61  {
62  case 1:
63  /**************************************************************************/
64  break;
65 
66  default :
67  /**************************************************************************/
68 
69  QDPIO::cerr << "Input parameter version " << version << " unsupported." << std::endl;
70  QDP_abort(1);
71  }
72 
73  read(paramtop, "nrow", param.nrow);
74 }
75 
76 
77 // Reader for input parameters
78 void read(XMLReader& xml, const std::string& path, Qpropadd_input_t& input)
79 {
80  XMLReader inputtop(xml, path);
81 
82  // Read all the input groups
83  try
84  {
85  // Read program parameters
86  read(inputtop, "Param", input.param);
87 
88  // Read in the propagator(s) info
89  read(inputtop, "Prop", input.prop);
90  }
91  catch (const std::string& e)
92  {
93  QDPIO::cerr << "Error reading qpropadd data: " << e << std::endl;
94  throw;
95  }
96 }
97 
98 //--------------------------------------------------------------
99 
100 
101 
102 
103 //! Add two propagators
104 /*! \defgroup qpropadd Add two propagators
105  * \ingroup main
106  *
107  * Main program for adding propagators
108  */
109 
110 int main(int argc, char *argv[])
111 {
112  // Put the machine into a known state
113  Chroma::initialize(&argc, &argv);
114 
115  START_CODE();
116 
117  // Input parameter structure
118  Qpropadd_input_t input;
119 
120  // Instantiate xml reader for DATA
121  XMLReader xml_in(Chroma::getXMLInputFileName());
122 
123  // Read data
124  read(xml_in, "/qpropadd", input);
125 
126  // Specify lattice size, shape, etc.
127  Layout::setLattSize(input.param.nrow);
128  Layout::create();
129 
130  QDPIO::cout << " QPROPADD: Add 2 propagators" << std::endl;
131 
132  // Instantiate XML writer for XMLDAT
133  // XMLFileWriter xml_out(Chroma::getXMLOutputFileName());
134  XMLFileWriter& xml_out = Chroma::getXMLOutputInstance();
135  push(xml_out, "qpropadd");
136 
137  proginfo(xml_out); // Print out basic program info
138 
139  // Write out the input
140  write(xml_out, "Input", xml_in);
141 
142  push(xml_out, "Output_version");
143  write(xml_out, "out_version", 1);
144  pop(xml_out);
145 
146  xml_out.flush();
147 
148  //
149  // Read the first quark propagator and extract headers
150  //
151  XMLReader prop_file_xml1, prop_record_xml1;
152  LatticePropagator quark_propagator1;
153  ChromaProp_t prop_header1;
154  PropSourceConst_t source_header1;
155  {
156  QDPIO::cout << "Attempt to read first forward propagator" << std::endl;
157  readQprop(prop_file_xml1,
158  prop_record_xml1, quark_propagator1,
159  input.prop.prop_file1, QDPIO_SERIAL);
160 
161  // Try to invert this record XML into a ChromaProp struct
162  // Also pull out the id of this source
163  try
164  {
165  read(prop_record_xml1, "/Propagator/ForwardProp", prop_header1);
166  read(prop_record_xml1, "/Propagator/PropSource", source_header1);
167  }
168  catch (const std::string& e)
169  {
170  QDPIO::cerr << "Error extracting forward_prop header: " << e << std::endl;
171  throw;
172  }
173  }
174  QDPIO::cout << "First forward propagator successfully read\n" << std::endl;
175 
176 
177  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
178  // Use this for any possible verification
179  {
180  // Initialize the slow Fourier transform phases
181  SftMom phases(0, true, source_header1.j_decay);
182 
183  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator1),
184  phases.getSet());
185 
186  push(xml_out, "Forward_prop_correlator1");
187  write(xml_out, "forward_prop_corr", forward_prop_corr);
188  pop(xml_out);
189  }
190 
191  // Save prop input
192  push(xml_out, "Propagator1");
193  write(xml_out, "ForwardProp", prop_header1);
194  write(xml_out, "PropSource", source_header1);
195  pop(xml_out);
196 
197 
198  //
199  // Read the second quark propagator and extract headers
200  //
201  XMLReader prop_file_xml2, prop_record_xml2;
202  LatticePropagator quark_propagator2;
203  ChromaProp_t prop_header2;
204  PropSourceConst_t source_header2;
205  {
206  QDPIO::cout << "Attempt to read second forward propagator" << std::endl;
207  readQprop(prop_file_xml2,
208  prop_record_xml2, quark_propagator2,
209  input.prop.prop_file2, QDPIO_SERIAL);
210 
211  // Try to invert this record XML into a ChromaProp struct
212  // Also pull out the id of this source
213  try
214  {
215  read(prop_record_xml2, "/Propagator/ForwardProp", prop_header2);
216  read(prop_record_xml2, "/Propagator/PropSource", source_header2);
217  }
218  catch (const std::string& e)
219  {
220  QDPIO::cerr << "Error extracting forward_prop header: " << e << std::endl;
221  throw;
222  }
223  }
224  QDPIO::cout << "Second forward propagator successfully read" << std::endl;
225 
226  // Sanity check - write out the norm2 of the forward prop in the j_decay direction
227  // Use this for any possible verification
228  {
229  // Initialize the slow Fourier transform phases
230  SftMom phases(0, true, source_header2.j_decay);
231 
232  multi1d<Double> forward_prop_corr = sumMulti(localNorm2(quark_propagator2),
233  phases.getSet());
234 
235  push(xml_out, "Forward_prop_correlator1");
236  write(xml_out, "forward_prop_corr", forward_prop_corr);
237  pop(xml_out);
238  }
239 
240  // Save prop input
241  push(xml_out, "Propagator2");
242  write(xml_out, "ForwardProp", prop_header2);
243  write(xml_out, "PropSource", source_header2);
244  pop(xml_out);
245 
246 
247 
248  // More sanity checks
249  if (source_header1.j_decay != source_header2.j_decay)
250  {
251  QDPIO::cerr << "Prop j_decay mismatch" << std::endl;
252  QDP_abort(1);
253  }
254 
255  for(int i=0; i < source_header1.t_source.size(); ++i)
256  if (source_header1.t_source[i] != source_header2.t_source[i])
257  {
258  QDPIO::cerr << "Prop t_source mismatch" << std::endl;
259  QDP_abort(1);
260  }
261 
262 
263  /*
264  * Add the props and be done...
265  */
266  LatticePropagator quark_propagator = 0.5*(quark_propagator1 + quark_propagator2);
267  ChromaProp_t prop_header = prop_header1;
268  PropSourceConst_t source_header = source_header1;
269 
270 
271  // Save the propagator
272  // ONLY SciDAC output format is supported!
273  QDPIO::cout << "Save the new forward propagator" << std::endl;
274  {
275  XMLBufferWriter file_xml;
276  push(file_xml, "propagator");
277  int id = 0; // NEED TO FIX THIS - SOMETHING NON-TRIVIAL NEEDED
278  write(file_xml, "id", id);
279  pop(file_xml);
280 
281  XMLBufferWriter record_xml;
282  push(record_xml, "Propagator");
283  write(record_xml, "ForwardProp", prop_header);
284  write(record_xml, "PropSource", source_header);
285 #if 0
286  {
287  QDPIO::cout << "Create config info" << std::endl;
288  XMLReader gauge_xml(prop_record_xml1, "/Propagator/Config_info");
289  std::ostringstream gauge_str;
290  gauge_xml.print(gauge_str);
291  write(record_xml, "Config_info", gauge_str);
292  QDPIO::cout << "Done config info" << std::endl;
293  }
294 #endif
295  pop(record_xml);
296 
297 
298  // Write the source
299  writeQprop(file_xml, record_xml, quark_propagator,
300  input.prop.prop_file, input.prop.prop_volfmt,
301  QDPIO_SERIAL);
302  }
303  QDPIO::cout << "New forward propagator successfully written" << std::endl;
304 
305 
306  // Close the namelist output file XMLDAT
307  pop(xml_out); // Qpropadd
308 
309  xml_in.close();
310  xml_out.close();
311 
312  END_CODE();
313 
314  // Time to bolt
315  QDP_finalize();
316 
317  exit(0);
318 }
Primary include file for CHROMA in application codes.
Fourier transform phase factor support.
Definition: sftmom.h:35
const Set & getSet() const
The set to be used in sumMulti.
Definition: sftmom.h:57
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
ForwardProp_t prop_header
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
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 readQprop(XMLReader &file_xml, XMLReader &record_xml, LatticePropagator &quark_prop, const std::string &file, QDP_serialparallel_t serpar)
Read a Chroma propagator.
Definition: qprop_io.cc:1573
void writeQprop(XMLBufferWriter &file_xml, XMLBufferWriter &record_xml, const LatticePropagator &quark_prop, const std::string &file, QDP_volfmt_t volfmt, QDP_serialparallel_t serpar)
Write a Chroma propagator.
Definition: qprop_io.cc:1532
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
::std::string string
Definition: gtest.h:1979
int main(int argc, char *argv[])
Definition: qpropadd.cc:110
Propagator parameters.
Definition: qprop_io.h:75
Propagator source construction parameters.
Definition: qprop_io.h:27
Parameters for running program.
Definition: qpropadd.cc:17
multi1d< int > nrow
Definition: qpropadd.cc:18
Propagators.
std::string prop_file1
Definition: qpropadd.cc:24
std::string prop_file2
Definition: qpropadd.cc:25
QDP_volfmt_t prop_volfmt
std::string prop_file
Mega-structure of all input.
Definition: qpropadd.cc:34
Param_t param
Definition: qpropadd.cc:35