1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-14 01:35:36 +00:00

CG test written and passes i.e. converges with small true residual

in RedBlack MpcDagMpc, Unprec MdagM and Schur red black solver for
each of.

DomainWallFermion
MobiusFermion
MobiusZolotarevFermion
ScaledShamirFermion
ScaledShamirZolotarevFermion
This commit is contained in:
Peter Boyle 2015-06-03 10:54:03 +01:00
parent 260011670e
commit 84b5c7217d
30 changed files with 241 additions and 74 deletions

View File

@ -6,24 +6,24 @@ AM_LDFLAGS = -L$(top_builddir)/lib
# Test code # Test code
# #
bin_PROGRAMS = \ bin_PROGRAMS = \
Grid_comms \ Benchmark_comms \
Grid_memory_bandwidth \ Benchmark_memory_bandwidth \
Grid_su3 \ Benchmark_su3 \
Grid_wilson \ Benchmark_wilson \
Grid_dwf Benchmark_dwf
Grid_comms_SOURCES = Grid_comms.cc Benchmark_comms_SOURCES = Benchmark_comms.cc
Grid_comms_LDADD = -lGrid Benchmark_comms_LDADD = -lGrid
Grid_memory_bandwidth_SOURCES = Grid_memory_bandwidth.cc Benchmark_memory_bandwidth_SOURCES = Benchmark_memory_bandwidth.cc
Grid_memory_bandwidth_LDADD = -lGrid Benchmark_memory_bandwidth_LDADD = -lGrid
Grid_su3_SOURCES = Grid_su3.cc Grid_su3_test.cc Grid_su3_expr.cc Benchmark_su3_SOURCES = Benchmark_su3.cc Benchmark_su3_test.cc Benchmark_su3_expr.cc
Grid_su3_LDADD = -lGrid Benchmark_su3_LDADD = -lGrid
Grid_wilson_SOURCES = Grid_wilson.cc Benchmark_wilson_SOURCES = Benchmark_wilson.cc
Grid_wilson_LDADD = -lGrid Benchmark_wilson_LDADD = -lGrid
Grid_dwf_SOURCES = Grid_dwf.cc Benchmark_dwf_SOURCES = Benchmark_dwf.cc
Grid_dwf_LDADD = -lGrid Benchmark_dwf_LDADD = -lGrid

View File

