12 #include "qdp_map_obj.h"
13 #include "qdp_map_obj_disk.h"
14 #include "qdp_map_obj_disk_multiple.h"
15 #include "qdp_map_obj_memory.h"
16 #include "qdp_disk_map_slice.h"
39 #ifndef QDP_IS_QDPJIT_NO_NVPTX
41 #ifdef BUILD_JIT_CONTRACTION_KERNELS
42 #include "custom_kernels/custom_kernels.h"
51 multi1d<SubsetVectorWeight_t> readEigVals(
const std::string& meta)
53 std::istringstream xml_l(meta);
54 XMLReader eigtop(xml_l);
58 multi1d< multi1d<Real> > eigens;
61 read(eigtop, pat, eigens);
65 QDPIO::cerr << __func__ <<
": Caught Exception reading meta= XX" << meta <<
"XX with path= " << pat <<
" error= " << e << std::endl;
71 multi1d<SubsetVectorWeight_t> eigenvalues(eigens.size());
73 for(
int i=0;
i < eigens.size(); ++
i)
74 eigenvalues[
i].weights = eigens[
i];
82 namespace InlinePropAndMatElemDistillationEnv
87 XMLReader inputtop(xml, path);
110 XMLReader inputtop(xml, path);
121 if( inputtop.count(
"zero_colorvecs") == 1 ) {
125 QDPIO::cout <<
"zero_colorvecs found, *** timing mode activated ***\n";
130 if( inputtop.count(
"fuse_timeloop") == 1 ) {
134 QDPIO::cout <<
"fuse_timeloop found!\n";
160 XMLReader inputtop(xml, path);
162 read(inputtop,
"Propagator", input.
prop);
200 namespace InlinePropAndMatElemDistillationEnv
204 typedef QDP::MapObjectDisk<KeyTimeSliceColorVec_t, TimeSliceIO<LatticeColorVectorF> >
MOD_t;
207 typedef QDP::MapObjectDiskMultiple<KeyTimeSliceColorVec_t, TimeSliceIO<LatticeColorVectorF> >
MODS_t;
210 typedef QDP::MapObjectMemory<KeyTimeSliceColorVec_t, SubLatticeColorVectorF>
SUB_MOD_t;
224 const SubLatticeColorVectorF& getVec(
int t_source,
int colorvec_src)
const;
244 const SubLatticeColorVectorF& SubEigenMap::getVec(
int t_source,
int colorvec_src)
const
251 QDPIO::cout << __func__ <<
": on t_source= " <<
t_source <<
" colorvec_src= " << colorvec_src << std::endl;
254 LatticeColorVectorF vec_srce;
258 TimeSliceIO<LatticeColorVectorF> time_slice_io(vec_srce,
t_source);
262 SubLatticeColorVectorF
tmp(getSet()[
t_source], vec_srce);
272 std::vector<bool> getActiveTSlices(
int t_source,
int Nt_forward,
int Nt_backward)
275 const int decay_dir =
Nd-1;
276 const int Lt = Layout::lattSize()[decay_dir];
278 std::vector<bool> active_t_slices(Lt);
279 for(
int t=0;
t < Lt; ++
t)
281 active_t_slices[
t] =
false;
285 for(
int dt=0;
dt < Nt_forward; ++
dt)
288 active_t_slices[
t % Lt] =
true;
292 for(
int dt=0;
dt < Nt_backward; ++
dt)
295 while (
t < 0) {
t += Lt;}
297 active_t_slices[
t % Lt] =
true;
300 return active_t_slices;
306 std::list<KeyPropElementalOperator_t> getSnkKeys(
int t_source,
int spin_source,
int Nt_forward,
int Nt_backward,
const std::string mass)
308 std::list<KeyPropElementalOperator_t> keys;
310 std::vector<bool> active_t_slices = getActiveTSlices(
t_source, Nt_forward, Nt_backward);
312 const int decay_dir =
Nd-1;
313 const int Lt = Layout::lattSize()[decay_dir];
315 for(
int spin_sink=0; spin_sink < Ns; ++spin_sink)
317 for(
int t=0;
t < Lt; ++
t)
319 if (! active_t_slices[
t]) {
continue;}
341 namespace InlinePropAndMatElemDistillationEnv
348 return new InlineMeas(Params(xml_in, path));
379 XMLReader paramtop(xml_in, path);
381 if (paramtop.count(
"Frequency") == 1)
393 if (paramtop.count(
"xml_file") != 0)
400 QDPIO::cerr << __func__ <<
": Caught Exception reading XML: " << e << std::endl;
418 push(xml_out,
"PropDistillation");
419 write(xml_out,
"update_no", update_no);
420 write(xml_out,
"xml_file", xml_file);
423 XMLFileWriter xml(xml_file);
424 func(update_no, xml);
428 func(update_no, xml_out);
445 multi1d<LatticeColorMatrix>
u;
446 XMLBufferWriter gauge_xml;
452 catch( std::bad_cast )
454 QDPIO::cerr <<
name <<
": caught dynamic cast error" << std::endl;
459 QDPIO::cerr <<
name <<
": std::map call failed: " << e << std::endl;
463 push(xml_out,
"PropDistillation");
464 write(xml_out,
"update_no", update_no);
466 QDPIO::cout <<
name <<
": propagator calculation" << std::endl;
474 write(xml_out,
"Config_info", gauge_xml);
476 push(xml_out,
"Output_version");
477 write(xml_out,
"out_version", 1);
481 MesPlq(xml_out,
"Observables",
u);
485 const int Lt = Layout::lattSize()[decay_dir];
488 if (decay_dir !=
Nd-1)
490 QDPIO::cerr <<
name <<
": TimeSliceIO only supports decay_dir= " <<
Nd-1 <<
"\n";
504 QDPIO::cout <<
"Snarf the source from a std::map object disk file" << std::endl;
520 QDPIO::cout <<
"Get user data" << std::endl;
529 catch (std::bad_cast) {
530 QDPIO::cerr <<
name <<
": caught dynamic cast error" << std::endl;
534 QDPIO::cerr <<
name <<
": error extracting source_header: " << e << std::endl;
537 catch(
const char* e) {
538 QDPIO::cerr <<
name <<
": Caught some char* exception:" << std::endl;
539 QDPIO::cerr << e << std::endl;
540 QDPIO::cerr <<
"Rethrowing" << std::endl;
544 QDPIO::cout <<
"Source successfully read and parsed" << std::endl;
551 QDPIO::cerr <<
name <<
": number of available eigenvectors is too small\n";
556 QDPIO::cout <<
"Number of vecs available is large enough" << std::endl;
559 QDPIO::cout <<
"Initialize sub-lattice std::map" << std::endl;
561 QDPIO::cout <<
"Finished initializing sub-lattice std::map" << std::endl;
574 XMLBufferWriter file_xml;
575 push(file_xml,
"DBMetaData");
577 write(file_xml,
"lattSize", QDP::Layout::lattSize());
581 write(file_xml,
"Config_info", gauge_xml);
583 write(file_xml,
"Weights", readEigVals(eigen_meta_data));
587 qdp_db.setMaxUserInfoLen(file_str.size());
591 qdp_db.insertUserdata(file_str);
598 QDPIO::cout <<
"Finished opening peram file" << std::endl;
611 QDPIO::cout <<
"Try the various factories" << std::endl;
614 typedef LatticeFermion
T;
615 typedef multi1d<LatticeColorMatrix>
P;
616 typedef multi1d<LatticeColorMatrix>
Q;
622 XMLReader fermacttop(xml_s);
636 QDPIO::cout <<
"Suitable factory found: compute all the quark props" << std::endl;
639 #ifdef BUILD_JIT_CONTRACTION_KERNELS
641 QDPIO::cout <<
"Using JIT contraction kernels (fused timeloop)\n";
643 QDPIO::cout <<
"Using JIT contraction kernels (non-fused timeloop)\n";
655 for(
int tt=0; tt < t_sources.size(); ++tt)
658 QDPIO::cout <<
"t_source = " <<
t_source << std::endl;
661 for(
int spin_source=0; spin_source < Ns; ++spin_source)
663 QDPIO::cout <<
"spin_source = " << spin_source << std::endl;
666 std::list<KeyPropElementalOperator_t> snk_keys(getSnkKeys(
t_source,
674 QDP::MapObjectMemory<KeyPropElementalOperator_t, ValPropElementalOperator_t> peram;
677 for(std::list<KeyPropElementalOperator_t>::const_iterator key = snk_keys.begin();
678 key != snk_keys.end();
683 peram.insert(*key,
tmp);
685 peram[*key].mat.resize(num_vecs,num_vecs);
686 peram[*key].mat =
zero;
688 QDPIO::cout <<
"peram initialized! " << std::endl;
693 for(
int colorvec_src=0; colorvec_src < num_vecs; ++colorvec_src)
702 QDPIO::cout <<
"Do spin_source= " << spin_source <<
" colorvec_src= " << colorvec_src << std::endl;
705 LatticeColorVector vec_srce =
zero;
709 vec_srce = sub_eigen_map.getVec(
t_source, colorvec_src);
716 multi1d<LatticeColorVector> ferm_out(Ns);
723 LatticeFermion quark_soln =
zero;
742 if (toDouble(res.
resid) > 1.0e-3)
744 QDPIO::cerr <<
name <<
": have a resid > 1.0e-3. That is unacceptable" << std::endl;
749 if (isfinite(quark_soln))
756 QDPIO::cerr <<
name <<
": WARNING - found something not finite, may retry\n";
764 QDPIO::cerr <<
name <<
": this is bad - did not get a finite solution std::vector after num_tries= "
771 for(
int spin_sink=0; spin_sink < Ns; ++spin_sink)
773 ferm_out(spin_sink) = peekSpin(quark_soln, spin_sink);
777 QDPIO::cout <<
"Time to compute prop for spin_source= " << spin_source <<
" colorvec_src= " << colorvec_src <<
" time = "
778 << snarss1.getTimeInSeconds()
779 <<
" secs" << std::endl;
784 #ifndef BUILD_JIT_CONTRACTION_KERNELS
788 for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
789 key != snk_keys.end();
792 if (key->t_slice !=
t_slice) {
continue;}
795 for(
int colorvec_sink=0; colorvec_sink < num_vecs; ++colorvec_sink)
797 peram[*key].mat(colorvec_sink,colorvec_src) =
innerProduct(sub_eigen_map.getVec(
t_slice, colorvec_sink),
798 ferm_out(key->spin_snk));
808 for(
int spin_snk = 0; spin_snk < Ns; ++spin_snk)
811 for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin(); key != snk_keys.end(); ++key)
813 if (key->spin_snk != spin_snk) {
continue;}
819 multi1d<SubLatticeColorVectorF*> vec_ptr(
count );
820 multi1d<ComplexD*> contr_ptr(
count );
825 for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
826 key != snk_keys.end();
829 if (key->spin_snk != spin_snk) {
continue;}
834 for (
int i=0 ;
i < num_vecs ; ++
i ) {
835 vec_ptr[run_count] =
const_cast<SubLatticeColorVectorF*
>( &sub_eigen_map.getVec( key->t_slice ,
i ) );
836 contr_ptr[run_count] = &peram[*key].mat(
i , colorvec_src );
844 multi_innerProduct( contr_ptr , vec_ptr , ferm_out(spin_snk) );
856 for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
857 key != snk_keys.end();
860 if (key->t_slice !=
t_slice) {
continue;}
864 multi1d<SubLatticeColorVectorF*> vec_ptr( num_vecs );
865 multi1d<ComplexD*> contr_ptr( num_vecs );
866 for (
int i=0 ;
i < num_vecs ; ++
i ) {
867 vec_ptr[
i] =
const_cast<SubLatticeColorVectorF*
>( &sub_eigen_map.getVec(
t_slice ,
i ) );
868 contr_ptr[
i] = &peram[*key].mat(
i , colorvec_src );
874 multi_innerProduct( contr_ptr , vec_ptr , ferm_out(key->spin_snk) );
881 QDPIO::cout <<
"Time to compute and assemble peram for spin_source= " << spin_source <<
" colorvec_src= " << colorvec_src <<
" time = "
882 << sniss1.getTimeInSeconds()
884 <<
" (for contraction: " << sniss1.getTimeInSeconds() - snarss1.getTimeInSeconds() <<
")"
892 QDPIO::cout <<
"Write perambulator for spin_source= " << spin_source <<
" to disk" << std::endl;
898 for(std::list<KeyPropElementalOperator_t>::const_iterator key= snk_keys.begin();
899 key != snk_keys.end();
903 qdp_db.insert(*key, peram[*key]);
908 QDPIO::cout <<
"Time to write perambulators for spin_src= " << spin_source <<
" time = "
909 << sniss2.getTimeInSeconds()
910 <<
" secs" << std::endl;
918 QDPIO::cout <<
"Propagators computed: time= "
919 << swatch.getTimeInSeconds()
920 <<
" secs" << std::endl;
924 QDPIO::cout <<
name <<
": caught exception around qprop: " << e << std::endl;
928 push(xml_out,
"Relaxation_Iterations");
929 write(xml_out,
"ncg_had", ncg_had);
935 QDPIO::cout <<
name <<
": total time = "
936 << snoop.getTimeInSeconds()
937 <<
" secs" << std::endl;
939 QDPIO::cout <<
name <<
": ran successfully" << std::endl;
Inline measurement factory.
Class for counted reference semantics.
void operator()(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
void func(const unsigned long update_no, XMLWriter &xml_out)
Do the measurement.
Serializable value harness.
Builds time slice subsets.
const Set & getSet() const
The set to be used in sumMulti.
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.
void read(XMLReader &xml, const std::string &path, AsqtadFermActParams ¶m)
Read parameters.
void proginfo(XMLWriter &xml)
Print out basic information about this program.
std::string makeXMLFileName(std::string xml_file, unsigned long update_no)
Return a xml file name for inline measurements.
TimeSliceSet time_slice_set
MODS_t & eigen_source
Eigenvectors.
SUB_MOD_t 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.
Named object function std::map.
static bool registered
Local registration flag.
multi1d< LatticeColorMatrix > P
BinaryReturn< C1, C2, FnInnerProduct >::Type_t innerProduct(const QDPSubType< T1, C1 > &s1, const QDPType< T2, C2 > &s2)
QDP::MapObjectDiskMultiple< KeyTimeSliceColorVec_t, TimeSliceIO< LatticeColorVectorF > > MODS_t
QDP::MapObjectMemory< KeyTimeSliceColorVec_t, SubLatticeColorVectorF > SUB_MOD_t
bool registerAll()
Register all the factories.
void write(XMLWriter &xml, const std::string &path, const Params::NamedObject_t &input)
Propagator output.
void read(XMLReader &xml, const std::string &path, Params::NamedObject_t &input)
Propagator input.
QDP::MapObjectDisk< KeyTimeSliceColorVec_t, TimeSliceIO< LatticeColorVectorF > > MOD_t
bool registerAll()
Register all the factories.
Asqtad Staggered-Dirac operator.
static multi1d< LatticeColorMatrix > u
LinOpSysSolverMGProtoClover::Q Q
push(xml_out,"Condensates")
LinOpSysSolverMGProtoClover::T T
multi1d< LatticeFermion > chi(Ncb)
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
const WilsonTypeFermAct< multi1d< LatticeFermion > > & S_f
Print out basic info about this program.
Fourier transform phase factor support.
Sparse matrix representation of spin matrices.
std::vector< std::string > colorvec_files
Holds return info from SystemSolver call.
Holds of vectors and weights.
Convenience for building time-slice subsets.
Contraction operators for two quarks.