48 #include <qdp-lapack.h>
49 #include <qdp_config.h>
56 namespace InlineDiscoEigCGEnv{
85 XMLReader paramtop(xml, path);
88 read(paramtop,
"version", version);
105 QDPIO::cerr <<
"Input parameter version " << version <<
" unsupported." << std::endl;
116 write(xml,
"version", version);
121 push(xml,
"FermionAction");
125 for(
int t(0);
t<param.
chi.size();
t++){
127 xml<<param.
chi[
t].xml;
138 XMLReader inputtop(xml, path);
142 if ( inputtop.count(
"evecs_file")!=0 )
170 XMLReader paramtop(xml_in, path);
172 if (paramtop.count(
"Frequency") == 1)
184 if (paramtop.count(
"xml_file") != 0)
191 QDPIO::cerr << __func__ <<
": Caught Exception reading XML: " << e << std::endl;
224 return ((
a.t_slice<
b.t_slice)||(
a.mom<
b.mom)||(
a.disp<
b.disp));
229 os <<
"KeyOperator_t:"
230 <<
" t_slice = " <<
d.t_slice
232 for (
int i=0;
i<
d.disp.size();
i++)
233 os <<
d.disp[
i] <<
" " ;
236 for (
int i=0;
i<
d.mom.size();
i++)
237 os <<
d.mom[
i] <<
" " ;
246 multi1d<ComplexD>
op ;
255 os <<
"ValOperator_t:\n";
256 for (
int i=0;
i<
d.op.size();
i++)
257 os <<
" gamma["<<
i<<
"] = "<<
d.op[
i] << std::endl ;
270 unsigned short int n ;
280 unsigned short int n ;
298 StandardOutputStream&
operator<<(StandardOutputStream& os,
const multi1d<short int>&
d){
301 for(
int i=1;
i <
d.size();
i++)
314 typedef LatticeFermion
T;
315 typedef multi1d<LatticeColorMatrix>
P;
316 typedef multi1d<LatticeColorMatrix>
Q;
323 std::istringstream xml_s(param.
action.
xml);
324 XMLReader fermacttop(xml_s);
325 QDPIO::cout <<
"FermAct = " << param.
action.
id << std::endl;
331 QDPIO::cout <<
"Try the various Wilson fermion factories" << std::endl;
337 state = Sf->createState(
u);
338 QDPIO::cout <<
"Suitable factory found: compute the trace quark prop"<<std::endl;
342 <<
": caught exception instantiating the action: " << e << std::endl;
356 else if(param.
action.
id ==
"CLOVER"){
361 QDPIO::cout<<
name<<
" : Tough luck dude! No code for you..."<<std::endl ;
370 multi1d<Complex>
HU ;
375 void do_disco(std::map< KeyOperator_t, ValOperator_t >& db,
376 const LatticeFermion& qbar,
377 const LatticeFermion&
q,
380 const multi1d<short int>& path,
381 const int& max_path_length ){
382 QDPIO::cout<<
" Computing Operator with path length "<<path.size()
383 <<
" on timeslice "<<
t<<
". Path: "<<path <<std::endl;
386 std::pair<KeyOperator_t, ValOperator_t> kv ;
389 kv.first.disp.resize(1);
390 kv.first.disp[0] = 0 ;
393 kv.first.disp = path ;
395 multi1d< multi1d<ComplexD> > foo(
p.numMom()) ;
396 for (
int m(0);
m <
p.numMom();
m++)
397 foo[
m].resize(Ns*Ns);
398 for(
int g(0);g<Ns*Ns;g++){
400 for (
int m(0);
m <
p.numMom();
m++){
401 foo[
m][g] =
sum(
p[
m]*cc,
p.getSet()[
t]);
404 for (
int m(0);
m <
p.numMom();
m++){
405 for(
int i(0);
i<(
Nd-1);
i++)
406 kv.first.mom[
i] =
p.numToMom(
m)[
i] ;
408 kv.second.op = foo[
m];
409 std::pair<std::map< KeyOperator_t, ValOperator_t >::iterator,
bool> itbo;
411 itbo = db.insert(kv);
413 QDPIO::cout<<
"Inserting new entry in std::map\n";
416 for(
int i(0);
i<kv.second.op.size();
i++)
417 itbo.first->second.op[
i] += kv.second.op[
i] ;
421 if(path.size()<max_path_length){
422 QDPIO::cout<<
" attempt to add new path. "
423 <<
" current path length is : "<<path.size();
424 multi1d<short int> new_path(path.size()+1);
425 QDPIO::cout<<
" new path length is : "<<new_path.size()<<std::endl;
426 for(
int i(0);
i<path.size();
i++)
427 new_path[
i] = path[
i] ;
428 for(
int sign(-1);sign<2;sign+=2)
430 new_path[path.size()]= sign*(
mu+1) ;
432 bool back_track=false ;
434 if(path[path.size()-1] == -new_path[path.size()])
437 QDPIO::cout<<
" Added path: "<<new_path<<std::endl;
438 LatticeFermion q_mu ;
444 do_disco(db, qbar, q_mu,
p,
t, new_path, max_path_length);
451 void do_disco(std::map< KeyOperator_t, ValOperator_t >& db,
453 multi1d<LatticeFermion>& vec,
460 const multi1d<short int>& path){
462 QDPIO::cout<<
" Computing Operator with path length "<<path.size()
463 <<
" on timeslice "<<
t<<
". Path: "<<path <<std::endl;
468 std::pair<KeyOperator_t, ValOperator_t> kv ;
472 kv.first.disp.resize(1);
473 kv.first.disp[0] = 0 ;
476 kv.first.disp = path ;
478 int ldb = vec.size();
482 multi2d<Complex> B(Nrhs,ldb);
511 multi1d< multi1d<ComplexD> > foo(
p.numMom()) ;
512 for (
int m(0);
m <
p.numMom();
m++){
513 foo[
m].resize(Ns*Ns);
517 multi1d< LatticeFermion > Svec(ldb);
518 multi1d< LatticeFermion > DDvec(ldb);
519 multi1d< LatticeFermion > DDSvec(ldb);
522 for(
int i(0);
i<ldb;
i++){
523 LatticeFermion qtmp =
zero ;
525 Doo->evenOddLinOp(qtmp, vec[
i],
PLUS);
526 Doo->evenEvenInvLinOp(DDvec[
i], qtmp,
PLUS);
529 Doo->oddOddLinOp(qtmp,vec[
i],
PLUS);
530 LatticeFermion qtmp2 =
zero;
531 Doo->evenOddLinOp(qtmp2,qtmp,
MINUS);
532 Doo->evenEvenInvLinOp(DDSvec[
i],qtmp2,
MINUS);
534 Doo->oddOddLinOp(Svec[
i],vec[
i],
PLUS);
537 for(
int g(0);g<Ns*Ns;g++){
538 for (
int m(0);
m <
p.numMom();
m++){
539 for (
int i(0);
i<ldb;
i++){
540 for (
int j(0);
j<ldb;
j++){
543 B[
i][
j] =
sum(
p[
m]*(cc1+cc2),trb) ;
548 #if BASE_PRECISION == 32
549 int r = QDPLapack::cpotrs(
U, Clsk.
Nvec, Nrhs, Clsk.
HU, Clsk.
ldh, B, ldb,
info);
551 int r = QDPLapack::zpotrs(
U, Clsk.
Nvec, Nrhs, Clsk.
HU, Clsk.
ldh, B, ldb,
info);
556 QDPIO::cout<<
"do_disco cpotrs r = "<<
r<<std::endl;
557 QDPIO::cout<<
"do_disco cpotrs info = "<<
info<<std::endl;
559 for (
int i(0);
i<ldb;
i++){
560 foo[
m][g] += ComplexD(B[
i][
i]);
564 for (
int m(0);
m <
p.numMom();
m++){
565 for(
int i(0);
i<(
Nd-1);
i++)
566 kv.first.mom[
i] =
p.numToMom(
m)[
i] ;
568 kv.second.op = foo[
m];
570 std::pair<std::map< KeyOperator_t, ValOperator_t >::iterator,
bool> itbo;
572 itbo = db.insert(kv);
573 if( !(itbo.second) ){
574 for(
int i(0);
i<kv.second.op.size();
i++)
575 itbo.first->second.op[
i] += kv.second.op[
i] ;
578 QDPIO::cout<<
"Inserting new entry in std::map\n";
581 if(path.size()<max_path_length){
582 QDPIO::cout<<
" attempt to add new path. "
583 <<
" current path length is : "<<path.size();
584 multi1d<short int> new_path(path.size()+1);
585 QDPIO::cout<<
" new path length is : "<<new_path.size()<<std::endl;
586 for(
int i(0);
i<path.size();
i++)
587 new_path[
i] = path[
i] ;
588 for(
int sign(-1);sign<2;sign+=2)
590 new_path[path.size()]= sign*(
mu+1) ;
592 bool back_track=false ;
594 if(path[path.size()-1] == -new_path[path.size()])
597 QDPIO::cout<<
" Added path: "<<new_path<<std::endl;
598 multi1d<LatticeFermion> vec_mu(vec.size()) ;
599 for(
int j(0);
j<vec.size();
j++){
605 do_disco(db, Clsk , vec_mu, param, Doo,
u,
t, trb,
p, new_path);
616 QDPIO::cout<<
name<<
" : Reading vecs from "
617 << evecs_file <<std::endl ;
626 QDPFileReader to(file_xml,evecs_file,QDPIO_SERIAL);
627 read(file_xml,
"/OptEigInfo/ncurEvals", Nvecs);
628 read(file_xml,
"/OptEigInfo/ldh", ldh);
633 Clsk.
evals.resize(ldh);
634 Clsk.
H.resize(ldh*ldh);
635 Clsk.
HU.resize(ldh*ldh);
637 for(
int v(0);v<Nvecs;v++){
638 XMLReader record_xml;
639 read(to, record_xml, vec[v]);
642 XMLReader record_xml;
644 read(to, record_xml, Clsk.
H);
645 read(to, record_xml, Clsk.
HU);
647 QDPIO::cout<<
name<<
" : Time to read vecs= "
648 << swatch.getTimeInSeconds() <<
" secs "<<std::endl ;
653 void PRchi(multi1d<multi1d< multi1d<LatticeFermion> > >& quarkstilde,
661 int ldb = vec.size();
667 for(
int n(0);
n<quarks.size();
n++){
668 for (
int it(0) ;
it < quarks[
n]->getNumTimeSlices() ; ++
it){
669 int t = quarks[
n]->getT0(
it) ;
670 int Nrhs = quarks[
n]->getDilSize(
it) ;
671 multi2d<Complex> B(Nrhs, ldb);
672 for(
int i(0);
i<ldb;
i++){
673 for(
int j = 0 ;
j < Nrhs ;
j++){
682 LatticeFermion qsrc = quarks[
n]->dilutedSource(
it,
j);
683 LatticeFermion SdagSchi =
zero ;
684 Doo->oddOddLinOp(SdagSchi,qsrc,
MINUS);
693 #if BASE_PRECISION == 32
694 int r = QDPLapack::cpotrs(
U, Clsk.
Nvec, Nrhs, Clsk.
HU, Clsk.
ldh, B, ldb,
info);
696 int r = QDPLapack::zpotrs(
U, Clsk.
Nvec, Nrhs, Clsk.
HU, Clsk.
ldh, B, ldb,
info);
698 QDPIO::cout<<
"PRchi cpotrs r = "<<
r<<std::endl;
699 QDPIO::cout<<
"PRchi cpotrs info = "<<
info<<std::endl;
701 for(
int j = 0 ;
j < Nrhs ;
j++){
702 LatticeFermion vB =
zero;
703 LatticeFermion
q = quarks[
n]->dilutedSolution(
it,
j);
704 for(
int i(0);
i<ldb;
i++)
705 vB += B[
j][
i]*vec[
i];
706 quarkstilde[
n][
it][
j] =
q - vB;
707 std::cout<<
"Norm of PRchi: "<<norm2(quarkstilde[
n][
it][
j])<<std::endl;
716 void PRchi(multi1d<multi1d< multi1d<LatticeFermion> > >& quarkstilde,
719 for(
int n(0);
n<quarks.size();
n++){
720 for (
int it(0) ;
it < quarks[
n]->getNumTimeSlices() ;
it++){
721 for (
int j(0) ;
j < quarks[
n]->getDilSize(
it) ;
j++){
722 quarkstilde[
n][
it][
j] = quarks[
n]->dilutedSolution(
it,
j);
740 push(xml_out,
"discoEigCG");
741 write(xml_out,
"update_no", update_no);
742 write(xml_out,
"xml_file", xml_file);
745 XMLFileWriter xml(xml_file);
746 func(update_no, xml);
749 func(update_no, xml_out);
769 XMLBufferWriter gauge_xml;
775 catch( std::bad_cast )
783 QDPIO::cerr <<
name <<
": std::map call failed: " << e
787 const multi1d<LatticeColorMatrix>&
u =
790 push(xml_out,
"discoEigCG");
791 write(xml_out,
"update_no", update_no);
793 QDPIO::cout <<
name <<
": Disconnected diagrams with eigCG vectors" << std::endl;
801 write(xml_out,
"Config_info", gauge_xml);
803 push(xml_out,
"Output_version");
804 write(xml_out,
"out_version", 1);
809 MesPlq(xml_out,
"Observables",
u);
824 multi1d< Handle< DilutionScheme<LatticeFermion> > > quarks(
N_quarks);
830 std::istringstream xml_d(dil_xml.
xml);
831 XMLReader diltop(xml_d);
832 QDPIO::cout <<
"Dilution type = " << dil_xml.
id << std::endl;
840 QDPIO::cerr <<
name <<
": Caught Exception constructing dilution scheme: " << e << std::endl;
851 if (quarks[0]->getCfgInfo() != quarks[
n]->getCfgInfo()){
852 QDPIO::cerr <<
name <<
" : Quarks do not contain the same cfg info";
853 QDPIO::cerr <<
", quark "<<
n << std::endl;
865 write(top,
"Config_info", gauge_xml);
867 XMLReader from2(from,
"/Config_info");
868 std::ostringstream os;
873 if (cfgInfo != quarks[0]->getCfgInfo()){
874 QDPIO::cerr <<
name <<
" : Quarks do not contain the same";
875 QDPIO::cerr <<
" cfg info as the gauge field." ;
876 QDPIO::cerr <<
"gauge: XX"<<cfgInfo<<
"XX quarks: XX" ;
877 QDPIO::cerr << quarks[0]->getCfgInfo()<<
"XX"<< std::endl;
882 int decay_dir = quarks[0]->getDecayDir();
894 for(
int n = 1 ;
n < quarks.size();
n++){
895 if(toBool(quarks[
n]->getSeed()==quarks[0]->getSeed())){
896 QDPIO::cerr <<
name <<
": error, quark seeds are the same" << std::endl;
900 if(toBool(quarks[
n]->getDecayDir()!=quarks[0]->getDecayDir())){
901 QDPIO::cerr<<
name<<
": error, quark decay dirs do not match" <<std::endl;
910 multi1d<LatticeFermion> vec;
915 std::map< KeyOperator_t, ValOperator_t > data ;
917 multi1d<multi1d< multi1d<LatticeFermion> > > quarkstilde(quarks.size());
918 for(
int n(0);
n<quarks.size();
n++){
919 quarkstilde[
n].resize(quarks[
n]->getNumTimeSlices());
920 for (
int it(0) ;
it < quarks[
n]->getNumTimeSlices() ;
it++){
921 quarkstilde[
n][
it].resize(quarks[
n]->getDilSize(
it));
932 PRchi(quarkstilde, quarks);
934 for(
int n(0);
n<quarks.size();
n++){
935 for (
int it(0) ;
it < quarks[
n]->getNumTimeSlices() ;
it++){
936 int t = quarks[
n]->getT0(
it) ;
937 QDPIO::cout<<
" Doing quark: "<<
n <<std::endl ;
938 QDPIO::cout<<
" quark: "<<
n <<
" has "<<quarks[
n]->getDilSize(
it);
939 QDPIO::cout<<
" dilutions on time slice "<<
t <<std::endl ;
940 for(
int i = 0 ;
i < quarks[
n]->getDilSize(
it) ;
i++){
941 QDPIO::cout<<
" Doing dilution : "<<
i<<std::endl ;
942 multi1d<short int>
d ;
944 LatticeFermion qbar = quarks[
n]->dilutedSource(
it,
i);
945 LatticeFermion
q = quarkstilde[
n][
it][
i];
946 QDPIO::cout<<
" Starting recursion "<<std::endl ;
950 QDPIO::cout<<
" done with recursion! "
951 <<
" The length of the path is: "<<
d.size()<<std::endl ;
953 QDPIO::cout<<
" Done with dilutions for quark: "<<
n <<std::endl ;
961 std::map< KeyOperator_t, ValOperator_t >::iterator
it;
963 for(
it=data.begin();
it!=data.end();
it++){
964 key.
key() =
it->first ;
965 val.
data().op.resize(
it->second.op.size()) ;
966 for(
int i(0);
i<
it->second.op.size();
i++){
967 val.
data().op[
i] =
it->second.op[
i]/toDouble(quarks.size());
976 for (
int it(0) ;
it < quarks[0]->getNumTimeSlices() ;
it++){
977 multi1d<short int>
d ;
978 int t = quarks[0]->getT0(
it) ;
979 QDPIO::cout<<
" Starting recursion again"<<std::endl ;
983 QDPIO::cout<<
" done with recursion! "
984 <<
" The length of the path is: "<<
d.size()<<std::endl ;
994 XMLBufferWriter file_xml;
996 push(file_xml,
"DBMetaData");
998 write(file_xml,
"lattSize", QDP::Layout::lattSize());
999 write(file_xml,
"decay_dir", decay_dir);
1001 write(file_xml,
"Config_info", gauge_xml);
1005 qdp_db.setMaxUserInfoLen(file_str.size());
1009 qdp_db.insertUserdata(file_str);
1013 for(
it=data.begin();
it!=data.end();
it++){
1014 key.
key() =
it->first ;
1015 val.
data().op.resize(
it->second.op.size()) ;
1018 for(
int i(0);
i<
it->second.op.size();
i++)
1019 val.
data().op[
i] =
it->second.op[
i];
1020 qdp_db.insert(key,val) ;
1027 QDPIO::cout <<
name <<
": total time = "
1028 << snoop.getTimeInSeconds()
1029 <<
" secs" << std::endl;
1031 QDPIO::cout <<
name <<
": ran successfully" << std::endl;
Inline measurement factory.
Heavy Baryon (Qll) 2-pt function : Orginos and Savage.
Baryon spin and projector matrices.
Factory for producing baryon operators.
Even-odd preconditioned Clover-Dirac operator.
Even-odd preconditioned linear operator.
Even-odd preconditioned Wilson-Dirac operator.
Class for counted reference semantics.
Inline measurement of stochastic baryon operators.
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.
Serializable key harness.
Fourier transform phase factor support.
Parameters for Clover fermion action.
Random Z(N) source construction using dilution.
All dilution scheme factories.
Factory for dilution schemes.
Parallel transport a lattice field.
Even-odd const determinant Wilson-like fermact.
Fermion action factories.
All Wilson-type fermion actions.
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.
multi1d< GroupXML_t > readXMLArrayGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
GroupXML_t readXMLGroup(XMLReader &xml_in, const std::string &path, const std::string &type_name)
Read group and return as a std::string.
Class for counted reference semantics.
Inline measurement of stochastic 3pt functions.
void savern(int iseed[4])
Named object function std::map.
static bool registered
Local registration flag.
bool operator<(const KeyOperator_t &a, const KeyOperator_t &b)
bool registerAll()
Register all the factories.
void PRchi(multi1d< multi1d< multi1d< LatticeFermion > > > &quarkstilde, const multi1d< Handle< DilutionScheme< LatticeFermion > > > &quarks, Handle< EvenOddPrecLinearOperator< T, P, Q > > &Doo, CholeskyFactors Clsk, multi1d< LatticeFermion > &vec, const Params::Param_t ¶m, const P &u)
multi1d< LatticeColorMatrix > P
void read(XMLReader &xml, const std::string &path, Params::Param_t ¶m)
void do_disco(std::map< KeyOperator_t, ValOperator_t > &db, const LatticeFermion &qbar, const LatticeFermion &q, const SftMom &p, const int &t, const multi1d< short int > &path, const int &max_path_length)
Handle< EvenOddPrecLinearOperator< T, P, Q > > createOddOdd_Op(const Params::Param_t ¶m, const P &u)
void write(XMLWriter &xml, const std::string &path, const Params::Param_t ¶m)
std::ostream & operator<<(std::ostream &os, const KeyOperator_t &d)
multi1d< LatticeColorMatrix > Q
void ReadOPTEigCGVecs(multi1d< LatticeFermion > &vec, CholeskyFactors &Clsk, const std::string &evecs_file)
QDPSubTypeTrait< typename BinaryReturn< C1, C2, FnLocalInnerProduct >::Type_t >::Type_t localInnerProduct(const QDPSubType< T1, C1 > &l, const QDPType< T2, C2 > &r)
const int N_quarks
Number of quarks to be used in this construction.
Asqtad Staggered-Dirac operator.
for(cb=0;cb< Ncb;++cb) cp+
static multi1d< LatticeColorMatrix > u
push(xml_out,"Condensates")
void MesPlq(const multi1d< LatticeColorMatrixF3 > &u, multi2d< Double > &plane_plaq, Double &link)
const WilsonTypeFermAct< multi1d< LatticeFermion > > Handle< const ConnectState > state
Print out basic info about this program.
All quark smearing constructors.
Factory for producing quark smearing objects.
Fourier transform phase factor support.
All make sink constructors.
Factory for producing quark prop sinks.
Factory for producing quark smearing objects.
Params for clover ferm acts.
Hold group xml and type id.
multi1d< short int > disp
unsigned short int t_slice
SerialDBData< ValOperator_t > v
SerialDBKey< KeyOperator_t > k
multi1d< GroupXML_t > chi
struct Chroma::InlineDiscoEigCGEnv::Params::NamedObject_t named_obj
struct Chroma::InlineDiscoEigCGEnv::Params::Param_t param
void write(XMLWriter &xml_out, const std::string &path)
Params for wilson ferm acts.
multi1d< LatticeColorMatrix > U
Wilson fermion action parameters.
Volume source of Z(N) noise.