diff --git a/lib/algorithms/iterative/ImplicitlyRestartedBlockLanczos.h b/lib/algorithms/iterative/ImplicitlyRestartedBlockLanczos.h index 71aa2891..2de35244 100644 --- a/lib/algorithms/iterative/ImplicitlyRestartedBlockLanczos.h +++ b/lib/algorithms/iterative/ImplicitlyRestartedBlockLanczos.h @@ -33,10 +33,12 @@ Author: Guido Cossu #include //memset -#define clog std::cout << GridLogMessage +#define Glog std::cout << GridLogMessage namespace Grid { +enum class LanczosType { irbl, rbl }; + ///////////////////////////////////////////////////////////// // Implicitly restarted block lanczos ///////////////////////////////////////////////////////////// @@ -53,6 +55,7 @@ private: int Nm; // total number of vectors int Nblock_k; // Nk/Nu int Nblock_m; // Nm/Nu + int Nconv_test_interval; // Number of skipped vectors when checking a convergence RealD eresid; IRLdiagonalisation diagonalisation; //////////////////////////////////// @@ -69,6 +72,7 @@ public: ImplicitlyRestartedBlockLanczos(LinearOperatorBase &Linop, // op OperatorFunction & poly, // polynomial int _Nstop, // really sought vecs + int _Nconv_test_interval, // conv check interval int _Nu, // vecs in the unit block int _Nk, // sought vecs int _Nm, // total vecs @@ -76,7 +80,8 @@ public: int _MaxIter, // Max iterations IRLdiagonalisation _diagonalisation = IRLdiagonaliseWithEigen) : _Linop(Linop), _poly(poly), - Nstop(_Nstop), Nu(_Nu), Nk(_Nk), Nm(_Nm), + Nstop(_Nstop), Nconv_test_interval(_Nconv_test_interval), + Nu(_Nu), Nk(_Nk), Nm(_Nm), Nblock_m(_Nm/_Nu), Nblock_k(_Nk/_Nu), //eresid(_eresid), MaxIter(10), eresid(_eresid), MaxIter(_MaxIter), @@ -117,30 +122,45 @@ public: } normalize(w); } - + void calc(std::vector& eval, std::vector& evec, - const std::vector& src, int& Nconv) + const std::vector& src, int& Nconv, LanczosType Impl) { - std::string fname = std::string(cname+"::calc()"); + switch (Impl) { + case LanczosType::irbl: + calc_irbl(eval,evec,src,Nconv); + break; + + case LanczosType::rbl: + calc_rbl(eval,evec,src,Nconv); + break; + } + } + + void calc_irbl(std::vector& eval, + std::vector& evec, + const std::vector& src, int& Nconv) + { + std::string fname = std::string(cname+"::calc_irbl()"); GridBase *grid = evec[0]._grid; assert(grid == src[0]._grid); assert( Nu = src.size() ); - clog << std::string(74,'*') << std::endl; - clog << fname + " starting iteration 0 / "<< MaxIter<< std::endl; - clog << std::string(74,'*') << std::endl; - clog <<" -- seek Nk = "<< Nk <<" vectors"<< std::endl; - clog <<" -- accept Nstop = "<< Nstop <<" vectors"<< std::endl; - clog <<" -- total Nm = "<< Nm <<" vectors"<< std::endl; - clog <<" -- size of eval = "<< eval.size() << std::endl; - clog <<" -- size of evec = "<< evec.size() << std::endl; + Glog << std::string(74,'*') << std::endl; + Glog << fname + " starting iteration 0 / "<< MaxIter<< std::endl; + Glog << std::string(74,'*') << std::endl; + Glog <<" -- seek Nk = "<< Nk <<" vectors"<< std::endl; + Glog <<" -- accept Nstop = "<< Nstop <<" vectors"<< std::endl; + Glog <<" -- total Nm = "<< Nm <<" vectors"<< std::endl; + Glog <<" -- size of eval = "<< eval.size() << std::endl; + Glog <<" -- size of evec = "<< evec.size() << std::endl; if ( diagonalisation == IRLdiagonaliseWithEigen ) { - clog << "Diagonalisation is Eigen "<< std::endl; + Glog << "Diagonalisation is Eigen "<< std::endl; } else { abort(); } - clog << std::string(74,'*') << std::endl; + Glog << std::string(74,'*') << std::endl; assert(Nm == evec.size() && Nm == eval.size()); @@ -167,10 +187,10 @@ public: // set initial vector for (int i=0; iNk ) { - clog <<" #Apply shifted QR transformations "<& eval, + std::vector& evec, + const std::vector& src, int& Nconv) + { + std::string fname = std::string(cname+"::calc_rbl()"); + GridBase *grid = evec[0]._grid; + assert(grid == src[0]._grid); + assert( Nu = src.size() ); + + int Np = (Nm-Nk); + if (Np > 0 && MaxIter > 1) Np /= MaxIter; + int Nblock_p = Np/Nu; + + Glog << std::string(74,'*') << std::endl; + Glog << fname + " starting iteration 0 / "<< MaxIter<< std::endl; + Glog << std::string(74,'*') << std::endl; + Glog <<" -- seek (min) Nk = "<< Nk <<" vectors"<< std::endl; + Glog <<" -- seek (inc) Np = "<< Np <<" vectors"<< std::endl; + Glog <<" -- seek (max) Nm = "<< Nm <<" vectors"<< std::endl; + Glog <<" -- accept Nstop = "<< Nstop <<" vectors"<< std::endl; + Glog <<" -- size of eval = "<< eval.size() << std::endl; + Glog <<" -- size of evec = "<< evec.size() << std::endl; + if ( diagonalisation == IRLdiagonaliseWithEigen ) { + Glog << "Diagonalisation is Eigen "<< std::endl; + } else { + abort(); + } + Glog << std::string(74,'*') << std::endl; + + assert(Nm == evec.size() && Nm == eval.size()); + + std::vector> lmd(Nu,std::vector(Nm,0.0)); + std::vector> lme(Nu,std::vector(Nm,0.0)); + std::vector> lmd2(Nu,std::vector(Nm,0.0)); + std::vector> lme2(Nu,std::vector(Nm,0.0)); + std::vector eval2(Nk); + std::vector resid(Nm); + + Eigen::MatrixXcd Qt = Eigen::MatrixXcd::Zero(Nm,Nm); + Eigen::MatrixXcd Q = Eigen::MatrixXcd::Zero(Nm,Nm); + + std::vector Iconv(Nm); + std::vector B(Nm,grid); // waste of space replicating + + std::vector f(Nu,grid); + std::vector f_copy(Nu,grid); + Field v(grid); + + Nconv = 0; + + RealD beta_k; + + // set initial vector + for (int i=0; i omega; // ZMobius @@ -254,10 +285,6 @@ int main (int argc, char ** argv) ZMobiusFermionR Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,JP.omega,1.,0.,params); SchurDiagTwoOperator HermOp(Ddwf); - int Nu = JP.Nu; - int Nk = JP.Nk; - int Nm = Nk+JP.Np; - //std::vector Coeffs { 0.,-1.}; // ypj [note] this may not be supported by some compilers std::vector Coeffs({ 0.,-1.}); @@ -267,23 +294,23 @@ int main (int argc, char ** argv) // Cheb.csv(std::cout); ImplicitlyRestartedBlockLanczos IRBL(HermOp, Cheb, - JP.Nstop, - Nu,Nk,Nm, + JP.Nstop, JP.Ntest, + JP.Nu, JP.Nk, JP.Nm, JP.resid, JP.MaxIter); - std::vector eval(Nm); + std::vector eval(JP.Nm); - std::vector src(Nu,FrbGrid); - for ( int i=0; i src(JP.Nu,FrbGrid); + for ( int i=0; i evec(Nm,FrbGrid); + std::vector evec(JP.Nm,FrbGrid); for(int i=0;i<1;++i){ - std::cout << GridLogMessage << i <<" / "<< Nm <<" grid pointer "<< evec[i]._grid << std::endl; + std::cout << GridLogMessage << i <<" / "<< JP.Nm <<" grid pointer "<< evec[i]._grid << std::endl; }; int Nconv; - IRBL.calc(eval,evec,src,Nconv); + IRBL.calc(eval,evec,src,Nconv,JP.Impl); Grid_finalize();