mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-19 08:17:05 +01:00
Merge branch 'develop' of https://github.com/paboyle/Grid into feature/rmhmc
This commit is contained in:
@ -29,7 +29,6 @@ Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
;
|
||||
|
||||
template<class d>
|
||||
struct scal {
|
||||
@ -51,6 +50,7 @@ int main (int argc, char ** argv)
|
||||
|
||||
std::cout << GridLogMessage << "::::: NB: to enable a quick bit reproducibility check use the --checksums flag. " << std::endl;
|
||||
|
||||
{
|
||||
GridCartesian * UGrid = SpaceTimeGrid::makeFourDimGrid(GridDefaultLatt(), GridDefaultSimd(Nd,vComplexD::Nsimd()),GridDefaultMpi());
|
||||
GridRedBlackCartesian * UrbGrid = SpaceTimeGrid::makeFourDimRedBlackGrid(UGrid);
|
||||
GridCartesian * FGrid = SpaceTimeGrid::makeFiveDimGrid(Ls,UGrid);
|
||||
@ -100,6 +100,8 @@ int main (int argc, char ** argv)
|
||||
ConjugateGradient<LatticeFermionD> CG(1.0e-8,10000);
|
||||
CG(HermOpEO,src_o,result_o_2);
|
||||
|
||||
MemoryManager::Print();
|
||||
|
||||
LatticeFermionD diff_o(FrbGrid);
|
||||
RealD diff = axpy_norm(diff_o, -1.0, result_o, result_o_2);
|
||||
|
||||
@ -130,7 +132,9 @@ int main (int argc, char ** argv)
|
||||
std::cout << GridLogMessage << " CG checksums "<<std::hex << scidac_csuma << " "<<scidac_csumb<<std::endl;
|
||||
}
|
||||
#endif
|
||||
|
||||
}
|
||||
|
||||
MemoryManager::Print();
|
||||
|
||||
Grid_finalize();
|
||||
}
|
||||
|
@ -107,9 +107,8 @@ int main(int argc, char ** argv)
|
||||
// Implement a stencil code that should agree with cshift!
|
||||
for(int i=0;i<Check.Grid()->oSites();i++){
|
||||
auto SE = gStencil.GetEntry(0,i);
|
||||
auto check = Check.View();
|
||||
auto foo = Foo.View();
|
||||
|
||||
autoView(check, Check, CpuWrite);
|
||||
autoView( foo, Foo, CpuRead);
|
||||
// Encapsulate in a general wrapper
|
||||
check[i] = foo[SE->_offset]; auto tmp=check[i];
|
||||
if (SE->_permute & 0x1 ) { permute(check[i],tmp,0); tmp=check[i];}
|
||||
@ -147,8 +146,8 @@ int main(int argc, char ** argv)
|
||||
}}}}
|
||||
|
||||
if (nrm > 1.0e-4) {
|
||||
auto check = Check.View();
|
||||
auto bar = Bar.View();
|
||||
autoView( check , Check, CpuRead);
|
||||
autoView( bar , Bar, CpuRead);
|
||||
for(int i=0;i<check.size();i++){
|
||||
std::cout << i<<" Check "<<check[i]<< "\n"<<i<<" Bar "<<bar[i]<<std::endl;
|
||||
}
|
||||
|
@ -109,8 +109,8 @@ int main(int argc, char ** argv) {
|
||||
StencilEntry *SE;
|
||||
SE = myStencil.GetEntry(permute_type,0,i);
|
||||
|
||||
auto check = Check.View();
|
||||
auto foo = Foo.View();
|
||||
autoView( check , Check, CpuWrite);
|
||||
autoView( foo , Foo, CpuRead);
|
||||
if ( SE->_is_local && SE->_permute )
|
||||
permute(check[i],foo[SE->_offset],permute_type);
|
||||
else if (SE->_is_local)
|
||||
@ -151,8 +151,8 @@ int main(int argc, char ** argv) {
|
||||
}}}}
|
||||
|
||||
if (nrm > 1.0e-4) {
|
||||
auto check = Check.View();
|
||||
auto bar = Bar.View();
|
||||
autoView( check , Check, CpuRead);
|
||||
autoView( bar , Bar, CpuRead);
|
||||
for(int i=0;i<check.size();i++){
|
||||
std::cout << i<<" Check "<<check[i]<< "\n"<<i<<" Bar "<<bar[i]<<std::endl;
|
||||
}
|
||||
@ -210,8 +210,8 @@ int main(int argc, char ** argv) {
|
||||
SE = EStencil.GetEntry(permute_type,0,i);
|
||||
// std::cout << "Even source "<< i<<" -> " <<SE->_offset << " "<< SE->_is_local<<std::endl;
|
||||
|
||||
auto ocheck = OCheck.View();
|
||||
auto efoo = EFoo.View();
|
||||
autoView( ocheck , OCheck, CpuWrite);
|
||||
autoView( efoo , EFoo, CpuRead);
|
||||
if ( SE->_is_local && SE->_permute )
|
||||
permute(ocheck[i],efoo[SE->_offset],permute_type);
|
||||
else if (SE->_is_local)
|
||||
@ -226,8 +226,8 @@ int main(int argc, char ** argv) {
|
||||
SE = OStencil.GetEntry(permute_type,0,i);
|
||||
// std::cout << "ODD source "<< i<<" -> " <<SE->_offset << " "<< SE->_is_local<<std::endl;
|
||||
|
||||
auto echeck = ECheck.View();
|
||||
auto ofoo = OFoo.View();
|
||||
autoView( echeck , ECheck, CpuWrite);
|
||||
autoView( ofoo , OFoo, CpuRead);
|
||||
if ( SE->_is_local && SE->_permute )
|
||||
permute(echeck[i],ofoo[SE->_offset],permute_type);
|
||||
else if (SE->_is_local)
|
||||
|
@ -82,7 +82,7 @@ int main (int argc, char ** argv)
|
||||
pickCheckerboard(Odd,Uo,U);
|
||||
|
||||
// std::cout<<GridLogMessage << U<<std::endl;
|
||||
std::cout<<GridLogMessage<< U <<std::endl;
|
||||
// std::cout<<GridLogMessage<< U <<std::endl;
|
||||
std::cout<<GridLogMessage << "U " <<norm2(U)<<std::endl;
|
||||
std::cout<<GridLogMessage << "Ue " <<norm2(Ue)<<std::endl;
|
||||
std::cout<<GridLogMessage << "Uo " <<norm2(Uo)<<std::endl;
|
||||
|
@ -69,6 +69,7 @@ int main (int argc, char ** argv)
|
||||
|
||||
ShiftU = Cshift(U,dir,shift); // Shift everything
|
||||
|
||||
std::cout<<GridLogMessage<<"Shifted by "<<shift<<" in direction"<<dir<<" checking the AE35 unit" <<std::endl;
|
||||
/*
|
||||
std::cout << "U[0]" << U[0]<<std::endl;
|
||||
std::cout << "U[1]" << U[1]<<std::endl;
|
||||
|
@ -73,7 +73,7 @@ int main(int argc, char **argv) {
|
||||
omp_set_num_threads(omp);
|
||||
#endif
|
||||
|
||||
for (int lat = 8; lat <= 16; lat += 40) {
|
||||
for (int lat = 16; lat <= 16; lat += 40) {
|
||||
std::cout << "Lat " << lat << std::endl;
|
||||
|
||||
latt_size[0] = lat;
|
||||
@ -159,15 +159,17 @@ int main(int argc, char **argv) {
|
||||
LatticeColourMatrix newFoo = Foo;
|
||||
// confirm correctness of copy constructor
|
||||
Bar = Foo - newFoo;
|
||||
std::cout << "Copy constructor diff check: ";
|
||||
std::cout << "Copy constructor diff check: \n";
|
||||
double test_cc = norm2(Bar);
|
||||
if (test_cc < 1e-5){
|
||||
std::cout << "OK\n";
|
||||
}
|
||||
else{
|
||||
} else{
|
||||
std::cout << "Foo\n"<<Foo<<std::endl;
|
||||
std::cout << "newFoo\n"<<newFoo<<std::endl;
|
||||
std::cout << "Bar\n"<<Bar<<std::endl;
|
||||
std::cout << "fail\n";
|
||||
abort();
|
||||
}
|
||||
}
|
||||
|
||||
// Norm2 check
|
||||
LatticeReal BarReal(&Fine);
|
||||
|
@ -88,14 +88,15 @@ int main (int argc, char ** argv)
|
||||
// replicate across fifth dimension
|
||||
////////////////////////////////////
|
||||
LatticeGaugeField Umu5d(FGrid);
|
||||
auto umu5d = Umu5d.View();
|
||||
auto umu = Umu.View();
|
||||
for(int ss=0;ss<Umu.Grid()->oSites();ss++){
|
||||
for(int s=0;s<Ls;s++){
|
||||
umu5d[Ls*ss+s] = umu[ss];
|
||||
{
|
||||
autoView(umu5d, Umu5d, CpuWrite);
|
||||
autoView( umu, Umu , CpuRead);
|
||||
for(int ss=0;ss<Umu.Grid()->oSites();ss++){
|
||||
for(int s=0;s<Ls;s++){
|
||||
umu5d[Ls*ss+s] = umu[ss];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
std::vector<LatticeColourMatrix> U(4,FGrid);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
|
282
tests/core/Test_staggered_naive.cc
Normal file
282
tests/core/Test_staggered_naive.cc
Normal file
@ -0,0 +1,282 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./benchmarks/Benchmark_wilson.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 <Grid/Grid.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
;
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
Coordinate latt_size = GridDefaultLatt();
|
||||
Coordinate simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd());
|
||||
Coordinate mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(&Grid);
|
||||
|
||||
int threads = GridThread::GetThreads();
|
||||
std::cout<<GridLogMessage << "Grid is setup to use "<<threads<<" threads"<<std::endl;
|
||||
std::cout<<GridLogMessage << "Grid floating point word size is REALF"<< sizeof(RealF)<<std::endl;
|
||||
std::cout<<GridLogMessage << "Grid floating point word size is REALD"<< sizeof(RealD)<<std::endl;
|
||||
std::cout<<GridLogMessage << "Grid floating point word size is REAL"<< sizeof(Real)<<std::endl;
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
GridParallelRNG pRNG(&Grid);
|
||||
pRNG.SeedFixedIntegers(seeds);
|
||||
// pRNG.SeedFixedIntegers(std::vector<int>({45,12,81,9});
|
||||
|
||||
typedef typename NaiveStaggeredFermionR::FermionField FermionField;
|
||||
typedef typename NaiveStaggeredFermionR::ComplexField ComplexField;
|
||||
typename NaiveStaggeredFermionR::ImplParams params;
|
||||
|
||||
FermionField src (&Grid); random(pRNG,src);
|
||||
FermionField result(&Grid); result=Zero();
|
||||
FermionField ref(&Grid); ref=Zero();
|
||||
FermionField tmp(&Grid); tmp=Zero();
|
||||
FermionField err(&Grid); tmp=Zero();
|
||||
FermionField phi (&Grid); random(pRNG,phi);
|
||||
FermionField chi (&Grid); random(pRNG,chi);
|
||||
LatticeGaugeField Umu(&Grid); SU3::HotConfiguration(pRNG,Umu);
|
||||
std::vector<LatticeColourMatrix> U(4,&Grid);
|
||||
|
||||
|
||||
double volume=1;
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
volume=volume*latt_size[mu];
|
||||
}
|
||||
|
||||
// Only one non-zero (y)
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = PeekIndex<LorentzIndex>(Umu,mu);
|
||||
/* Debug force unit
|
||||
U[mu] = 1.0;
|
||||
PokeIndex<LorentzIndex>(Umu,U[mu],mu);
|
||||
*/
|
||||
}
|
||||
|
||||
ref = Zero();
|
||||
|
||||
RealD mass=0.1;
|
||||
RealD c1=9.0/8.0;
|
||||
RealD u0=1.0;
|
||||
|
||||
{ // Simple improved staggered implementation
|
||||
ref = Zero();
|
||||
RealD c1tad = 0.5*c1/u0;
|
||||
|
||||
Lattice<iScalar<vInteger> > coor(&Grid);
|
||||
|
||||
Lattice<iScalar<vInteger> > x(&Grid); LatticeCoordinate(x,0);
|
||||
Lattice<iScalar<vInteger> > y(&Grid); LatticeCoordinate(y,1);
|
||||
Lattice<iScalar<vInteger> > z(&Grid); LatticeCoordinate(z,2);
|
||||
Lattice<iScalar<vInteger> > t(&Grid); LatticeCoordinate(t,3);
|
||||
|
||||
Lattice<iScalar<vInteger> > lin_z(&Grid); lin_z=x+y;
|
||||
Lattice<iScalar<vInteger> > lin_t(&Grid); lin_t=x+y+z;
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
|
||||
// Staggered Phase.
|
||||
ComplexField phases(&Grid); phases=1.0;
|
||||
|
||||
if ( mu == 1 ) phases = where( mod(x ,2)==(Integer)0, phases,-phases);
|
||||
if ( mu == 2 ) phases = where( mod(lin_z,2)==(Integer)0, phases,-phases);
|
||||
if ( mu == 3 ) phases = where( mod(lin_t,2)==(Integer)0, phases,-phases);
|
||||
|
||||
tmp = PeriodicBC::CovShiftForward(U[mu],mu,src);
|
||||
ref = ref +c1tad*tmp*phases; // Forward 1 hop
|
||||
|
||||
tmp = PeriodicBC::CovShiftBackward(U[mu],mu,src);
|
||||
ref = ref -c1tad*tmp*phases; // Backward 1 hop
|
||||
|
||||
}
|
||||
// ref = ref + mass * src;
|
||||
}
|
||||
|
||||
NaiveStaggeredFermionR Ds(Umu,Grid,RBGrid,mass,c1,u0,params);
|
||||
|
||||
|
||||
std::cout<<GridLogMessage<<"=========================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Testing Dhop against cshift implementation "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=========================================================="<<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage << "Calling Ds"<<std::endl;
|
||||
int ncall=1000;
|
||||
double t0=usecond();
|
||||
for(int i=0;i<ncall;i++){
|
||||
Ds.Dhop(src,result,0);
|
||||
}
|
||||
double t1=usecond();
|
||||
double t2;
|
||||
double flops=(16*(3*(6+8+8)) + 15*3*2)*volume*ncall; // == 66*16 + == 1146
|
||||
|
||||
std::cout<<GridLogMessage << "Called Ds"<<std::endl;
|
||||
std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl;
|
||||
std::cout<<GridLogMessage << "norm ref "<< norm2(ref)<<std::endl;
|
||||
std::cout<<GridLogMessage << "mflop/s = "<< flops/(t1-t0)<<std::endl;
|
||||
|
||||
err = ref-result;
|
||||
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage<<"=========================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Testing that Deo + Doe = Dunprec "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=========================================================="<<std::endl;
|
||||
|
||||
FermionField src_e (&RBGrid);
|
||||
FermionField src_o (&RBGrid);
|
||||
FermionField r_e (&RBGrid);
|
||||
FermionField r_o (&RBGrid);
|
||||
FermionField r_eo (&Grid);
|
||||
pickCheckerboard(Even,src_e,src);
|
||||
pickCheckerboard(Odd,src_o,src);
|
||||
|
||||
Ds.Meooe(src_e,r_o); std::cout<<GridLogMessage<<"Applied Meo"<<std::endl;
|
||||
Ds.Meooe(src_o,r_e); std::cout<<GridLogMessage<<"Applied Moe"<<std::endl;
|
||||
Ds.Dhop (src,ref,DaggerNo);
|
||||
|
||||
setCheckerboard(r_eo,r_o);
|
||||
setCheckerboard(r_eo,r_e);
|
||||
|
||||
err= ref - r_eo;
|
||||
std::cout<<GridLogMessage << "EO norm diff "<< norm2(err)<< " "<<norm2(ref)<< " " << norm2(r_eo) <<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Test Ddagger is the dagger of D by requiring "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= < phi | Deo | chi > * = < chi | Deo^dag| phi> "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
|
||||
FermionField chi_e (&RBGrid);
|
||||
FermionField chi_o (&RBGrid);
|
||||
|
||||
FermionField dchi_e (&RBGrid);
|
||||
FermionField dchi_o (&RBGrid);
|
||||
|
||||
FermionField phi_e (&RBGrid);
|
||||
FermionField phi_o (&RBGrid);
|
||||
|
||||
FermionField dphi_e (&RBGrid);
|
||||
FermionField dphi_o (&RBGrid);
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
pickCheckerboard(Even,phi_e,phi);
|
||||
pickCheckerboard(Odd ,phi_o,phi);
|
||||
|
||||
Ds.Meooe(chi_e,dchi_o);
|
||||
Ds.Meooe(chi_o,dchi_e);
|
||||
Ds.MeooeDag(phi_e,dphi_o);
|
||||
Ds.MeooeDag(phi_o,dphi_e);
|
||||
|
||||
ComplexD pDce = innerProduct(phi_e,dchi_e);
|
||||
ComplexD pDco = innerProduct(phi_o,dchi_o);
|
||||
ComplexD cDpe = innerProduct(chi_e,dphi_e);
|
||||
ComplexD cDpo = innerProduct(chi_o,dphi_o);
|
||||
|
||||
std::cout<<GridLogMessage <<"e "<<pDce<<" "<<cDpe <<std::endl;
|
||||
std::cout<<GridLogMessage <<"o "<<pDco<<" "<<cDpo <<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage <<"pDce - conj(cDpo) "<< pDce-conj(cDpo) <<std::endl;
|
||||
std::cout<<GridLogMessage <<"pDco - conj(cDpe) "<< pDco-conj(cDpe) <<std::endl;
|
||||
std::cout<<GridLogMessage <<"e "<<pDce<<" "<<cDpe <<std::endl;
|
||||
std::cout<<GridLogMessage <<"o "<<pDco<<" "<<cDpo <<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage <<"pDce - conj(cDpo) "<< pDce-conj(cDpo) <<std::endl;
|
||||
std::cout<<GridLogMessage <<"pDco - conj(cDpe) "<< pDco-conj(cDpe) <<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Test MeeInv Mee = 1 "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
|
||||
Ds.Mooee(chi_e,src_e);
|
||||
Ds.MooeeInv(src_e,phi_e);
|
||||
|
||||
Ds.Mooee(chi_o,src_o);
|
||||
Ds.MooeeInv(src_o,phi_o);
|
||||
|
||||
setCheckerboard(phi,phi_e);
|
||||
setCheckerboard(phi,phi_o);
|
||||
|
||||
err = phi-chi;
|
||||
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<< std::endl;
|
||||
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Test MeeInvDag MeeDag = 1 "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
|
||||
Ds.MooeeDag(chi_e,src_e);
|
||||
Ds.MooeeInvDag(src_e,phi_e);
|
||||
|
||||
Ds.MooeeDag(chi_o,src_o);
|
||||
Ds.MooeeInvDag(src_o,phi_o);
|
||||
|
||||
setCheckerboard(phi,phi_e);
|
||||
setCheckerboard(phi,phi_o);
|
||||
|
||||
err = phi-chi;
|
||||
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<< std::endl;
|
||||
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
std::cout<<GridLogMessage<<"= Test MpcDagMpc is Hermitian "<<std::endl;
|
||||
std::cout<<GridLogMessage<<"=============================================================="<<std::endl;
|
||||
|
||||
random(pRNG,phi);
|
||||
random(pRNG,chi);
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
pickCheckerboard(Even,phi_e,phi);
|
||||
pickCheckerboard(Odd ,phi_o,phi);
|
||||
|
||||
SchurDiagMooeeOperator<NaiveStaggeredFermionR,FermionField> HermOpEO(Ds);
|
||||
HermOpEO.MpcDagMpc(chi_e,dchi_e,t1,t2);
|
||||
HermOpEO.MpcDagMpc(chi_o,dchi_o,t1,t2);
|
||||
|
||||
HermOpEO.MpcDagMpc(phi_e,dphi_e,t1,t2);
|
||||
HermOpEO.MpcDagMpc(phi_o,dphi_o,t1,t2);
|
||||
|
||||
pDce = innerProduct(phi_e,dchi_e);
|
||||
pDco = innerProduct(phi_o,dchi_o);
|
||||
cDpe = innerProduct(chi_e,dphi_e);
|
||||
cDpo = innerProduct(chi_o,dphi_o);
|
||||
|
||||
std::cout<<GridLogMessage <<"e "<<pDce<<" "<<cDpe <<std::endl;
|
||||
std::cout<<GridLogMessage <<"o "<<pDco<<" "<<cDpo <<std::endl;
|
||||
|
||||
std::cout<<GridLogMessage <<"pDce - conj(cDpo) "<< pDco-conj(cDpo) <<std::endl;
|
||||
std::cout<<GridLogMessage <<"pDco - conj(cDpe) "<< pDce-conj(cDpe) <<std::endl;
|
||||
|
||||
Grid_finalize();
|
||||
}
|
@ -570,8 +570,8 @@ void TestConserved1(Action & Ddwf, Action & Ddwfrev,
|
||||
LatticeGaugeField Umu5d(FGrid);
|
||||
std::vector<LatticeColourMatrix> U(4,FGrid);
|
||||
{
|
||||
auto Umu5d_v = Umu5d.View();
|
||||
auto Umu_v = Umu.View();
|
||||
autoView( Umu5d_v , Umu5d, CpuWrite);
|
||||
autoView( Umu_v , Umu , CpuRead);
|
||||
for(int ss=0;ss<Umu.Grid()->oSites();ss++){
|
||||
for(int s=0;s<Ls;s++){
|
||||
Umu5d_v[Ls*ss+s] = Umu_v[ss];
|
||||
@ -597,8 +597,8 @@ void TestConserved1(Action & Ddwf, Action & Ddwfrev,
|
||||
{
|
||||
RealD diag = 5.0 - Ddwf.M5;
|
||||
mass = Ddwf.mass;
|
||||
auto psi=result5.View();
|
||||
auto chi=tmp.View();
|
||||
autoView( psi,result5,CpuRead);
|
||||
autoView( chi,tmp, CpuWrite);
|
||||
thread_for(sss,UGrid->oSites(),{
|
||||
uint64_t ss= sss*Ls;
|
||||
typedef vSpinColourVector spinor;
|
||||
|
@ -98,9 +98,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
auto U_v = U.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
thread_foreach( i,mom_v,{
|
||||
Uprime_v[i](mu) =
|
||||
U_v[i](mu)
|
||||
|
@ -100,9 +100,9 @@ int main (int argc, char ** argv)
|
||||
|
||||
// fourth order exponential approx
|
||||
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach( i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -110,9 +110,9 @@ int main (int argc, char** argv)
|
||||
PokeIndex<LorentzIndex>(mom, mommu, mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -119,9 +119,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -114,9 +114,9 @@ int main (int argc, char** argv)
|
||||
PokeIndex<LorentzIndex>(mom, mommu, mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -85,9 +85,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto Uprime_v = Uprime.View();
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
thread_foreach(i,mom_v,{ // exp(pmu dt) * Umu
|
||||
Uprime_v[i](mu) = U_v[i](mu) + mom_v[i](mu)*U_v[i](mu)*dt ;
|
||||
});
|
||||
|
@ -87,9 +87,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v= Uprime.View();
|
||||
auto U_v = U.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
autoView( U_v , U, CpuRead);
|
||||
thread_foreach(i,mom_v,{ // exp(pmu dt) * Umu
|
||||
Uprime_v[i](mu) = U_v[i](mu) + mom_v[i](mu)*U_v[i](mu)*dt ;
|
||||
});
|
||||
|
@ -105,9 +105,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
+ mom_v[i](mu)*U_v[i](mu)*dt
|
||||
|
@ -99,9 +99,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -101,9 +101,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
+ mom_v[i](mu)*U_v[i](mu)*dt
|
||||
|
@ -112,9 +112,9 @@ int main (int argc, char** argv)
|
||||
PokeIndex<LorentzIndex>(mom, mommu, mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -115,9 +115,9 @@ int main (int argc, char** argv)
|
||||
SU3::GaussianFundamentalLieAlgebraMatrix(RNG4, mommu); // Traceless antihermitian momentum; gaussian in lie alg
|
||||
|
||||
PokeIndex<LorentzIndex>(mom, mommu, mu);
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
// fourth order exponential approx
|
||||
thread_foreach( i, mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu) + mom_v[i](mu)*U_v[i](mu)*dt + mom_v[i](mu) *mom_v[i](mu) *U_v[i](mu)*(dt*dt/2.0)
|
||||
|
@ -101,9 +101,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
+ mom_v[i](mu)*U_v[i](mu)*dt
|
||||
|
@ -87,9 +87,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto Uprime_v = Uprime.View();
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
thread_foreach(i,mom_v,{ // exp(pmu dt) * Umu
|
||||
Uprime_v[i](mu) = U_v[i](mu) + mom_v[i](mu)*U_v[i](mu)*dt ;
|
||||
});
|
||||
|
@ -105,9 +105,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
thread_foreach( i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu);
|
||||
Uprime_v[i](mu) += mom_v[i](mu)*U_v[i](mu)*dt ;
|
||||
|
@ -105,9 +105,9 @@ int main(int argc, char **argv)
|
||||
Hmom -= real(sum(trace(mommu * mommu)));
|
||||
PokeIndex<LorentzIndex>(mom, mommu, mu);
|
||||
|
||||
auto Uprime_v = Uprime.View();
|
||||
auto U_v = U.View();
|
||||
auto mom_v = mom.View();
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
thread_foreach(ss,mom_v,
|
||||
{
|
||||
Uprime_v[ss]._internal[mu] = ProjectOnGroup(Exponentiate(mom_v[ss]._internal[mu], dt, 12) * U_v[ss]._internal[mu]);
|
||||
|
@ -114,9 +114,9 @@ int main (int argc, char ** argv)
|
||||
PokeIndex<LorentzIndex>(mom,mommu,mu);
|
||||
|
||||
// fourth order exponential approx
|
||||
auto mom_v = mom.View();
|
||||
auto U_v = U.View();
|
||||
auto Uprime_v = Uprime.View();
|
||||
autoView( mom_v, mom, CpuRead);
|
||||
autoView( U_v , U, CpuRead);
|
||||
autoView(Uprime_v, Uprime, CpuWrite);
|
||||
|
||||
thread_foreach(i,mom_v,{
|
||||
Uprime_v[i](mu) = U_v[i](mu)
|
||||
|
@ -35,7 +35,7 @@ directory
|
||||
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
#ifndef GRID_NVCC
|
||||
#ifndef GRID_CUDA
|
||||
using namespace Grid;
|
||||
|
||||
|
||||
|
@ -31,7 +31,6 @@ Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
;
|
||||
|
||||
template<class Field> class DumbOperator : public LinearOperatorBase<Field> {
|
||||
public:
|
||||
@ -57,7 +56,7 @@ public:
|
||||
// Support for coarsening to a multigrid
|
||||
void OpDiag (const Field &in, Field &out) {};
|
||||
void OpDir (const Field &in, Field &out,int dir,int disp){};
|
||||
void OpDirAll (const Field &in, std::vector<Field> &out) {}; // Abstract base
|
||||
void OpDirAll (const Field &in, std::vector<Field> &out) {};
|
||||
|
||||
void Op (const Field &in, Field &out){
|
||||
out = scale * in;
|
||||
@ -105,7 +104,7 @@ int main (int argc, char ** argv)
|
||||
GridDefaultMpi());
|
||||
|
||||
double lo=0.001;
|
||||
double hi=1.0;
|
||||
double hi=20.0;
|
||||
int precision=64;
|
||||
int degree=10;
|
||||
AlgRemez remez(lo,hi,precision);
|
||||
|
@ -1,5 +1,3 @@
|
||||
|
||||
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
@ -302,8 +300,8 @@ int main (int argc, char ** argv)
|
||||
int nb=nbasisc/2;
|
||||
CoarseAggregates.CreateSubspaceChebyshev(CRNG,PosdefLdop,nb,12.0,0.02,500,100,100,0.0);
|
||||
for(int n=0;n<nb;n++){
|
||||
auto subspace = CoarseAggregates.subspace[n].View();
|
||||
auto subspace_g5 = CoarseAggregates.subspace[n+nb].View();
|
||||
autoView( subspace, CoarseAggregates.subspace[n] ,CpuRead);
|
||||
autoView( subspace_g5,CoarseAggregates.subspace[n+nb],CpuWrite);
|
||||
for(int nn=0;nn<nb;nn++){
|
||||
for(int site=0;site<Coarse5d->oSites();site++){
|
||||
subspace_g5[site](nn) = subspace[site](nn);
|
||||
|
594
tests/solver/Test_dwf_multigrid.cc
Normal file
594
tests/solver/Test_dwf_multigrid.cc
Normal file
@ -0,0 +1,594 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./tests/Test_dwf_hdcr.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Antonin Portelli <antonin.portelli@me.com>
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
Author: paboyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 <Grid/Grid.h>
|
||||
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
/* Params
|
||||
* Grid:
|
||||
* block1(4)
|
||||
* block2(4)
|
||||
*
|
||||
* Subspace
|
||||
* * Fine : Subspace(nbasis,hi,lo,order,first,step) -- 32, 60,0.02,500,100,100
|
||||
* * Coarse: Subspace(nbasis,hi,lo,order,first,step) -- 32, 18,0.02,500,100,100
|
||||
|
||||
* Smoother:
|
||||
* * Fine: Cheby(hi, lo, order) -- 60,0.5,10
|
||||
* * Coarse: Cheby(hi, lo, order) -- 12,0.1,4
|
||||
|
||||
* Lanczos:
|
||||
* CoarseCoarse IRL( Nk, Nm, Nstop, poly(lo,hi,order)) 24,36,24,0.002,4.0,61
|
||||
*/
|
||||
|
||||
template<class Field> class SolverWrapper : public LinearFunction<Field> {
|
||||
private:
|
||||
LinearOperatorBase<Field> & _Matrix;
|
||||
OperatorFunction<Field> & _Solver;
|
||||
LinearFunction<Field> & _Guess;
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Wrap the usual normal equations trick
|
||||
/////////////////////////////////////////////////////
|
||||
SolverWrapper(LinearOperatorBase<Field> &Matrix,
|
||||
OperatorFunction<Field> &Solver,
|
||||
LinearFunction<Field> &Guess)
|
||||
: _Matrix(Matrix), _Solver(Solver), _Guess(Guess) {};
|
||||
|
||||
void operator() (const Field &in, Field &out){
|
||||
|
||||
_Guess(in,out);
|
||||
_Solver(_Matrix,in,out); // Mdag M out = Mdag in
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Must use a non-hermitian solver
|
||||
template<class Matrix,class Field>
|
||||
class PVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||
Matrix &_Mat;
|
||||
Matrix &_PV;
|
||||
public:
|
||||
PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||
|
||||
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<Field> &out){
|
||||
assert(0);
|
||||
};
|
||||
void Op (const Field &in, Field &out){
|
||||
Field tmp(in.Grid());
|
||||
_Mat.M(in,tmp);
|
||||
_PV.Mdag(tmp,out);
|
||||
}
|
||||
void AdjOp (const Field &in, Field &out){
|
||||
Field tmp(in.Grid());
|
||||
_PV.M(tmp,out);
|
||||
_Mat.Mdag(in,tmp);
|
||||
}
|
||||
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||
assert(0);
|
||||
}
|
||||
void HermOp(const Field &in, Field &out){
|
||||
assert(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
RealD InverseApproximation(RealD x){
|
||||
return 1.0/x;
|
||||
}
|
||||
|
||||
template<class Field,class Matrix> class ChebyshevSmoother : public LinearFunction<Field>
|
||||
{
|
||||
public:
|
||||
typedef LinearOperatorBase<Field> FineOperator;
|
||||
Matrix & _SmootherMatrix;
|
||||
FineOperator & _SmootherOperator;
|
||||
|
||||
Chebyshev<Field> Cheby;
|
||||
|
||||
ChebyshevSmoother(RealD _lo,RealD _hi,int _ord, FineOperator &SmootherOperator,Matrix &SmootherMatrix) :
|
||||
_SmootherOperator(SmootherOperator),
|
||||
_SmootherMatrix(SmootherMatrix),
|
||||
Cheby(_lo,_hi,_ord,InverseApproximation)
|
||||
{};
|
||||
|
||||
void operator() (const Field &in, Field &out)
|
||||
{
|
||||
Field tmp(in.Grid());
|
||||
MdagMLinearOperator<Matrix,Field> MdagMOp(_SmootherMatrix);
|
||||
_SmootherOperator.AdjOp(in,tmp);
|
||||
Cheby(MdagMOp,tmp,out);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Field,class Matrix> class MirsSmoother : public LinearFunction<Field>
|
||||
{
|
||||
public:
|
||||
typedef LinearOperatorBase<Field> FineOperator;
|
||||
Matrix & SmootherMatrix;
|
||||
FineOperator & SmootherOperator;
|
||||
RealD tol;
|
||||
RealD shift;
|
||||
int maxit;
|
||||
|
||||
MirsSmoother(RealD _shift,RealD _tol,int _maxit,FineOperator &_SmootherOperator,Matrix &_SmootherMatrix) :
|
||||
shift(_shift),tol(_tol),maxit(_maxit),
|
||||
SmootherOperator(_SmootherOperator),
|
||||
SmootherMatrix(_SmootherMatrix)
|
||||
{};
|
||||
|
||||
void operator() (const Field &in, Field &out)
|
||||
{
|
||||
ZeroGuesser<Field> Guess;
|
||||
ConjugateGradient<Field> CG(tol,maxit,false);
|
||||
|
||||
Field src(in.Grid());
|
||||
|
||||
ShiftedMdagMLinearOperator<SparseMatrixBase<Field>,Field> MdagMOp(SmootherMatrix,shift);
|
||||
SmootherOperator.AdjOp(in,src);
|
||||
Guess(src,out);
|
||||
CG(MdagMOp,src,out);
|
||||
}
|
||||
};
|
||||
|
||||
#define GridLogLevel std::cout << GridLogMessage <<std::string(level,'\t')<< " Level "<<level <<" "
|
||||
|
||||
template<class Fobj,class CComplex,int nbasis, class CoarseSolver>
|
||||
class HDCRPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||
public:
|
||||
|
||||
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||
typedef CoarsenedMatrix<Fobj,CComplex,nbasis> CoarseOperator;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||
typedef LinearOperatorBase<FineField> FineOperator;
|
||||
typedef LinearFunction <FineField> FineSmoother;
|
||||
|
||||
Aggregates & _Aggregates;
|
||||
FineOperator & _FineOperator;
|
||||
FineSmoother & _Smoother;
|
||||
CoarseSolver & _CoarseSolve;
|
||||
|
||||
int level; void Level(int lv) {level = lv; };
|
||||
|
||||
|
||||
HDCRPreconditioner(Aggregates &Agg,
|
||||
FineOperator &Fine,
|
||||
FineSmoother &Smoother,
|
||||
CoarseSolver &CoarseSolve_)
|
||||
: _Aggregates(Agg),
|
||||
_FineOperator(Fine),
|
||||
_Smoother(Smoother),
|
||||
_CoarseSolve(CoarseSolve_),
|
||||
level(1) { }
|
||||
|
||||
virtual void operator()(const FineField &in, FineField & out)
|
||||
{
|
||||
auto CoarseGrid = _Aggregates.CoarseGrid;
|
||||
CoarseVector Csrc(CoarseGrid);
|
||||
CoarseVector Csol(CoarseGrid);
|
||||
FineField vec1(in.Grid());
|
||||
FineField vec2(in.Grid());
|
||||
|
||||
double t;
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(in,out);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Update the residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||
|
||||
// Fine to Coarse
|
||||
t=-usecond();
|
||||
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse correction
|
||||
t=-usecond();
|
||||
_CoarseSolve(Csrc,Csol);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse to Fine
|
||||
t=-usecond();
|
||||
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||
add(out,out,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(vec1,vec2);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
add( out,out,vec2);
|
||||
}
|
||||
};
|
||||
|
||||
/*
|
||||
template<class Fobj,class CComplex,int nbasis, class Guesser, class CoarseSolver>
|
||||
class MultiGridPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||
public:
|
||||
|
||||
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||
typedef CoarsenedMatrix<Fobj,CComplex,nbasis> CoarseOperator;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||
typedef LinearOperatorBase<FineField> FineOperator;
|
||||
typedef LinearFunction <FineField> FineSmoother;
|
||||
|
||||
Aggregates & _Aggregates;
|
||||
CoarseOperator & _CoarseOperator;
|
||||
FineOperator & _FineOperator;
|
||||
Guesser & _Guess;
|
||||
FineSmoother & _Smoother;
|
||||
CoarseSolver & _CoarseSolve;
|
||||
|
||||
int level; void Level(int lv) {level = lv; };
|
||||
|
||||
|
||||
MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse,
|
||||
FineOperator &Fine,
|
||||
FineSmoother &Smoother,
|
||||
Guesser &Guess_,
|
||||
CoarseSolver &CoarseSolve_)
|
||||
: _Aggregates(Agg),
|
||||
_CoarseOperator(Coarse),
|
||||
_FineOperator(Fine),
|
||||
_Smoother(Smoother),
|
||||
_Guess(Guess_),
|
||||
_CoarseSolve(CoarseSolve_),
|
||||
level(1) { }
|
||||
|
||||
virtual void operator()(const FineField &in, FineField & out)
|
||||
{
|
||||
CoarseVector Csrc(_CoarseOperator.Grid());
|
||||
CoarseVector Csol(_CoarseOperator.Grid());
|
||||
FineField vec1(in.Grid());
|
||||
FineField vec2(in.Grid());
|
||||
|
||||
double t;
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(in,out);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Update the residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||
|
||||
// Fine to Coarse
|
||||
t=-usecond();
|
||||
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse correction
|
||||
t=-usecond();
|
||||
_CoarseSolve(Csrc,Csol);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse to Fine
|
||||
t=-usecond();
|
||||
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||
add(out,out,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(vec1,vec2);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
add( out,out,vec2);
|
||||
}
|
||||
};
|
||||
*/
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
const int Ls=16;
|
||||
|
||||
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; utility for this?
|
||||
///////////////////////////////////////////////////
|
||||
std::vector<int> block ({2,2,2,2});
|
||||
std::vector<int> blockc ({2,2,2,2});
|
||||
const int nbasis= 32;
|
||||
const int nbasisc= 32;
|
||||
auto clatt = GridDefaultLatt();
|
||||
for(int d=0;d<clatt.size();d++){
|
||||
clatt[d] = clatt[d]/block[d];
|
||||
}
|
||||
auto cclatt = clatt;
|
||||
for(int d=0;d<clatt.size();d++){
|
||||
cclatt[d] = clatt[d]/blockc[d];
|
||||
}
|
||||
|
||||
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||
GridCartesian *Coarse5d = SpaceTimeGrid::makeFiveDimGrid(1,Coarse4d);
|
||||
GridCartesian *CoarseCoarse4d = SpaceTimeGrid::makeFourDimGrid(cclatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||
GridCartesian *CoarseCoarse5d = SpaceTimeGrid::makeFiveDimGrid(1,CoarseCoarse4d);
|
||||
|
||||
std::vector<int> seeds4({1,2,3,4});
|
||||
std::vector<int> seeds5({5,6,7,8});
|
||||
std::vector<int> cseeds({5,6,7,8});
|
||||
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5);
|
||||
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4);
|
||||
GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(cseeds);
|
||||
LatticeFermion src(FGrid); gaussian(RNG5,src);// src=src+g5*src;
|
||||
LatticeFermion result(FGrid);
|
||||
LatticeGaugeField Umu(UGrid);
|
||||
|
||||
FieldMetaData header;
|
||||
std::string file("./ckpoint_lat.4000");
|
||||
NerscIO::readConfiguration(Umu,header,file);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Building g5R5 hermitian DWF operator" <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
RealD mass=0.001;
|
||||
RealD M5=1.8;
|
||||
DomainWallFermionR Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
|
||||
DomainWallFermionR Dpv (Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5);
|
||||
|
||||
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||
typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> CoarseOperator;
|
||||
typedef CoarseOperator::CoarseVector CoarseVector;
|
||||
typedef CoarseOperator::siteVector siteVector;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Calling Aggregation class to build subspace" <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
MdagMLinearOperator<DomainWallFermionR,LatticeFermion> HermDefOp(Ddwf);
|
||||
|
||||
Subspace Aggregates(Coarse5d,FGrid,0);
|
||||
|
||||
assert ( (nbasis & 0x1)==0);
|
||||
{
|
||||
int nb=nbasis/2;
|
||||
Aggregates.CreateSubspaceChebyshev(RNG5,HermDefOp,nb,60.0,0.02,500,100,100,0.0);
|
||||
for(int n=0;n<nb;n++){
|
||||
G5R5(Aggregates.subspace[n+nb],Aggregates.subspace[n]);
|
||||
}
|
||||
LatticeFermion A(FGrid);
|
||||
LatticeFermion B(FGrid);
|
||||
for(int n=0;n<nb;n++){
|
||||
A = Aggregates.subspace[n];
|
||||
B = Aggregates.subspace[n+nb];
|
||||
Aggregates.subspace[n] = A+B; // 1+G5 // eigen value of G5R5 is +1
|
||||
Aggregates.subspace[n+nb]= A-B; // 1-G5 // eigen value of G5R5 is -1
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Will coarsen G5R5 M and G5R5 Mpv in G5R5 compatible way " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> Level1Op;
|
||||
typedef CoarsenedMatrix<siteVector,iScalar<vTComplex>,nbasisc> Level2Op;
|
||||
|
||||
Gamma5R5HermitianLinearOperator<DomainWallFermionR,LatticeFermion> HermIndefOp(Ddwf);
|
||||
Gamma5R5HermitianLinearOperator<DomainWallFermionR,LatticeFermion> HermIndefOpPV(Dpv);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Building coarse representation of Indef operator" <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
Level1Op LDOp(*Coarse5d,1); LDOp.CoarsenOperator(FGrid,HermIndefOp,Aggregates);
|
||||
Level1Op LDOpPV(*Coarse5d,1); LDOpPV.CoarsenOperator(FGrid,HermIndefOpPV,Aggregates);
|
||||
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Testing fine and coarse solvers " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
CoarseVector c_src(Coarse5d); c_src=1.0;
|
||||
CoarseVector c_res(Coarse5d);
|
||||
|
||||
LatticeFermion f_src(FGrid); f_src=1.0;
|
||||
LatticeFermion f_res(FGrid);
|
||||
|
||||
LatticeFermion f_src_e(FrbGrid); f_src_e=1.0;
|
||||
LatticeFermion f_res_e(FrbGrid);
|
||||
|
||||
RealD tol=1.0e-8;
|
||||
int MaxIt = 10000;
|
||||
|
||||
BiCGSTAB<CoarseVector> CoarseBiCGSTAB(tol,MaxIt);
|
||||
ConjugateGradient<CoarseVector> CoarseCG(tol,MaxIt);
|
||||
// GeneralisedMinimalResidual<CoarseVector> CoarseGMRES(tol,MaxIt,20);
|
||||
|
||||
BiCGSTAB<LatticeFermion> FineBiCGSTAB(tol,MaxIt);
|
||||
ConjugateGradient<LatticeFermion> FineCG(tol,MaxIt);
|
||||
// GeneralisedMinimalResidual<LatticeFermion> FineGMRES(tol,MaxIt,20);
|
||||
|
||||
MdagMLinearOperator<DomainWallFermionR,LatticeFermion> FineMdagM(Ddwf); // M^\dag M
|
||||
PVdagMLinearOperator<DomainWallFermionR,LatticeFermion> FinePVdagM(Ddwf,Dpv);// M_{pv}^\dag M
|
||||
SchurDiagMooeeOperator<DomainWallFermionR,LatticeFermion> FineDiagMooee(Ddwf); // M_ee - Meo Moo^-1 Moe
|
||||
SchurDiagOneOperator<DomainWallFermionR,LatticeFermion> FineDiagOne(Ddwf); // 1 - M_ee^{-1} Meo Moo^{-1} Moe e
|
||||
|
||||
MdagMLinearOperator<Level1Op,CoarseVector> CoarseMdagM(LDOp);
|
||||
PVdagMLinearOperator<Level1Op,CoarseVector> CoarsePVdagM(LDOp,LDOpPV);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Fine CG unprec "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
f_res=Zero();
|
||||
FineCG(FineMdagM,f_src,f_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Fine CG prec DiagMooee "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
f_res_e=Zero();
|
||||
FineCG(FineDiagMooee,f_src_e,f_res_e);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Fine CG prec DiagOne "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
f_res_e=Zero();
|
||||
FineCG(FineDiagOne,f_src_e,f_res_e);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Fine BiCGSTAB unprec "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
f_res=Zero();
|
||||
FineBiCGSTAB(FinePVdagM,f_src,f_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Coarse BiCGSTAB "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
c_res=Zero();
|
||||
CoarseBiCGSTAB(CoarsePVdagM,c_src,c_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Coarse CG unprec "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
c_res=Zero();
|
||||
CoarseCG(CoarseMdagM,c_src,c_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Running Coarse grid Lanczos "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
Chebyshev<CoarseVector> IRLCheby(0.03,12.0,71); // 1 iter
|
||||
FunctionHermOp<CoarseVector> IRLOpCheby(IRLCheby,CoarseMdagM);
|
||||
PlainHermOp<CoarseVector> IRLOp (CoarseMdagM);
|
||||
int Nk=64;
|
||||
int Nm=128;
|
||||
int Nstop=Nk;
|
||||
ImplicitlyRestartedLanczos<CoarseVector> IRL(IRLOpCheby,IRLOp,Nstop,Nk,Nm,1.0e-3,20);
|
||||
|
||||
int Nconv;
|
||||
std::vector<RealD> eval(Nm);
|
||||
std::vector<CoarseVector> evec(Nm,Coarse5d);
|
||||
IRL.calc(eval,evec,c_src,Nconv);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Running Coarse grid deflated solver "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
DeflatedGuesser<CoarseVector> DeflCoarseGuesser(evec,eval);
|
||||
NormalEquations<CoarseVector> DeflCoarseCGNE (LDOp,CoarseCG,DeflCoarseGuesser);
|
||||
c_res=Zero();
|
||||
DeflCoarseCGNE(c_src,c_res);
|
||||
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Running HDCR "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
ConjugateGradient<CoarseVector> CoarseMgridCG(0.001,1000);
|
||||
ChebyshevSmoother<LatticeFermion,DomainWallFermionR> FineSmoother(0.5,60.0,10,HermIndefOp,Ddwf);
|
||||
|
||||
typedef HDCRPreconditioner<vSpinColourVector, vTComplex,nbasis, NormalEquations<CoarseVector> > TwoLevelHDCR;
|
||||
TwoLevelHDCR TwoLevelPrecon(Aggregates,
|
||||
HermIndefOp,
|
||||
FineSmoother,
|
||||
DeflCoarseCGNE);
|
||||
TwoLevelPrecon.Level(1);
|
||||
// PrecGeneralisedConjugateResidual<LatticeFermion> l1PGCR(1.0e-8,100,HermIndefOp,TwoLevelPrecon,16,16);
|
||||
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> l1PGCR(1.0e-8,100,HermIndefOp,TwoLevelPrecon,16,16);
|
||||
l1PGCR.Level(1);
|
||||
|
||||
f_res=Zero();
|
||||
|
||||
CoarseCG.Tolerance=0.02;
|
||||
l1PGCR(f_src,f_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Running Multigrid "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
BiCGSTAB<CoarseVector> CoarseMgridBiCGSTAB(0.01,1000);
|
||||
BiCGSTAB<LatticeFermion> FineMgridBiCGSTAB(0.0,24);
|
||||
ZeroGuesser<CoarseVector> CoarseZeroGuesser;
|
||||
ZeroGuesser<LatticeFermion> FineZeroGuesser;
|
||||
|
||||
SolverWrapper<LatticeFermion> FineBiCGSmoother( FinePVdagM, FineMgridBiCGSTAB, FineZeroGuesser);
|
||||
SolverWrapper<CoarseVector> CoarsePVdagMSolver(CoarsePVdagM,CoarseMgridBiCGSTAB,CoarseZeroGuesser);
|
||||
typedef HDCRPreconditioner<vSpinColourVector, vTComplex,nbasis, SolverWrapper<CoarseVector> > TwoLevelMG;
|
||||
|
||||
TwoLevelMG _TwoLevelMG(Aggregates,
|
||||
FinePVdagM,
|
||||
FineBiCGSmoother,
|
||||
CoarsePVdagMSolver);
|
||||
_TwoLevelMG.Level(1);
|
||||
|
||||
PrecGeneralisedConjugateResidualNonHermitian<LatticeFermion> pvPGCR(1.0e-8,100,FinePVdagM,_TwoLevelMG,16,16);
|
||||
pvPGCR.Level(1);
|
||||
|
||||
f_res=Zero();
|
||||
pvPGCR(f_src,f_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
Grid_finalize();
|
||||
|
||||
}
|
375
tests/solver/Test_hw_multigrid.cc
Normal file
375
tests/solver/Test_hw_multigrid.cc
Normal file
@ -0,0 +1,375 @@
|
||||
/*************************************************************************************
|
||||
|
||||
Grid physics library, www.github.com/paboyle/Grid
|
||||
|
||||
Source file: ./tests/Test_dwf_hdcr.cc
|
||||
|
||||
Copyright (C) 2015
|
||||
|
||||
Author: Peter Boyle <paboyle@ph.ed.ac.uk>
|
||||
|
||||
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 <Grid/Grid.h>
|
||||
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
|
||||
//#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidualNonHermitian.h>
|
||||
#include <Grid/algorithms/iterative/BiCGSTAB.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
/* Params
|
||||
* Grid:
|
||||
* block1(4)
|
||||
* block2(4)
|
||||
*
|
||||
* Subspace
|
||||
* * Fine : Subspace(nbasis,hi,lo,order,first,step) -- 32, 60,0.02,500,100,100
|
||||
* * Coarse: Subspace(nbasis,hi,lo,order,first,step) -- 32, 18,0.02,500,100,100
|
||||
|
||||
* Smoother:
|
||||
* * Fine: Cheby(hi, lo, order) -- 60,0.5,10
|
||||
* * Coarse: Cheby(hi, lo, order) -- 12,0.1,4
|
||||
|
||||
* Lanczos:
|
||||
* CoarseCoarse IRL( Nk, Nm, Nstop, poly(lo,hi,order)) 24,36,24,0.002,4.0,61
|
||||
*/
|
||||
|
||||
template<class Field> class SolverWrapper : public LinearFunction<Field> {
|
||||
private:
|
||||
LinearOperatorBase<Field> & _Matrix;
|
||||
OperatorFunction<Field> & _Solver;
|
||||
LinearFunction<Field> & _Guess;
|
||||
public:
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
// Wrap the usual normal equations trick
|
||||
/////////////////////////////////////////////////////
|
||||
SolverWrapper(LinearOperatorBase<Field> &Matrix,
|
||||
OperatorFunction<Field> &Solver,
|
||||
LinearFunction<Field> &Guess)
|
||||
: _Matrix(Matrix), _Solver(Solver), _Guess(Guess) {};
|
||||
|
||||
void operator() (const Field &in, Field &out){
|
||||
|
||||
_Guess(in,out);
|
||||
_Solver(_Matrix,in,out); // Mdag M out = Mdag in
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
// Must use a non-hermitian solver
|
||||
template<class Matrix,class Field>
|
||||
class PVdagMLinearOperator : public LinearOperatorBase<Field> {
|
||||
Matrix &_Mat;
|
||||
Matrix &_PV;
|
||||
public:
|
||||
PVdagMLinearOperator(Matrix &Mat,Matrix &PV): _Mat(Mat),_PV(PV){};
|
||||
|
||||
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<Field> &out){
|
||||
assert(0);
|
||||
};
|
||||
void Op (const Field &in, Field &out){
|
||||
Field tmp(in.Grid());
|
||||
_Mat.M(in,tmp);
|
||||
_PV.Mdag(tmp,out);
|
||||
}
|
||||
void AdjOp (const Field &in, Field &out){
|
||||
Field tmp(in.Grid());
|
||||
_PV.M(tmp,out);
|
||||
_Mat.Mdag(in,tmp);
|
||||
}
|
||||
void HermOpAndNorm(const Field &in, Field &out,RealD &n1,RealD &n2){
|
||||
assert(0);
|
||||
}
|
||||
void HermOp(const Field &in, Field &out){
|
||||
assert(0);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
RealD InverseApproximation(RealD x){
|
||||
return 1.0/x;
|
||||
}
|
||||
|
||||
template<class Field,class Matrix> class ChebyshevSmoother : public LinearFunction<Field>
|
||||
{
|
||||
public:
|
||||
typedef LinearOperatorBase<Field> FineOperator;
|
||||
Matrix & _SmootherMatrix;
|
||||
FineOperator & _SmootherOperator;
|
||||
|
||||
Chebyshev<Field> Cheby;
|
||||
|
||||
ChebyshevSmoother(RealD _lo,RealD _hi,int _ord, FineOperator &SmootherOperator,Matrix &SmootherMatrix) :
|
||||
_SmootherOperator(SmootherOperator),
|
||||
_SmootherMatrix(SmootherMatrix),
|
||||
Cheby(_lo,_hi,_ord,InverseApproximation)
|
||||
{};
|
||||
|
||||
void operator() (const Field &in, Field &out)
|
||||
{
|
||||
Field tmp(in.Grid());
|
||||
MdagMLinearOperator<Matrix,Field> MdagMOp(_SmootherMatrix);
|
||||
_SmootherOperator.AdjOp(in,tmp);
|
||||
Cheby(MdagMOp,tmp,out);
|
||||
}
|
||||
};
|
||||
|
||||
template<class Field,class Matrix> class MirsSmoother : public LinearFunction<Field>
|
||||
{
|
||||
public:
|
||||
typedef LinearOperatorBase<Field> FineOperator;
|
||||
Matrix & SmootherMatrix;
|
||||
FineOperator & SmootherOperator;
|
||||
RealD tol;
|
||||
RealD shift;
|
||||
int maxit;
|
||||
|
||||
MirsSmoother(RealD _shift,RealD _tol,int _maxit,FineOperator &_SmootherOperator,Matrix &_SmootherMatrix) :
|
||||
shift(_shift),tol(_tol),maxit(_maxit),
|
||||
SmootherOperator(_SmootherOperator),
|
||||
SmootherMatrix(_SmootherMatrix)
|
||||
{};
|
||||
|
||||
void operator() (const Field &in, Field &out)
|
||||
{
|
||||
ZeroGuesser<Field> Guess;
|
||||
ConjugateGradient<Field> CG(tol,maxit,false);
|
||||
|
||||
Field src(in.Grid());
|
||||
|
||||
ShiftedMdagMLinearOperator<SparseMatrixBase<Field>,Field> MdagMOp(SmootherMatrix,shift);
|
||||
SmootherOperator.AdjOp(in,src);
|
||||
Guess(src,out);
|
||||
CG(MdagMOp,src,out);
|
||||
}
|
||||
};
|
||||
|
||||
#define GridLogLevel std::cout << GridLogMessage <<std::string(level,'\t')<< " Level "<<level <<" "
|
||||
|
||||
template<class Fobj,class CComplex,int nbasis, class CoarseSolver>
|
||||
class HDCRPreconditioner : public LinearFunction< Lattice<Fobj> > {
|
||||
public:
|
||||
|
||||
typedef Aggregation<Fobj,CComplex,nbasis> Aggregates;
|
||||
typedef CoarsenedMatrix<Fobj,CComplex,nbasis> CoarseOperator;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseVector CoarseVector;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::CoarseMatrix CoarseMatrix;
|
||||
typedef typename Aggregation<Fobj,CComplex,nbasis>::FineField FineField;
|
||||
typedef LinearOperatorBase<FineField> FineOperator;
|
||||
typedef LinearFunction <FineField> FineSmoother;
|
||||
|
||||
Aggregates & _Aggregates;
|
||||
FineOperator & _FineOperator;
|
||||
FineSmoother & _Smoother;
|
||||
CoarseSolver & _CoarseSolve;
|
||||
|
||||
int level; void Level(int lv) {level = lv; };
|
||||
|
||||
|
||||
HDCRPreconditioner(Aggregates &Agg,
|
||||
FineOperator &Fine,
|
||||
FineSmoother &Smoother,
|
||||
CoarseSolver &CoarseSolve_)
|
||||
: _Aggregates(Agg),
|
||||
_FineOperator(Fine),
|
||||
_Smoother(Smoother),
|
||||
_CoarseSolve(CoarseSolve_),
|
||||
level(1) { }
|
||||
|
||||
virtual void operator()(const FineField &in, FineField & out)
|
||||
{
|
||||
auto CoarseGrid = _Aggregates.CoarseGrid;
|
||||
CoarseVector Csrc(CoarseGrid);
|
||||
CoarseVector Csol(CoarseGrid);
|
||||
FineField vec1(in.Grid());
|
||||
FineField vec2(in.Grid());
|
||||
|
||||
double t;
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(in,out);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Update the residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1, in ,vec1);
|
||||
|
||||
// Fine to Coarse
|
||||
t=-usecond();
|
||||
_Aggregates.ProjectToSubspace (Csrc,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Project to coarse took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse correction
|
||||
t=-usecond();
|
||||
_CoarseSolve(Csrc,Csol);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Coarse solve took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Coarse to Fine
|
||||
t=-usecond();
|
||||
_Aggregates.PromoteFromSubspace(Csol,vec1);
|
||||
add(out,out,vec1);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Promote to this level took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
// Residual
|
||||
_FineOperator.Op(out,vec1); sub(vec1 ,in , vec1);
|
||||
|
||||
// Fine Smoother
|
||||
t=-usecond();
|
||||
_Smoother(vec1,vec2);
|
||||
t+=usecond();
|
||||
GridLogLevel << "Smoother took "<< t/1000.0<< "ms" <<std::endl;
|
||||
|
||||
add( out,out,vec2);
|
||||
}
|
||||
};
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
const int Ls=16;
|
||||
|
||||
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; utility for this?
|
||||
///////////////////////////////////////////////////
|
||||
std::vector<int> block ({2,2,2,2});
|
||||
const int nbasis= 8;
|
||||
|
||||
auto clatt = GridDefaultLatt();
|
||||
for(int d=0;d<clatt.size();d++){
|
||||
clatt[d] = clatt[d]/block[d];
|
||||
}
|
||||
|
||||
GridCartesian *Coarse4d = SpaceTimeGrid::makeFourDimGrid(clatt, GridDefaultSimd(Nd,vComplex::Nsimd()),GridDefaultMpi());;
|
||||
GridCartesian *Coarse5d = SpaceTimeGrid::makeFiveDimGrid(Ls,Coarse4d);
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds);
|
||||
GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds);
|
||||
GridParallelRNG CRNG(Coarse5d);CRNG.SeedFixedIntegers(seeds);
|
||||
|
||||
LatticeGaugeField Umu(UGrid);
|
||||
FieldMetaData header;
|
||||
std::string file("./ckpoint_lat.4000");
|
||||
NerscIO::readConfiguration(Umu,header,file);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Building g5R5 hermitian DWF operator" <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
RealD mass=0.001;
|
||||
RealD M5=1.8;
|
||||
WilsonFermionR Dw(Umu,*UGrid,*UrbGrid,-M5);
|
||||
DomainWallFermionR Ddwf(Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,mass,M5);
|
||||
DomainWallFermionR Dpv (Umu,*FGrid,*FrbGrid,*UGrid,*UrbGrid,1.0,M5);
|
||||
|
||||
typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
|
||||
typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> CoarseOperator;
|
||||
typedef CoarseOperator::CoarseVector CoarseVector;
|
||||
typedef CoarseOperator::siteVector siteVector;
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Calling Aggregation class to build subspace" <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
MdagMLinearOperator<WilsonFermionR,LatticeFermion> SubspaceOp(Dw);
|
||||
|
||||
Subspace Aggregates4D(Coarse4d,UGrid,0);
|
||||
Subspace Aggregates5D(Coarse5d,FGrid,0);
|
||||
|
||||
assert ( (nbasis & 0x1)==0);
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " 4D subspace build " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
int nb=nbasis/2;
|
||||
Gamma g5(Gamma::Algebra::Gamma5);
|
||||
Aggregates4D.CreateSubspaceChebyshev(RNG4,SubspaceOp,nb,60.0,0.02,500,100,100,0.0);
|
||||
for(int n=0;n<nb;n++){
|
||||
Aggregates4D.subspace[n+nb]= Aggregates4D.subspace[n] - g5 * Aggregates4D.subspace[n];
|
||||
Aggregates4D.subspace[n] = Aggregates4D.subspace[n] + g5 * Aggregates4D.subspace[n];
|
||||
}
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Promote to 5D basis " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
for(int n=0;n<nbasis;n++){
|
||||
for(int s=0;s<Ls;s++){
|
||||
InsertSlice(Aggregates4D.subspace[n],Aggregates5D.subspace[n],s,0);
|
||||
}
|
||||
}
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Coarsen the operator " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> Level1Op;
|
||||
|
||||
NonHermitianLinearOperator<DomainWallFermionR,LatticeFermion> LinOpDwf(Ddwf);
|
||||
|
||||
Level1Op LDOp (*Coarse5d,0);
|
||||
|
||||
std::cout<<GridLogMessage << " Callinig Coarsen the operator " <<std::endl;
|
||||
LDOp.CoarsenOperator(FGrid,LinOpDwf,Aggregates5D);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Coarse CG unprec "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
CoarseVector c_src(Coarse5d); c_src=1.0;
|
||||
CoarseVector c_res(Coarse5d);
|
||||
|
||||
LatticeFermion f_src(FGrid); f_src=1.0;
|
||||
LatticeFermion f_res(FGrid);
|
||||
|
||||
RealD tol=1.0e-8;
|
||||
int MaxIt = 10000;
|
||||
|
||||
MdagMLinearOperator<Level1Op,CoarseVector> CoarseMdagM(LDOp);
|
||||
BiCGSTAB<CoarseVector> CoarseBiCGSTAB(tol,MaxIt);
|
||||
ConjugateGradient<CoarseVector> CoarseCG(tol,MaxIt);
|
||||
|
||||
c_res=Zero();
|
||||
CoarseCG(CoarseMdagM,c_src,c_res);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << " Solve " <<std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
|
||||
LatticeFermion src(FGrid); gaussian(RNG5,src);
|
||||
LatticeFermion result(FGrid);
|
||||
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
std::cout<<GridLogMessage << "Done "<< std::endl;
|
||||
std::cout<<GridLogMessage << "**************************************************"<< std::endl;
|
||||
Grid_finalize();
|
||||
|
||||
}
|
Reference in New Issue
Block a user