CHROMA
inline_prop_and_matelem_distillation2_w.cc
Go to the documentation of this file.
1 /*! \file
2  * \brief Compute propagators from distillation
3  *
4  * Propagator calculation in distillation
5  */
6 
7 #include "fermact.h"
10 #include "meas/glue/mesplq.h"
11 #include "qdp_map_obj.h"
12 #include "qdp_map_obj_disk.h"
13 #include "qdp_map_obj_disk_multiple.h"
14 #include "qdp_map_obj_memory.h"
15 #include "qdp_disk_map_slice.h"
21 #include "util/ferm/key_val_db.h"
22 #include "util/ferm/transf.h"
23 #include "util/ferm/spin_rep.h"
24 #include "util/ferm/diractodr.h"
26 #include "util/ft/sftmom.h"
27 #include "util/ft/time_slice_set.h"
28 #include "util/info/proginfo.h"
29 #include "util/info/proginfo.h"
33 
35 
36 #ifndef QDP_IS_QDPJIT
37 
38 namespace Chroma
39 {
40  //----------------------------------------------------------------------------
41  // Utilities
42  namespace {
43  multi1d<SubsetVectorWeight_t> readEigVals(const std::string& meta)
44  {
45  std::istringstream xml_l(meta);
46  XMLReader eigtop(xml_l);
47 
48  std::string pat("/MODMetaData/Weights");
49  // multi1d<SubsetVectorWeight_t> eigenvalues;
50  multi1d< multi1d<Real> > eigens;
51  try
52  {
53  read(eigtop, pat, eigens);
54  }
55  catch(const std::string& e)
56  {
57  QDPIO::cerr << __func__ << ": Caught Exception reading meta= XX" << meta << "XX with path= " << pat << " error= " << e << std::endl;
58  QDP_abort(1);
59  }
60 
61  eigtop.close();
62 
63  multi1d<SubsetVectorWeight_t> eigenvalues(eigens.size());
64 
65  for(int i=0; i < eigens.size(); ++i)
66  eigenvalues[i].weights = eigens[i];
67 
68  return eigenvalues;
69  }
70  }
71 
72  //----------------------------------------------------------------------------
73  namespace InlinePropAndMatElemDistillation2Env
74  {
75  //! Propagator input
76  void read(XMLReader& xml, const std::string& path, Params::NamedObject_t& input)
77  {
78  XMLReader inputtop(xml, path);
79 
80  read(inputtop, "gauge_id", input.gauge_id);
81  read(inputtop, "colorvec_files", input.colorvec_files);
82  read(inputtop, "prop_op_file", input.prop_op_file);
83  }
84 
85  //! Propagator output
86  void write(XMLWriter& xml, const std::string& path, const Params::NamedObject_t& input)
87  {
88  push(xml, path);
89 
90  write(xml, "gauge_id", input.gauge_id);
91  write(xml, "colorvec_files", input.colorvec_files);
92  write(xml, "prop_op_file", input.prop_op_file);
93 
94  pop(xml);
95  }
96 
97 
98  //! Propagator input
99  void read(XMLReader& xml, const std::string& path, Params::Param_t::Contract_t& input)
100  {
101  XMLReader inputtop(xml, path);
102 
103  read(inputtop, "num_vecs", input.num_vecs);
104  read(inputtop, "t_sources", input.t_sources);
105  read(inputtop, "decay_dir", input.decay_dir);
106  read(inputtop, "Nt_forward", input.Nt_forward);
107  read(inputtop, "Nt_backward", input.Nt_backward);
108  read(inputtop, "mass_label", input.mass_label);
109  read(inputtop, "num_tries", input.num_tries);
110  read(inputtop, "src_spins", input.src_spins);
111  }
112 
113  //! Propagator output
114  void write(XMLWriter& xml, const std::string& path, const Params::Param_t::Contract_t& input)
115  {
116  push(xml, path);
117 
118  write(xml, "num_vecs", input.num_vecs);
119  write(xml, "t_sources", input.t_sources);
120  write(xml, "decay_dir", input.decay_dir);
121  write(xml, "Nt_forward", input.Nt_forward);
122  write(xml, "Nt_backward", input.Nt_backward);
123  write(xml, "mass_label", input.mass_label);
124  write(xml, "num_tries", input.num_tries);
125 
126  pop(xml);
127  }
128 
129 
130  //! Propagator input
131  void read(XMLReader& xml, const std::string& path, Params::Param_t& input)
132  {
133  XMLReader inputtop(xml, path);
134 
135  read(inputtop, "Propagator", input.prop);
136  read(inputtop, "Contractions", input.contract);
137  }
138 
139  //! Propagator output
140  void write(XMLWriter& xml, const std::string& path, const Params::Param_t& input)
141  {
142  push(xml, path);
143 
144  write(xml, "Propagator", input.prop);
145  write(xml, "Contractions", input.contract);
146 
147  pop(xml);
148  }
149 
150 
151  //! Propagator input
152  void read(XMLReader& xml, const std::string& path, Params& input)
153  {
154  Params tmp(xml, path);
155  input = tmp;
156  }
157 
158  //! Propagator output
159  void write(XMLWriter& xml, const std::string& path, const Params& input)
160  {
161  push(xml, path);
162 
163  write(xml, "Param", input.param);
164  write(xml, "NamedObject", input.named_obj);
165 
166  pop(xml);
167  }
168  } // namespace InlinePropDistillationEnv
169 
170 
171  //----------------------------------------------------------------------------
172  //----------------------------------------------------------------------------
173  namespace InlinePropAndMatElemDistillation2Env
174  {
175  //----------------------------------------------------------------------------
176  // Convenience type
177  typedef QDP::MapObjectDisk<KeyTimeSliceColorVec_t, TimeSliceIO<LatticeColorVectorF> > MOD_t;
178 
179  // Convenience type
180  typedef QDP::MapObjectDiskMultiple<KeyTimeSliceColorVec_t, TimeSliceIO<LatticeColorVectorF> > MODS_t;
181 
182  // Convenience type
183  typedef QDP::MapObjectMemory<KeyTimeSliceColorVec_t, SubLatticeColorVectorF> SUB_MOD_t;
184 
185  // Anonymous namespace
186  namespace
187  {
188  //----------------------------------------------------------------------------
189  //! Class to hold std::map of eigenvectors
190 
191  class SubEigenMap
192  {
193  public:
194  struct Key_t {
195  Key_t(int t_source, int colorvec_src): t_source(t_source), vec_num(colorvec_src) {}
196  int t_source;
197  int vec_num;
198  };
199 
200 
201  //! Constructor
202  SubEigenMap(MODS_t& eigen_source_, int decay_dir) : eigen_source(eigen_source_), time_slice_set(decay_dir) {}
203 
204  //! Getter
205  const SubLatticeColorVectorF& getVec(int t_source, int colorvec_src) const;
206  const SubLatticeColorVectorF& getVecConst(int t_source, int colorvec_src) const;
207  void cacheVec(int t_source, int colorvec_src) const;
208 
209  //! The set to be used in sumMulti
210  const Set& getSet() const {return time_slice_set.getSet();}
211 
212  private:
213  //! Eigenvectors
215 
216  // The time-slice set
218 
219  private:
220  //! Where we store the sublattice versions
221  //mutable SUB_MOD_t sub_eigen;
222  mutable std::map< Key_t , SubLatticeColorVectorF > sub_eigen;
223  };
224 
225  bool operator<( const SubEigenMap::Key_t& l , const SubEigenMap::Key_t& r )
226  {
227  if ( l.vec_num < r.vec_num )
228  return true;
229  if ( l.vec_num > r.vec_num )
230  return false;
231  if ( l.t_source < r.t_source )
232  return true;
233  return false;
234  }
235 
236 
237  //----------------------------------------------------------------------------
238  //! Getter
239  const SubLatticeColorVectorF& SubEigenMap::getVec(int t_source, int colorvec_src) const
240  {
241  // The key
242  KeyTimeSliceColorVec_t src_key(t_source, colorvec_src);
243  Key_t map_key(t_source,colorvec_src);
244 
245  // If item does not exist, read from original std::map and put in memory std::map
246  if (sub_eigen.count( map_key ) == 0)
247  {
248  QDPIO::cout << __func__ << ": on t_source= " << t_source << " STL map colorvec_src= " << colorvec_src << std::endl;
249 
250  LatticeColorVectorF vec_srce = zero;
251 
252  TimeSliceIO<LatticeColorVectorF> time_slice_io(vec_srce, t_source);
253  eigen_source.get(src_key, time_slice_io);
254 
255  SubLatticeColorVectorF tmp(getSet()[t_source], vec_srce);
256 
257  //sub_eigen.insert(src_key, tmp);
258  sub_eigen.insert( std::make_pair( map_key , tmp));
259  }
260  return sub_eigen[map_key];
261  }
262 
263 
264  const SubLatticeColorVectorF& SubEigenMap::getVecConst(int t_source, int colorvec_src) const
265  {
266  Key_t map_key(t_source,colorvec_src);
267 
268  return sub_eigen.at(map_key);
269  }
270 
271 
272  void SubEigenMap::cacheVec(int t_source, int colorvec_src) const
273  {
274  // The key
275  KeyTimeSliceColorVec_t src_key(t_source, colorvec_src);
276  Key_t map_key(t_source,colorvec_src);
277 
278  // If item does not exist, read from original std::map and put in memory std::map
279  if (sub_eigen.count( map_key ) == 0)
280  {
281  QDPIO::cout << __func__ << ": on t_source= " << t_source << " STL map colorvec_src= " << colorvec_src << std::endl;
282 
283  LatticeColorVectorF vec_srce = zero;
284 
285  TimeSliceIO<LatticeColorVectorF> time_slice_io(vec_srce, t_source);
286  eigen_source.get(src_key, time_slice_io);
287 
288  SubLatticeColorVectorF tmp(getSet()[t_source], vec_srce);
289 
290  //sub_eigen.insert(src_key, tmp);
291  sub_eigen.insert( std::make_pair( map_key , tmp));
292  }
293  }
294 
295 
296 
297  //----------------------------------------------------------------------------
298  //! Get active time-slices
299  std::vector<bool> getActiveTSlices(int t_source, int Nt_forward, int Nt_backward)
300  {
301  // Initialize the active time slices
302  const int decay_dir = Nd-1;
303  const int Lt = Layout::lattSize()[decay_dir];
304 
305  std::vector<bool> active_t_slices(Lt);
306  for(int t=0; t < Lt; ++t)
307  {
308  active_t_slices[t] = false;
309  }
310 
311  // Forward
312  for(int dt=0; dt < Nt_forward; ++dt)
313  {
314  int t = t_source + dt;
315  active_t_slices[t % Lt] = true;
316  }
317 
318  // Backward
319  for(int dt=0; dt < Nt_backward; ++dt)
320  {
321  int t = t_source - dt;
322  while (t < 0) {t += Lt;}
323 
324  active_t_slices[t % Lt] = true;
325  }
326 
327  return active_t_slices;
328  }
329 
330 
331  //----------------------------------------------------------------------------
332  //! Get sink keys
333  std::list<KeyPropElementalOperator_t> getSnkKeys(int t_source, int spin_source, int Nt_forward, int Nt_backward, const std::string mass)
334  {
335  std::list<KeyPropElementalOperator_t> keys;
336 
337  std::vector<bool> active_t_slices = getActiveTSlices(t_source, Nt_forward, Nt_backward);
338 
339  const int decay_dir = Nd-1;
340  const int Lt = Layout::lattSize()[decay_dir];
341 
342  for(int spin_sink=0; spin_sink < Ns; ++spin_sink)
343  {
344  for(int t=0; t < Lt; ++t)
345  {
346  if (! active_t_slices[t]) {continue;}
347 
349 
350  key.t_source = t_source;
351  key.t_slice = t;
352  key.spin_src = spin_source;
353  key.spin_snk = spin_sink;
354  key.mass_label = mass;
355 
356  keys.push_back(key);
357  } // for t
358  } // for spin_sink
359 
360  return keys;
361  }
362 
363  } // end anonymous
364  } // end namespace
365 
366 
367  //----------------------------------------------------------------------------
368  namespace InlinePropAndMatElemDistillation2Env
369  {
370  namespace
371  {
372  AbsInlineMeasurement* createMeasurement(XMLReader& xml_in,
373  const std::string& path)
374  {
375  return new InlineMeas(Params(xml_in, path));
376  }
377 
378  //! Local registration flag
379  bool registered = false;
380  }
381 
382  const std::string name = "PROP_AND_MATELEM_DISTILLATION2";
383 
384  //! Register all the factories
385  bool registerAll()
386  {
387  bool success = true;
388  if (! registered)
389  {
391  success &= TheInlineMeasurementFactory::Instance().registerObject(name, createMeasurement);
392  registered = true;
393  }
394  return success;
395  }
396 
397 
398  //----------------------------------------------------------------------------
399  // Param stuff
401 
402  Params::Params(XMLReader& xml_in, const std::string& path)
403  {
404  try
405  {
406  XMLReader paramtop(xml_in, path);
407 
408  if (paramtop.count("Frequency") == 1)
409  read(paramtop, "Frequency", frequency);
410  else
411  frequency = 1;
412 
413  // Parameters for source construction
414  read(paramtop, "Param", param);
415 
416  // Read in the output propagator/source configuration info
417  read(paramtop, "NamedObject", named_obj);
418 
419  // Possible alternate XML file pattern
420  if (paramtop.count("xml_file") != 0)
421  {
422  read(paramtop, "xml_file", xml_file);
423  }
424  }
425  catch(const std::string& e)
426  {
427  QDPIO::cerr << __func__ << ": Caught Exception reading XML: " << e << std::endl;
428  QDP_abort(1);
429  }
430  }
431 
432 
433 
434  namespace local {
435 
436  template<class T1,class C1,class T2,class C2>
437  typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalInnerProduct>::Type_t >::Type_t
438  localInnerProduct(const QDPSubType<T1,C1> & l,const QDPType<T2,C2> & r)
439  {
440  if (!l.getOwnsMemory())
441  QDP_error_exit("localInnerProduct with subtype view called");
442 
443  typename QDPSubTypeTrait< typename BinaryReturn<C1,C2,FnLocalInnerProduct>::Type_t >::Type_t ret;
444  ret.setSubset( l.subset() );
445 
446  //QDP_info("localInnerProduct %d sites",l.subset().numSiteTable());
447 
448  const int *tab = l.subset().siteTable().slice();
449  //#pragma omp parallel for
450  for(int j=0; j < l.subset().numSiteTable(); ++j)
451  {
452  int i = tab[j];
453  FnLocalInnerProduct op;
454  ret.getF()[j] = op( l.getF()[j] , r.elem(i) );
455  }
456 
457  return ret;
458  }
459 
460 
461  template<class T1, class C1, class T2, class C2>
462  inline typename BinaryReturn<C1, C2, FnInnerProduct>::Type_t
463  innerProduct(const QDPSubType<T1,C1>& s1, const QDPType<T2,C2>& s2)
464  {
465  return sum(local::localInnerProduct(s1,s2));
466  }
467 
468 
469  template<class T1,class C1,class T2,class C2>
470  typename UnaryReturn< OLattice< typename BinaryReturn<T1,T2,FnLocalInnerProduct>::Type_t >, FnSum>::Type_t
471  sumLocalInnerProduct(const QDPSubType<T1,C1> & l,const QDPType<T2,C2> & r)
472  {
473  if (!l.getOwnsMemory())
474  QDP_error_exit("localInnerProduct with subtype view called");
475 
476  typename UnaryReturn<OLattice< typename BinaryReturn<T1,T2,FnLocalInnerProduct>::Type_t >, FnSum>::Type_t ret;
477 
478  zero_rep(ret.elem());
479 
480  const int *tab = l.subset().siteTable().slice();
481 
482  for(int j=0; j < l.subset().numSiteTable(); ++j)
483  {
484  int i = tab[j];
485  FnLocalInnerProduct op;
486 
487  ret.elem() += op( l.getF()[j] , r.elem(i) );
488  }
489 
490 
491  // The global sum is not thread-safe and we run this function in a parallel region
492 
493  //QDPInternal::globalSum(ret);
494 
495  return ret;
496  }
497 
498 
499  }
500 
501 
502  //----------------------------------------------------------------------------
503  //----------------------------------------------------------------------------
504  // Function call
505  void
506  InlineMeas::operator()(unsigned long update_no,
507  XMLWriter& xml_out)
508  {
509  // If xml file not empty, then use alternate
510  if (params.xml_file != "")
511  {
512  std::string xml_file = makeXMLFileName(params.xml_file, update_no);
513 
514  push(xml_out, "PropDistillation");
515  write(xml_out, "update_no", update_no);
516  write(xml_out, "xml_file", xml_file);
517  pop(xml_out);
518 
519  XMLFileWriter xml(xml_file);
520  func(update_no, xml);
521  }
522  else
523  {
524  func(update_no, xml_out);
525  }
526  }
527 
528 
529  // Real work done here
530  void
531  InlineMeas::func(unsigned long update_no,
532  XMLWriter& xml_out)
533  {
534  START_CODE();
535 
536  if ( Layout::numNodes() != 1 ) {
537  QDPIO::cerr << "This measurement does not support running on multiple nodes." << std::endl;
538  QDP_abort(1);
539  }
540 
541  StopWatch snoop;
542  snoop.reset();
543  snoop.start();
544 
545  // Test and grab a reference to the gauge field
546  multi1d<LatticeColorMatrix> u;
547  XMLBufferWriter gauge_xml;
548  try
549  {
550  u = TheNamedObjMap::Instance().getData< multi1d<LatticeColorMatrix> >(params.named_obj.gauge_id);
551  TheNamedObjMap::Instance().get(params.named_obj.gauge_id).getRecordXML(gauge_xml);
552  }
553  catch( std::bad_cast )
554  {
555  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
556  QDP_abort(1);
557  }
558  catch (const std::string& e)
559  {
560  QDPIO::cerr << name << ": std::map call failed: " << e << std::endl;
561  QDP_abort(1);
562  }
563 
564  push(xml_out, "PropDistillation");
565  write(xml_out, "update_no", update_no);
566 
567  QDPIO::cout << name << ": propagator calculation" << std::endl;
568 
569  proginfo(xml_out); // Print out basic program info
570 
571  // Write out the input
572  write(xml_out, "Input", params);
573 
574  // Write out the config header
575  write(xml_out, "Config_info", gauge_xml);
576 
577  push(xml_out, "Output_version");
578  write(xml_out, "out_version", 1);
579  pop(xml_out);
580 
581  // Calculate some gauge invariant observables just for info.
582  MesPlq(xml_out, "Observables", u);
583 
584  // Will use TimeSliceSet-s a lot
585  const int decay_dir = params.param.contract.decay_dir;
586  const int Lt = Layout::lattSize()[decay_dir];
587 
588  // A sanity check
589  if (decay_dir != Nd-1)
590  {
591  QDPIO::cerr << name << ": TimeSliceIO only supports decay_dir= " << Nd-1 << "\n";
592  QDP_abort(1);
593  }
594 
595  // Reset
596  if (params.param.contract.num_tries <= 0)
597  {
599  }
600 
601 
602  //
603  // Read in the source along with relevant information.
604  //
605  QDPIO::cout << "Snarf the source from a std::map object disk file" << std::endl;
606 
608  eigen_source.setDebug(0);
609 
610  std::string eigen_meta_data; // holds the eigenvalues
611 
612  try
613  {
614  // Open
615  QDPIO::cout << "Open file= " << params.named_obj.colorvec_files[0] << std::endl;
617 
618  // Snarf the source info.
619  QDPIO::cout << "Get user data" << std::endl;
620  eigen_source.getUserdata(eigen_meta_data);
621  // QDPIO::cout << "User data= " << eigen_meta_data << std::endl;
622 
623  // Write it
624  // QDPIO::cout << "Write to an xml file" << std::endl;
625  // XMLBufferWriter xml_buf(eigen_meta_data);
626  // write(xml_out, "Source_info", xml_buf);
627  }
628  catch (std::bad_cast) {
629  QDPIO::cerr << name << ": caught dynamic cast error" << std::endl;
630  QDP_abort(1);
631  }
632  catch (const std::string& e) {
633  QDPIO::cerr << name << ": error extracting source_header: " << e << std::endl;
634  QDP_abort(1);
635  }
636  catch( const char* e) {
637  QDPIO::cerr << name <<": Caught some char* exception:" << std::endl;
638  QDPIO::cerr << e << std::endl;
639  QDPIO::cerr << "Rethrowing" << std::endl;
640  throw;
641  }
642 
643  QDPIO::cout << "Source successfully read and parsed" << std::endl;
644 
645 #if 0
646  // Sanity check
648  {
649  QDPIO::cerr << name << ": number of available eigenvectors is too small\n";
650  QDP_abort(1);
651  }
652 #endif
653 
654  QDPIO::cout << "Number of vecs available is large enough" << std::endl;
655 
656  // The sub-lattice eigenstd::vector std::map
657  QDPIO::cout << "Initialize sub-lattice std::map" << std::endl;
658  SubEigenMap sub_eigen_map(eigen_source, decay_dir);
659  QDPIO::cout << "Finished initializing sub-lattice std::map" << std::endl;
660 
661 
662  //
663  // DB storage
664  //
665  BinaryStoreDB< SerialDBKey<KeyPropElementalOperator_t>, SerialDBData<ValPropElementalOperator_t> > qdp_db;
666 
667  // Open the file, and write the meta-data and the binary for this operator
668  if (! qdp_db.fileExists(params.named_obj.prop_op_file))
669  {
670  XMLBufferWriter file_xml;
671 
672  push(file_xml, "DBMetaData");
673  write(file_xml, "id", std::string("propElemOp"));
674  write(file_xml, "lattSize", QDP::Layout::lattSize());
675  write(file_xml, "decay_dir", params.param.contract.decay_dir);
676  proginfo(file_xml); // Print out basic program info
677  write(file_xml, "Params", params.param);
678  write(file_xml, "Config_info", gauge_xml);
679  write(file_xml, "Weights", readEigVals(eigen_meta_data));
680  pop(file_xml);
681 
682  std::string file_str(file_xml.str());
683  qdp_db.setMaxUserInfoLen(file_str.size());
684 
685  qdp_db.open(params.named_obj.prop_op_file, O_RDWR | O_CREAT, 0664);
686 
687  qdp_db.insertUserdata(file_str);
688  }
689  else
690  {
691  qdp_db.open(params.named_obj.prop_op_file, O_RDWR, 0664);
692  }
693 
694  QDPIO::cout << "Finished opening peram file" << std::endl;
695 
696 
697  // Total number of iterations
698  int ncg_had = 0;
699 
700  //
701  // Try the factories
702  //
703  try
704  {
705  StopWatch swatch;
706  swatch.reset();
707  QDPIO::cout << "Try the various factories" << std::endl;
708 
709  // Typedefs to save typing
710  typedef LatticeFermion T;
711  typedef multi1d<LatticeColorMatrix> P;
712  typedef multi1d<LatticeColorMatrix> Q;
713 
714  //
715  // Initialize fermion action
716  //
717  std::istringstream xml_s(params.param.prop.fermact.xml);
718  XMLReader fermacttop(xml_s);
719  QDPIO::cout << "FermAct = " << params.param.prop.fermact.id << std::endl;
720 
721  // Generic Wilson-Type stuff
724  fermacttop,
726 
727  Handle< FermState<T,P,Q> > state(S_f->createState(u));
728 
731 
732  QDPIO::cout << "Suitable factory found: compute all the quark props" << std::endl;
733  swatch.start();
734 
735 
736  //
737  // Loop over the source color and spin, creating the source
738  // and calling the relevant propagator routines.
739  //
740  const int num_vecs = params.param.contract.num_vecs;
741  const multi1d<int>& t_sources = params.param.contract.t_sources;
742  const multi1d<int>& src_spins = params.param.contract.src_spins;
743 
744  // Loop over each time source
745  for(int tt=0; tt < t_sources.size(); ++tt)
746  {
747  int t_source = t_sources[tt]; // This is the actual time-slice.
748  QDPIO::cout << "t_source = " << t_source << std::endl;
749 
750  // Loop over each spin source
751  for(int ss=0; ss < src_spins.size(); ++ss)
752  {
753  int spin_source = src_spins[ss];
754  QDPIO::cout << "spin_source = " << spin_source << std::endl;
755 
756  // These are the common parts of a perambulator that are needed for this time source
757  std::list<KeyPropElementalOperator_t> snk_keys(getSnkKeys(t_source,
758  spin_source,
762 
763 
764  //
765  // The space distillation loop
766  //
767  for(int colorvec_src=0; colorvec_src < num_vecs; ++colorvec_src)
768  {
769  StopWatch sniss1;
770  sniss1.reset();
771  sniss1.start();
772 
773  StopWatch snarss1;
774  snarss1.reset();
775  snarss1.start();
776  QDPIO::cout << "Do spin_source= " << spin_source << " colorvec_src= " << colorvec_src << std::endl;
777 
778  // Get the source std::vector
779  LatticeColorVector vec_srce = zero;
780  vec_srce = sub_eigen_map.getVec(t_source, colorvec_src);
781 
782  //
783  // Loop over each spin source and invert.
784  // Use the same colorstd::vector source. No spin dilution will be used.
785  //
786  multi1d<LatticeColorVector> ferm_out(Ns);
787 
788  // Insert a ColorVector into spin index spin_source
789  // This only overwrites sections, so need to initialize first
790  LatticeFermion chi = zero;
791  CvToFerm(vec_srce, chi, spin_source);
792 
793  LatticeFermion quark_soln = zero;
794 
795  // Do the propagator inversion
796  // Check if bad things are happening
797  bool badP = true;
798  for(int nn = 1; nn <= params.param.contract.num_tries; ++nn)
799  {
800  // Reset
801  quark_soln = zero;
802  badP = false;
803 
804  // Solve for the solution std::vector
805  SystemSolverResults_t res = (*PP)(quark_soln, chi);
806  ncg_had += res.n_count;
807 
808  // Some sanity checks
809  if (toDouble(res.resid) > 1.0e-3)
810  {
811  QDPIO::cerr << name << ": have a resid > 1.0e-3. That is unacceptable" << std::endl;
812  QDP_abort(1);
813  }
814 
815  // Check for finite values - neither NaN nor Inf
816  if (isfinite(quark_soln))
817  {
818  // Okay
819  break;
820  }
821  else
822  {
823  QDPIO::cerr << name << ": WARNING - found something not finite, may retry\n";
824  badP = true;
825  }
826  }
827 
828  // Sanity check
829  if (badP)
830  {
831  QDPIO::cerr << name << ": this is bad - did not get a finite solution std::vector after num_tries= "
832  << params.param.contract.num_tries << std::endl;
833  QDP_abort(1);
834  }
835 
836  // Extract into the temporary output array
837  for(int spin_sink=0; spin_sink < Ns; ++spin_sink)
838  {
839  ferm_out(spin_sink) = peekSpin(quark_soln, spin_sink);
840  }
841 
842  snarss1.stop();
843  QDPIO::cout << "Time to compute prop for spin_source= " << spin_source << " colorvec_src= " << colorvec_src << " time = "
844  << snarss1.getTimeInSeconds()
845  << " secs" << std::endl;
846 
847  // The perambulator part
848  // Loop over time
849 
850  for(int t_slice = 0; t_slice < Lt; ++t_slice)
851  {
852  // Loop over all the keys
853  for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
854  key != snk_keys.end();
855  ++key)
856  {
857  if (key->t_slice != t_slice) {continue;}
858 
859  // new:
861  tmp.mat.resize(num_vecs,num_vecs);
862  tmp.mat = zero;
863 
864  // pre cache
865  for(int colorvec_sink=0; colorvec_sink < num_vecs; ++colorvec_sink)
866  sub_eigen_map.cacheVec(t_slice, colorvec_sink);
867 
868 #pragma omp parallel for
869  for(int colorvec_sink=0; colorvec_sink < num_vecs; ++colorvec_sink)
870  {
871  tmp.mat(colorvec_sink,colorvec_src) = local::sumLocalInnerProduct(sub_eigen_map.getVecConst(t_slice, colorvec_sink),
872  ferm_out(key->spin_snk));
873  } // for colorvec_sink
874 
875  // write out
876  qdp_db.insert(*key, tmp);
877 
878  } // for key
879  } // for t_slice
880 
881  sniss1.stop();
882  QDPIO::cout << "Time to compute and assemble peram for spin_source= " << spin_source << " colorvec_src= " << colorvec_src << " time = "
883  << sniss1.getTimeInSeconds()
884  << " secs" << std::endl;
885 
886  } // for colorvec_src
887 
888  // Write out each time-slice chunk of a lattice colorvec soln to disk
889  QDPIO::cout << "Write perambulator for spin_source= " << spin_source << " to disk" << std::endl;
890  StopWatch sniss2;
891  sniss2.reset();
892  sniss2.start();
893 
894 #if 0
895  // The perambulator is complete. Write it.
896  for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
897  key != snk_keys.end();
898  ++key)
899  {
900  // Insert/write to disk
901  qdp_db.insert(*key, peram[*key]);
902  } // for key
903 #endif
904 
905  sniss2.stop();
906  QDPIO::cout << "Time to write perambulators for spin_src= " << spin_source << " time = "
907  << sniss2.getTimeInSeconds()
908  << " secs" << std::endl;
909 
910  } // for spin_src
911  } // for tt
912 
913  swatch.stop();
914  QDPIO::cout << "Propagators computed: time= "
915  << swatch.getTimeInSeconds()
916  << " secs" << std::endl;
917  }
918  catch (const std::string& e)
919  {
920  QDPIO::cout << name << ": caught exception around qprop: " << e << std::endl;
921  QDP_abort(1);
922  }
923 
924  push(xml_out,"Relaxation_Iterations");
925  write(xml_out, "ncg_had", ncg_had);
926  pop(xml_out);
927 
928  pop(xml_out); // prop_dist
929 
930  snoop.stop();
931  QDPIO::cout << name << ": total time = "
932  << snoop.getTimeInSeconds()
933  << " secs" << std::endl;
934 
935  QDPIO::cout << name << ": ran successfully" << std::endl;
936 
937  END_CODE();
938  }
939 
940  }
941 
942 } // namespace Chroma
943 
944 #endif
Inline measurement factory.
Class for counted reference semantics.
Definition: handle.h:33
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.
Serializable value harness.
Definition: key_val_db.h:69
static T & Instance()
Definition: singleton.h:432
Builds time slice subsets.
const Set & getSet() const
The set to be used in sumMulti.
EXTERN Real dt
Basis rotation matrix from Dirac to Degrand-Rossi (and reverse)
Class structure for fermion actions.
Fermion action factories.
All Wilson-type fermion actions.
void CvToFerm(const LatticeColorVectorF &a, LatticeFermionF &b, int spin_index)
Convert (insert) a LatticeColorVector into a LatticeFermion.
Definition: transf.cc:18
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams &param)
Read parameters.
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.
MODS_t & eigen_source
Eigenvectors.
std::map< Key_t, SubLatticeColorVectorF > sub_eigen
Where we store the sublattice versions.
Compute the propagator from distillation.
Key for propagator colorstd::vector sources.
Key for vanilla distillation propagator sources and solutions.
Key for propagator colorstd::vector matrix elements.
Key for time-sliced color eigenvectors.
Key and values for DB.
unsigned j
Definition: ldumul_w.cc:35
Make xml file writer.
int t
Definition: meslate.cc:37
int t_slice
Definition: meslate.cc:23
Nd
Definition: meslate.cc:74
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
UnaryReturn< OLattice< typename BinaryReturn< T1, T2, FnLocalInnerProduct >::Type_t >, FnSum >::Type_t sumLocalInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Propagator input.
QDP::MapObjectDisk< KeyTimeSliceColorVec_t, TimeSliceIO< LatticeColorVectorF > > MOD_t
QDP::MapObjectMemory< KeyTimeSliceColorVec_t, SubLatticeColorVectorF > SUB_MOD_t
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Propagator output.
QDP::MapObjectDiskMultiple< KeyTimeSliceColorVec_t, TimeSliceIO< LatticeColorVectorF > > MODS_t
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
Definition: klein_gord.cc:10
QDP_error_exit("too many BiCG iterations", n_count, rsd_sq, cp, c, re_rvr, im_rvr, re_a, im_a, re_b, im_b)
bool operator<(const KeyDispColorVector_t &a, const KeyDispColorVector_t &b)
Support for the keys of smeared and displaced color vectors.
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
LatticeFermion tmp
Definition: mespbg5p_w.cc:36
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
int i
Definition: pbg5p_w.cc:55
Double mass
Definition: pbg5p_w.cc:54
multi1d< LatticeFermion > chi(Ncb)
pop(xml_out)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
Definition: mesplq.cc:83
START_CODE()
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Definition: pbg5p_w.cc:28
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Definition: pbg5p_w.cc:27
Double zero
Definition: invbicg.cc:106
::std::string string
Definition: gtest.h:1979
int l
Definition: pade_trln_w.cc:111
Print out basic info about this program.
Double sum
Definition: qtopcor.cc:37
Fourier transform phase factor support.
Sparse matrix representation of spin matrices.
GroupXML_t invParam
Definition: qprop_io.h:84
GroupXML_t fermact
Definition: qprop_io.h:80
Holds return info from SystemSolver call.
Definition: syssolver.h:17
Holds of vectors and weights.
Convenience for building time-slice subsets.
Contraction operators for two quarks.