mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-10 07:55:35 +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:
parent
c659c76053
commit
2b083ca987
@ -6,24 +6,24 @@ AM_LDFLAGS = -L$(top_builddir)/lib
|
||||
# Test code
|
||||
#
|
||||
bin_PROGRAMS = \
|
||||
Grid_comms \
|
||||
Grid_memory_bandwidth \
|
||||
Grid_su3 \
|
||||
Grid_wilson \
|
||||
Grid_dwf
|
||||
Benchmark_comms \
|
||||
Benchmark_memory_bandwidth \
|
||||
Benchmark_su3 \
|
||||
Benchmark_wilson \
|
||||
Benchmark_dwf
|
||||
|
||||
Grid_comms_SOURCES = Grid_comms.cc
|
||||
Grid_comms_LDADD = -lGrid
|
||||
Benchmark_comms_SOURCES = Benchmark_comms.cc
|
||||
Benchmark_comms_LDADD = -lGrid
|
||||
|
||||
Grid_memory_bandwidth_SOURCES = Grid_memory_bandwidth.cc
|
||||
Grid_memory_bandwidth_LDADD = -lGrid
|
||||
Benchmark_memory_bandwidth_SOURCES = Benchmark_memory_bandwidth.cc
|
||||
Benchmark_memory_bandwidth_LDADD = -lGrid
|
||||
|
||||
Grid_su3_SOURCES = Grid_su3.cc Grid_su3_test.cc Grid_su3_expr.cc
|
||||
Grid_su3_LDADD = -lGrid
|
||||
Benchmark_su3_SOURCES = Benchmark_su3.cc Benchmark_su3_test.cc Benchmark_su3_expr.cc
|
||||
Benchmark_su3_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_SOURCES = Grid_wilson.cc
|
||||
Grid_wilson_LDADD = -lGrid
|
||||
Benchmark_wilson_SOURCES = Benchmark_wilson.cc
|
||||
Benchmark_wilson_LDADD = -lGrid
|
||||
|
||||
Grid_dwf_SOURCES = Grid_dwf.cc
|
||||
Grid_dwf_LDADD = -lGrid
|
||||
Benchmark_dwf_SOURCES = Benchmark_dwf.cc
|
||||
Benchmark_dwf_LDADD = -lGrid
|
||||
|
||||
|
@ -5,85 +5,88 @@ AM_LDFLAGS = -L$(top_builddir)/lib
|
||||
#
|
||||
# Test code
|
||||
#
|
||||
bin_PROGRAMS = Grid_main \
|
||||
Grid_simd \
|
||||
Grid_gamma \
|
||||
Grid_cshift \
|
||||
Grid_cshift_red_black \
|
||||
Grid_stencil \
|
||||
Grid_nersc_io \
|
||||
Grid_rng \
|
||||
Grid_remez \
|
||||
Grid_rng_fixed \
|
||||
Grid_wilson_evenodd \
|
||||
Grid_wilson_cg_unprec \
|
||||
Grid_wilson_cg_prec \
|
||||
Grid_wilson_cg_schur \
|
||||
Grid_dwf_even_odd\
|
||||
Grid_dwf_cg_unprec\
|
||||
Grid_dwf_cg_prec\
|
||||
Grid_dwf_cg_schur\
|
||||
Grid_any_evenodd
|
||||
bin_PROGRAMS = Test_main \
|
||||
Test_simd \
|
||||
Test_gamma \
|
||||
Test_cshift \
|
||||
Test_cshift_red_black \
|
||||
Test_stencil \
|
||||
Test_nersc_io \
|
||||
Test_rng \
|
||||
Test_remez \
|
||||
Test_rng_fixed \
|
||||
Test_wilson_evenodd \
|
||||
Test_wilson_cg_unprec \
|
||||
Test_wilson_cg_prec \
|
||||
Test_wilson_cg_schur \
|
||||
Test_dwf_even_odd\
|
||||
Test_dwf_cg_unprec\
|
||||
Test_dwf_cg_prec\
|
||||
Test_dwf_cg_schur\
|
||||
Test_many_evenodd\
|
||||
Test_many_cg
|
||||
|
||||
|
||||
|
||||
Grid_main_SOURCES = Grid_main.cc
|
||||
Grid_main_LDADD = -lGrid
|
||||
Test_main_SOURCES = Test_main.cc
|
||||
Test_main_LDADD = -lGrid
|
||||
|
||||
Grid_rng_SOURCES = Grid_rng.cc
|
||||
Grid_rng_LDADD = -lGrid
|
||||
Test_rng_SOURCES = Test_rng.cc
|
||||
Test_rng_LDADD = -lGrid
|
||||
|
||||
Grid_rng_fixed_SOURCES = Grid_rng_fixed.cc
|
||||
Grid_rng_fixed_LDADD = -lGrid
|
||||
Test_rng_fixed_SOURCES = Test_rng_fixed.cc
|
||||
Test_rng_fixed_LDADD = -lGrid
|
||||
|
||||
Grid_remez_SOURCES = Grid_remez.cc
|
||||
Grid_remez_LDADD = -lGrid
|
||||
Test_remez_SOURCES = Test_remez.cc
|
||||
Test_remez_LDADD = -lGrid
|
||||
|
||||
Grid_nersc_io_SOURCES = Grid_nersc_io.cc
|
||||
Grid_nersc_io_LDADD = -lGrid
|
||||
Test_nersc_io_SOURCES = Test_nersc_io.cc
|
||||
Test_nersc_io_LDADD = -lGrid
|
||||
|
||||
Grid_cshift_SOURCES = Grid_cshift.cc
|
||||
Grid_cshift_LDADD = -lGrid
|
||||
Test_cshift_SOURCES = Test_cshift.cc
|
||||
Test_cshift_LDADD = -lGrid
|
||||
|
||||
Grid_cshift_red_black_SOURCES = Grid_cshift_red_black.cc
|
||||
Grid_cshift_red_black_LDADD = -lGrid
|
||||
Test_cshift_red_black_SOURCES = Test_cshift_red_black.cc
|
||||
Test_cshift_red_black_LDADD = -lGrid
|
||||
|
||||
Grid_gamma_SOURCES = Grid_gamma.cc
|
||||
Grid_gamma_LDADD = -lGrid
|
||||
Test_gamma_SOURCES = Test_gamma.cc
|
||||
Test_gamma_LDADD = -lGrid
|
||||
|
||||
Grid_stencil_SOURCES = Grid_stencil.cc
|
||||
Grid_stencil_LDADD = -lGrid
|
||||
Test_stencil_SOURCES = Test_stencil.cc
|
||||
Test_stencil_LDADD = -lGrid
|
||||
|
||||
Grid_simd_SOURCES = Grid_simd.cc
|
||||
Grid_simd_LDADD = -lGrid
|
||||
Test_simd_SOURCES = Test_simd.cc
|
||||
Test_simd_LDADD = -lGrid
|
||||
|
||||
#Grid_simd_new_SOURCES = Grid_simd_new.cc
|
||||
#Grid_simd_new_LDADD = -lGrid
|
||||
#Test_simd_new_SOURCES = Test_simd_new.cc
|
||||
#Test_simd_new_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_evenodd_SOURCES = Grid_wilson_evenodd.cc
|
||||
Grid_wilson_evenodd_LDADD = -lGrid
|
||||
Test_wilson_evenodd_SOURCES = Test_wilson_evenodd.cc
|
||||
Test_wilson_evenodd_LDADD = -lGrid
|
||||
|
||||
Grid_any_evenodd_SOURCES = Grid_any_evenodd.cc
|
||||
Grid_any_evenodd_LDADD = -lGrid
|
||||
Test_wilson_cg_unprec_SOURCES = Test_wilson_cg_unprec.cc
|
||||
Test_wilson_cg_unprec_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_cg_unprec_SOURCES = Grid_wilson_cg_unprec.cc
|
||||
Grid_wilson_cg_unprec_LDADD = -lGrid
|
||||
Test_wilson_cg_prec_SOURCES = Test_wilson_cg_prec.cc
|
||||
Test_wilson_cg_prec_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_cg_prec_SOURCES = Grid_wilson_cg_prec.cc
|
||||
Grid_wilson_cg_prec_LDADD = -lGrid
|
||||
Test_wilson_cg_schur_SOURCES = Test_wilson_cg_schur.cc
|
||||
Test_wilson_cg_schur_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_cg_schur_SOURCES = Grid_wilson_cg_schur.cc
|
||||
Grid_wilson_cg_schur_LDADD = -lGrid
|
||||
Test_dwf_even_odd_SOURCES = Test_dwf_even_odd.cc
|
||||
Test_dwf_even_odd_LDADD = -lGrid
|
||||
|
||||
Grid_dwf_even_odd_SOURCES = Grid_dwf_even_odd.cc
|
||||
Grid_dwf_even_odd_LDADD = -lGrid
|
||||
Test_dwf_cg_unprec_SOURCES = Test_dwf_cg_unprec.cc
|
||||
Test_dwf_cg_unprec_LDADD = -lGrid
|
||||
|
||||
Grid_dwf_cg_unprec_SOURCES = Grid_dwf_cg_unprec.cc
|
||||
Grid_dwf_cg_unprec_LDADD = -lGrid
|
||||
Test_dwf_cg_prec_SOURCES = Test_dwf_cg_prec.cc
|
||||
Test_dwf_cg_prec_LDADD = -lGrid
|
||||
|
||||
Grid_dwf_cg_prec_SOURCES = Grid_dwf_cg_prec.cc
|
||||
Grid_dwf_cg_prec_LDADD = -lGrid
|
||||
Test_dwf_cg_schur_SOURCES = Test_dwf_cg_schur.cc
|
||||
Test_dwf_cg_schur_LDADD = -lGrid
|
||||
|
||||
Grid_dwf_cg_schur_SOURCES = Grid_dwf_cg_schur.cc
|
||||
Grid_dwf_cg_schur_LDADD = -lGrid
|
||||
Test_many_evenodd_SOURCES = Test_many_evenodd.cc
|
||||
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
164
tests/Test_many_cg.cc
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user