/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_general_coarse_hdcg.cc Copyright (C) 2023 Author: Peter Boyle This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. See the full license in the file "LICENSE" in the top level distribution directory *************************************************************************************/ /* END LEGAL */ #include #include #include #include using namespace std; using namespace Grid; template void SaveBasis(aggregation &Agg,std::string file) { #ifdef HAVE_LIME emptyUserRecord record; ScidacWriter WR(Agg.FineGrid->IsBoss()); WR.open(file); for(int b=0;b void LoadBasis(aggregation &Agg, std::string file) { #ifdef HAVE_LIME emptyUserRecord record; ScidacReader RD ; RD.open(file); for(int b=0;b void SaveEigenvectors(std::vector &eval, std::vector &evec, std::string evec_file, std::string eval_file) { #ifdef HAVE_LIME emptyUserRecord record; ScidacWriter WR(evec[0].Grid()->IsBoss()); WR.open(evec_file); for(int b=0;b void LoadEigenvectors(std::vector &eval, std::vector &evec, std::string evec_file, std::string eval_file) { #ifdef HAVE_LIME XmlReader RDx(eval_file); read(RDx,"evals",eval); emptyUserRecord record; Grid::ScidacReader RD ; RD.open(evec_file); assert(evec.size()==eval.size()); for(int k=0;k class HermOpAdaptor : public LinearOperatorBase { LinearOperatorBase & wrapped; public: HermOpAdaptor(LinearOperatorBase &wrapme) : wrapped(wrapme) {}; void Op (const Field &in, Field &out) { wrapped.HermOp(in,out); } void HermOp(const Field &in, Field &out) { wrapped.HermOp(in,out); } void AdjOp (const Field &in, Field &out){ wrapped.HermOp(in,out); } void OpDiag (const Field &in, Field &out) { assert(0); } void OpDir (const Field &in, Field &out,int dir,int disp) { assert(0); } void OpDirAll (const Field &in, std::vector &out) { assert(0); }; void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){ assert(0); } }; template class CGSmoother : public LinearFunction { public: using LinearFunction::operator(); typedef LinearOperatorBase FineOperator; FineOperator & _SmootherOperator; int iters; CGSmoother(int _iters, FineOperator &SmootherOperator) : _SmootherOperator(SmootherOperator), iters(_iters) { std::cout << GridLogMessage<<" Mirs smoother order "< CG(0.0,iters,false); // non-converge is just fine in a smoother out=Zero(); CG(_SmootherOperator,in,out); } }; int main (int argc, char ** argv) { Grid_init(&argc,&argv); const int Ls=24; const int nbasis = 60; const int cb = 0 ; RealD mass=0.00078; RealD M5=1.8; RealD b=1.5; RealD c=0.5; GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplex::Nsimd()), GridDefaultMpi()); GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid); GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid); GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid); // Construct a coarsened grid with 4^4 cell // Coordinate Block({4,4,6,4}); Coordinate Block({4,4,4,4}); Coordinate clatt = GridDefaultLatt(); for(int d=0;d seeds4({1,2,3,4}); std::vector seeds5({5,6,7,8}); std::vector cseeds({5,6,7,8}); GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5); GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds); ///////////////////////// Configuration ///////////////////////////////// LatticeGaugeField Umu(UGrid); FieldMetaData header; std::string file("/lustre/orion/phy157/proj-shared/phy157_dwf/lehner/ensemble-Ha/ckpoint_lat.2250"); NerscIO::readConfiguration(Umu,header,file); //////////////////////// Fermion action ////////////////////////////////// MobiusFermionD Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,b,c); SchurDiagMooeeOperator HermOpEO(Ddwf); typedef HermOpAdaptor HermFineMatrix; HermFineMatrix FineHermOp(HermOpEO); //////////////////////////////////////////////////////////// ///////////// Coarse basis and Little Dirac Operator /////// //////////////////////////////////////////////////////////// typedef GeneralCoarsenedMatrix LittleDiracOperator; typedef LittleDiracOperator::CoarseVector CoarseVector; NextToNextToNextToNearestStencilGeometry5D geom(Coarse5d); typedef Aggregation Subspace; Subspace Aggregates(Coarse5d,FrbGrid,cb); //////////////////////////////////////////////////////////// // Need to check about red-black grid coarsening //////////////////////////////////////////////////////////// // std::string subspace_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/Subspace.phys96.mixed.2500.60"); std::string subspace_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/Refine.phys96.mixed.2500.60"); std::string refine_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/Refine.phys96.mixed.2500.60_v2"); std::string ldop_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/LittleDiracOp.phys96.mixed.60"); std::string evec_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/evecs.scidac"); std::string eval_file("/lustre/orion/phy157/proj-shared/phy157_dwf/paboyle/eval.xml"); bool load_agg=true; bool load_refine=true; bool load_mat=false; bool load_evec=false; int refine=1; if ( load_agg ) { if ( !(refine) || (!load_refine) ) { LoadBasis(Aggregates,subspace_file); } } else { Aggregates.CreateSubspaceChebyshevNew(RNG5,HermOpEO,95.); SaveBasis(Aggregates,subspace_file); } if ( load_refine ) { std::cout << " Load Refine "<< refine_file < MultiGeneralCoarsenedMatrix_t; MultiGeneralCoarsenedMatrix_t mrhs(geom,CoarseMrhs); /////////////////////// // Deflation guesser object /////////////////////// MultiRHSDeflation MrhsGuesser; ////////////////////////////////////////// // Block projector for coarse/fine ////////////////////////////////////////// MultiRHSBlockProject MrhsProjector; std::cout << "**************************************"< MrhsHermMatrix; // Chebyshev IRLCheby(0.0012,42.0,301); // 4.4.6.4 // Chebyshev IRLCheby(0.0012,42.0,501); // for 4.4.4.4 blocking 350 evs // Chebyshev IRLCheby(0.0014,42.0,501); // for 4.4.4.4 blocking 700 evs // Chebyshev IRLCheby(0.002,42.0,501); // for 4.4.4.4 blocking 1226 evs // Chebyshev IRLCheby(0.0025,42.0,501); // for 4.4.4.4 blocking 1059 evs // 3e-4,2); Chebyshev IRLCheby(0.0018,42.0,301); // for 4.4.4.4 blocking // 790 evs MrhsHermMatrix MrhsCoarseOp (mrhs); CoarseVector pm_src(CoarseMrhs); pm_src = ComplexD(1.0); PowerMethod cPM; cPM(MrhsCoarseOp,pm_src); // int Nk=nrhs*30; // 4.4.6.4 // int Nk=nrhs*80; int Nk=nrhs*60; // 720 int Nm=Nk*4; // 2880 ; generally finishes at 1440 int Nstop=512; int Nconv_test_interval=1; ImplicitlyRestartedBlockLanczosCoarse IRL(MrhsCoarseOp, Coarse5d, CoarseMrhs, nrhs, IRLCheby, Nstop, Nconv_test_interval, nrhs, Nk, Nm, 3e-4,2); std::vector eval(Nm); std::vector evec(Nm,Coarse5d); std::vector c_src(nrhs,Coarse5d); std::cout << "**************************************"< CG(7.5e-2,maxit,false); RealD lo=2.0; int ord = 7; DoNothingGuesser DoNothing; HPDSolver HPDSolveMrhs(MrhsCoarseOp,CG,DoNothing); HPDSolver HPDSolveMrhsRefine(MrhsCoarseOp,CG,DoNothing); ///////////////////////////////////////////////// // Mirs smoother ///////////////////////////////////////////////// RealD MirsShift = lo; ShiftedHermOpLinearOperator ShiftedFineHermOp(HermOpEO,MirsShift); CGSmoother CGsmooth(ord,ShiftedFineHermOp) ; TwoLevelADEF2mrhs HDCGmrhs(1.0e-8, 500, FineHermOp, CGsmooth, HPDSolveMrhs, // Used in M1 HPDSolveMrhs, // Used in Vstart MrhsProjector, MrhsGuesser, CoarseMrhs); std::vector src_mrhs(nrhs,FrbGrid); std::vector res_mrhs(nrhs,FrbGrid); for(int r=0;r CGfine(1.0e-8,30000,false); CGfine(HermOpEO, src, result); } #endif Grid_finalize(); return 0; }