CHROMA
inline_eigen_bin_lime_colvec_read_obj.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Inline task to read an object from a named buffer
3  *
4  * Named object reading
5  */
6 
7 #include "chromabase.h"
8 //#include "qdp_iogauge.h"
12 
14 
17 
18 namespace Chroma
19 {
20 
21 
22  //! Object buffer
24  {
25  XMLReader inputtop(xml, path);
26 
27  read(inputtop, "object_id", input.object_id);
28 
29  // User Specified MapObject tags
30  input.object_map = readXMLGroup(inputtop, "ColorVecMapObject", "MapObjType");
31  }
32 
33  //! File output
35  {
36  XMLReader inputtop(xml, path);
37 
38  read(inputtop, "file_name", input.file_name);
39  }
40 
41 
42  namespace InlineEigenBinLimeColVecReadNamedObjEnv
43  {
44 
45 
46 //convience routine to return an array given space and time coords
47  multi1d<int> coords(const int x, const int y, const int z, const int t)
48  {
49  multi1d<int> ret(4);
50 
51  ret[0] = x;
52  ret[1] = y;
53  ret[2] = z;
54  ret[3] = t;
55 
56  return ret;
57  }
58 
59  //Turn an array into a timeslice of a LatticeColorVector
60  void unserialize(LatticeColorVector &cvec, const multi1d< Complex > &vec,
61  const int& t)
62  {
63  int vsize = QDP::Layout::lattSize()[0] * QDP::Layout::lattSize()[0] * QDP::Layout::lattSize()[0] * Nc;
64 
65  if (vec.size() != vsize)
66  {
67  QDPIO::cerr << "in unserialize: invalid size of serialized std::vector"
68  << std::endl;
69 
70  exit(0);
71  }
72 
73  //Loop over space coords
74  for (int x = 0 ; x < QDP::Layout::lattSize()[0] ; ++x)
75  for (int y = 0 ; y < QDP::Layout::lattSize()[0] ; ++y)
76  for (int z = 0 ; z < QDP::Layout::lattSize()[0] ; ++z)
77  {
78  ColorVector sitevec = zero;
79 
80  for (int c = 0 ; c < Nc ; ++c)
81  {
82  Complex temp = vec[ c + Nc*(z + QDP::Layout::lattSize()[0]*(y + QDP::Layout::lattSize()[0]*x)) ];
83 
84  pokeColor(sitevec, temp, c);
85  }
86 
87  pokeSite(cvec, sitevec, coords(x, y, z, t) );
88  }
89 
90  }
91 
92 
93 
94 
95  namespace
96  {
97  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
98  const std::string& path)
99  {
100  return new InlineMeas(Params(xml_in, path));
101  }
102 
103  //! Local registration flag
104  bool registered = false;
105 
106  const std::string name = "EIGENINFO_BIN_LIME_COLORVEC_READ_NAMED_OBJECT";
107  }
108 
109  //! Register all the factories
110  bool registerAll()
111  {
112  bool success = true;
113  if (! registered)
114  {
115  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
117  registered = true;
118  }
119  return success;
120  }
121 
122  // Param stuff
124 
125  Params::Params(XMLReader& xml_in, const std::string& path)
126  {
127  try
128  {
129  XMLReader paramtop(xml_in, path);
130 
131  if (paramtop.count("Frequency") == 1)
132  read(paramtop, "Frequency", frequency);
133  else
134  frequency = 1;
135 
136  // Parameters for source construction
137  read(paramtop, "NamedObject", named_obj);
138 
139  // Read in the destination
140  read(paramtop, "File", file);
141 
142  }
143  catch(const std::string& e)
144  {
145  QDPIO::cerr << __func__ << ": caught Exception reading XML: " << e << std::endl;
146  QDP_abort(1);
147  }
148  }
149 
150 
151  void
152  InlineMeas::operator()(unsigned long update_no, XMLWriter& xml_out)
153  {
154  START_CODE();
155 
156  push(xml_out, "eigeninfo_bin_lime_colorvec_read_named_obj");
157  write(xml_out, "update_no", update_no);
158 
159  QDPIO::cout << name << ": object reader" << std::endl;
160  StopWatch swatch;
161 
162  // Read the object
163  QDPIO::cout << "Attempt to read object name = " << params.named_obj.object_id << std::endl;
164  write(xml_out, "object_id", params.named_obj.object_id);
165  try
166  {
167  swatch.reset();
168 
169  // Generate a metadata
170  std::string file_str;
171  if (1)
172  {
173  XMLBufferWriter file_xml;
174 
175  push(file_xml, "MODMetaData");
176  write(file_xml, "id", std::string("eigenColorVec"));
177  write(file_xml, "lattSize", QDP::Layout::lattSize());
178  // write(file_xml, "num_vecs", readpair.eigenValue.weights.size()); // do not have num_vecs before the data is read!
179  pop(file_xml);
180 
181  file_str = file_xml.str();
182  }
183 
184  // Create the entry
185  std::istringstream xml_s(params.named_obj.object_map.xml);
186  XMLReader MapObjReader(xml_s);
187 
190  MapObjReader,
192  file_str) );
193 
196 
197  int nt = QDP::Layout::lattSize()[Nd-1];
198  int ns = QDP::Layout::lattSize()[0];
199 
200  int ndim = ns * ns * ns * Nc;
201 
202  // Read the object
203  swatch.start();
204 
205  //Make the final file xml which will only contain
206  //gauge info, and eigen calculation info
207  XMLBufferWriter final_file_xml;
208 
209  XMLBufferWriter final_record_xml;
210  push(final_record_xml, "SubsetVectors");
211  push(final_record_xml, "InfoArray");
212 
213  XMLReader file_xml;
214 
215  std::string filename = params.file.file_name;
216  QDPFileReader rdr(file_xml, filename, QDPIO_SERIAL);
217 
218  //Plop some info into the file xml only once
219  write(final_file_xml, "Input", file_xml);
220 
221 #if 1
222  multi1d<LatticeColorVector> evecs;
223  multi1d<SubsetVectorWeight_t> evals;
224 #endif
225  int nev;
226 
227  // Weird storage (time slower than std::vector number)
228  for (int t = 0 ; t < nt ; ++t)
229  {
230 
231  XMLReader curr_record_xml;
232  BinaryBufferReader bin_rdr;
233  read(rdr, curr_record_xml, bin_rdr);
234 
235 
236  // Weights for all vectors on a given timeslice t
237  multi1d<Real> evals_t;
238 
239  if (curr_record_xml.count("/LaplaceEigInfo/EigenValues") != 0)
240  read(curr_record_xml, "/LaplaceEigInfo/EigenValues", evals_t);
241  else if (curr_record_xml.count("/LaplaceEigInfo/EigParams/EigenValues") != 0)
242  read(curr_record_xml, "/LaplaceEigInfo/EigParams/EigenValues", evals_t);
243  else
244  {
245  QDPIO::cerr << __func__ << ": LaplaceEigInfo tag for EigenValues not found\n" << std::endl;
246  QDP_abort(1);
247  }
248 
249 
250 
251  if (t == 0)
252  {
253  nev = evals_t.size();
254  evals.resize(nev);
255  evecs.resize(nev);
256  QDPIO::cout << "Initializing eigenpairs" << std::endl;
257  for (int v = 0 ; v < nev ; ++v)
258  {
259  evecs[v] = zero;
260  evals[v].weights.resize(nt);
261  }
262  }
263  QDPIO::cout << "Unserealizing evecs for timeslice " << t << std::endl;
264  for (int n = 0 ; n < nev ; n++)
265  {
266 
267  evals[n].weights[t] = evals_t[n]; // Copies all the weights
268 
269  multi1d<Complex> temp;
270  read(bin_rdr, temp);
271 
272  if (temp.size() != ndim )
273  {
274  QDPIO::cerr << "Invalid array size" << std::endl;
275  exit(1);
276  }
277  unserialize(evecs[n], temp, t);
278  }
279  write(final_record_xml, "elem", curr_record_xml);
280 
281  }//t
282 
283  for(int n=0; n < nev; n++) {
284  QDPIO::cout << "Inserting eval/evec pair " << n << std::endl;
286  pair.eigenValue = evals[n];
287  pair.eigenVector = evecs[n];
288  eigen->insert(n,pair);
289  }
290 
291  pop(final_record_xml);
292  pop(final_record_xml);
293 
294  swatch.stop();
295 
296  TheNamedObjMap::Instance().get(params.named_obj.object_id).setFileXML(final_file_xml);
297  TheNamedObjMap::Instance().get(params.named_obj.object_id).setRecordXML(final_record_xml);
298 
299  QDPIO::cout << "Object successfully read: time= "
300  << swatch.getTimeInSeconds()
301  << " secs" << std::endl;
302  }
303  catch( std::bad_cast )
304  {
305  QDPIO::cerr << name << ": cast error" << std::endl;
306  QDP_abort(1);
307  }
308  catch (const std::string& e)
309  {
310  QDPIO::cerr << name << ": error message: " << e << std::endl;
311  QDP_abort(1);
312  }
313 
314  QDPIO::cout << name << ": ran successfully" << std::endl;
315 
316  pop(xml_out); // read_named_obj
317 
318  END_CODE();
319  }
320 
321  }
322 }
Inline measurement factory.
Primary include file for CHROMA library code.
Class for counted reference semantics.
Definition: handle.h:33
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the writing.
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.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Inline task to read an object from a named buffer.
unsigned n
Definition: ldumul_w.cc:36
int y
Definition: meslate.cc:35
int z
Definition: meslate.cc:36
int x
Definition: meslate.cc:34
int t
Definition: meslate.cc:37
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
const std::string name
Name to be used.
void unserialize(LatticeColorVector &cvec, const multi1d< Complex > &vec, const int &t)
multi1d< int > coords(const int x, const int y, const int z, const int t)
bool registerAll()
aggregate everything
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
push(xml_out,"Condensates")
Double c
Definition: invbicg.cc:108
pop(xml_out)
START_CODE()
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
A Pair type.
SubsetVectorWeight_t eigenValue
struct Chroma::InlineEigenBinLimeColVecReadNamedObjEnv::Params::File_t file
struct Chroma::InlineEigenBinLimeColVecReadNamedObjEnv::Params::NamedObject_t named_obj
Holds of vectors and weights.