@ -5,85 +5,88 @@ AM_LDFLAGS = -L$(top_builddir)/lib
# #
# Test code # Test code
# #
bin_PROGRAMS = Grid_main \ bin_PROGRAMS = Test_main \
Grid_simd \ Test_simd \
Grid_gamma \ Test_gamma \
Grid_cshift \ Test_cshift \
Grid_cshift_red_black \ Test_cshift_red_black \
Grid_stencil \ Test_stencil \
Grid_nersc_io \ Test_nersc_io \
Grid_rng \ Test_rng \
Grid_remez \ Test_remez \
Grid_rng_fixed \ Test_rng_fixed \
Grid_wilson_evenodd \ Test_wilson_evenodd \
Grid_wilson_cg_unprec \ Test_wilson_cg_unprec \
Grid_wilson_cg_prec \ Test_wilson_cg_prec \
Grid_wilson_cg_schur \ Test_wilson_cg_schur \
Grid_dwf_even_odd\ Test_dwf_even_odd\
Grid_dwf_cg_unprec\ Test_dwf_cg_unprec\
Grid_dwf_cg_prec\ Test_dwf_cg_prec\
Grid_dwf_cg_schur\ Test_dwf_cg_schur\
Grid_any_evenodd Test_many_evenodd\
Test_many_cg
Grid_main_SOURCES = Grid_main.cc Test_main_SOURCES = Test_main.cc
Grid_main_LDADD = -lGrid Test_main_LDADD = -lGrid
Grid_rng_SOURCES = Grid_rng.cc Test_rng_SOURCES = Test_rng.cc
Grid_rng_LDADD = -lGrid Test_rng_LDADD = -lGrid
Grid_rng_fixed_SOURCES = Grid_rng_fixed.cc Test_rng_fixed_SOURCES = Test_rng_fixed.cc
Grid_rng_fixed_LDADD = -lGrid Test_rng_fixed_LDADD = -lGrid
Grid_remez_SOURCES = Grid_remez.cc Test_remez_SOURCES = Test_remez.cc
Grid_remez_LDADD = -lGrid Test_remez_LDADD = -lGrid
Grid_nersc_io_SOURCES = Grid_nersc_io.cc Test_nersc_io_SOURCES = Test_nersc_io.cc
Grid_nersc_io_LDADD = -lGrid Test_nersc_io_LDADD = -lGrid
Grid_cshift_SOURCES = Grid_cshift.cc Test_cshift_SOURCES = Test_cshift.cc
Grid_cshift_LDADD = -lGrid Test_cshift_LDADD = -lGrid
Grid_cshift_red_black_SOURCES = Grid_cshift_red_black.cc Test_cshift_red_black_SOURCES = Test_cshift_red_black.cc
Grid_cshift_red_black_LDADD = -lGrid Test_cshift_red_black_LDADD = -lGrid
Grid_gamma_SOURCES = Grid_gamma.cc Test_gamma_SOURCES = Test_gamma.cc
Grid_gamma_LDADD = -lGrid Test_gamma_LDADD = -lGrid
Grid_stencil_SOURCES = Grid_stencil.cc Test_stencil_SOURCES = Test_stencil.cc
Grid_stencil_LDADD = -lGrid Test_stencil_LDADD = -lGrid
Grid_simd_SOURCES = Grid_simd.cc Test_simd_SOURCES = Test_simd.cc
Grid_simd_LDADD = -lGrid Test_simd_LDADD = -lGrid
#Grid_simd_new_SOURCES = Grid_simd_new.cc #Test_simd_new_SOURCES = Test_simd_new.cc
#Grid_simd_new_LDADD = -lGrid #Test_simd_new_LDADD = -lGrid
Grid_wilson_evenodd_SOURCES = Grid_wilson_evenodd.cc Test_wilson_evenodd_SOURCES = Test_wilson_evenodd.cc
Grid_wilson_evenodd_LDADD = -lGrid Test_wilson_evenodd_LDADD = -lGrid
Grid_any_evenodd_SOURCES = Grid_any_evenodd.cc Test_wilson_cg_unprec_SOURCES = Test_wilson_cg_unprec.cc
Grid_any_evenodd_LDADD = -lGrid Test_wilson_cg_unprec_LDADD = -lGrid
Grid_wilson_cg_unprec_SOURCES = Grid_wilson_cg_unprec.cc Test_wilson_cg_prec_SOURCES = Test_wilson_cg_prec.cc
Grid_wilson_cg_unprec_LDADD = -lGrid Test_wilson_cg_prec_LDADD = -lGrid
Grid_wilson_cg_prec_SOURCES = Grid_wilson_cg_prec.cc Test_wilson_cg_schur_SOURCES = Test_wilson_cg_schur.cc
Grid_wilson_cg_prec_LDADD = -lGrid Test_wilson_cg_schur_LDADD = -lGrid
Grid_wilson_cg_schur_SOURCES = Grid_wilson_cg_schur.cc Test_dwf_even_odd_SOURCES = Test_dwf_even_odd.cc
Grid_wilson_cg_schur_LDADD = -lGrid Test_dwf_even_odd_LDADD = -lGrid
Grid_dwf_even_odd_SOURCES = Grid_dwf_even_odd.cc Test_dwf_cg_unprec_SOURCES = Test_dwf_cg_unprec.cc
Grid_dwf_even_odd_LDADD = -lGrid Test_dwf_cg_unprec_LDADD = -lGrid
Grid_dwf_cg_unprec_SOURCES = Grid_dwf_cg_unprec.cc Test_dwf_cg_prec_SOURCES = Test_dwf_cg_prec.cc
Grid_dwf_cg_unprec_LDADD = -lGrid Test_dwf_cg_prec_LDADD = -lGrid
Grid_dwf_cg_prec_SOURCES = Grid_dwf_cg_prec.cc Test_dwf_cg_schur_SOURCES = Test_dwf_cg_schur.cc
Grid_dwf_cg_prec_LDADD = -lGrid Test_dwf_cg_schur_LDADD = -lGrid
Grid_dwf_cg_schur_SOURCES = Grid_dwf_cg_schur.cc Test_many_evenodd_SOURCES = Test_many_evenodd.cc
Grid_dwf_cg_schur_LDADD = -lGrid Test_many_evenodd_LDADD = -lGrid
Test_many_cg_SOURCES = Test_many_cg.cc
Test_many_cg_LDADD = -lGrid

164
tests/Test_many_cg.cc Normal file
View File

@ -0,0 +1,164 @@
#include <Grid.h>
using namespace std;
using namespace Grid;
using namespace Grid::QCD;
template<class d>
struct scal {
d internal;
};
Gamma::GammaMatrix Gmu [] = {
Gamma::GammaX,
Gamma::GammaY,
Gamma::GammaZ,
Gamma::GammaT
};
template<class What>
void TestCGinversions(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5);
template<class What>
void TestCGschur(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5);
template<class What>
void TestCGunprec(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5);
template<class What>
void TestCGprec(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5);
int main (int argc, char ** argv)
{
Grid_init(&argc,&argv);
int threads = GridThread::GetThreads();
std::cout << "Grid is setup to use "<<threads<<" threads"<<std::endl;
const int Ls=8;
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplexF::Nsimd()),GridDefaultMpi());
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid);
GridRedBlackCartesian * FrbGrid = SpaceTimeGrid::makeFiveDimRedBlackGrid(Ls,UGrid);
std::vector<int> seeds4({1,2,3,4});
std::vector<int> seeds5({5,6,7,8});
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5);
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
LatticeGaugeField Umu(UGrid); random(RNG4,Umu);
std::vector<LatticeColourMatrix> U(4,UGrid);
RealD mass=0.1;
RealD M5 =1.8;
std::cout <<"DomainWallFermion test"<<std::endl;
DomainWallFermion Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
TestCGinversions<DomainWallFermion>(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5);
RealD b=1.5;// Scale factor b+c=2, b-c=1
RealD c=0.5;
std::cout <<"MobiusFermion test"<<std::endl;
MobiusFermion Dmob(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,b,c);
TestCGinversions<MobiusFermion>(Dmob,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5);
std::cout <<"MobiusZolotarevFermion test"<<std::endl;
MobiusZolotarevFermion Dzolo(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,b,c,0.1,2.0);
TestCGinversions<MobiusZolotarevFermion>(Dzolo,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5);
std::cout <<"ScaledShamirFermion test"<<std::endl;
ScaledShamirFermion Dsham(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,2.0);
TestCGinversions<ScaledShamirFermion>(Dsham,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5);
std::cout <<"ScaledShamirZolotarevFermion test"<<std::endl;
ScaledShamirZolotarevFermion Dshamz(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5,2.0,0.1,2.0);
TestCGinversions<ScaledShamirZolotarevFermion>(Dshamz,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5);
Grid_finalize();
}
template<class What>
void TestCGinversions(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5)
{
std::cout << "Testing unpreconditioned inverter"<<std::endl;
TestCGunprec<What>(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5);
std::cout << "Testing red black preconditioned inverter"<<std::endl;
TestCGprec<What>(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5);
std::cout << "Testing red black Schur inverter"<<std::endl;
TestCGschur<What>(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5);
}
template<class What>
void TestCGunprec(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5)
{
LatticeFermion src (FGrid); random(*RNG5,src);
LatticeFermion result(FGrid); result=zero;
HermitianOperator<What,LatticeFermion> HermOp(Ddwf);
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
CG(HermOp,src,result);
}
template<class What>
void TestCGprec(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5)
{
LatticeFermion src (FGrid); random(*RNG5,src);
LatticeFermion src_o(FrbGrid);
LatticeFermion result_o(FrbGrid);
pickCheckerboard(Odd,src_o,src);
result_o=zero;
HermitianCheckerBoardedOperator<What,LatticeFermion> HermOpEO(Ddwf);
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
CG(HermOpEO,src_o,result_o);
}
template<class What>
void TestCGschur(What & Ddwf,
GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid,
GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid,
RealD mass, RealD M5,
GridParallelRNG *RNG4,
GridParallelRNG *RNG5)
{
LatticeFermion src (FGrid); random(*RNG5,src);
LatticeFermion result(FGrid); result=zero;
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
SchurRedBlackSolve<LatticeFermion> SchurSolver(CG);
SchurSolver(Ddwf,src,result);
}