mirror of
https://github.com/paboyle/Grid.git
synced 2024-11-09 23:45:36 +00:00
Schur complement based red-black inversion working
This commit is contained in:
parent
ea3240ad55
commit
489b1b9633
@ -24,7 +24,8 @@ int main (int argc, char ** argv)
|
||||
std::vector<int> latt_size = GridDefaultLatt();
|
||||
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplexF::Nsimd());
|
||||
std::vector<int> mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
||||
|
||||
int threads = GridThread::GetThreads();
|
||||
std::cout << "Grid is setup to use "<<threads<<" threads"<<std::endl;
|
||||
@ -36,11 +37,11 @@ int main (int argc, char ** argv)
|
||||
// pRNG.SeedFixedIntegers(seeds);
|
||||
pRNG.SeedRandomDevice();
|
||||
|
||||
LatticeFermion src(&Grid); random(pRNG,src);
|
||||
LatticeFermion src (&Grid); random(pRNG,src);
|
||||
LatticeFermion result(&Grid); result=zero;
|
||||
LatticeFermion ref(&Grid); ref=zero;
|
||||
LatticeFermion err(&Grid);
|
||||
LatticeFermion tmp(&Grid); tmp=zero;
|
||||
LatticeFermion err(&Grid); tmp=zero;
|
||||
LatticeGaugeField Umu(&Grid); random(pRNG,Umu);
|
||||
std::vector<LatticeColourMatrix> U(4,&Grid);
|
||||
|
||||
@ -51,8 +52,11 @@ int main (int argc, char ** argv)
|
||||
|
||||
// Only one non-zero (y)
|
||||
Umu=zero;
|
||||
Complex cone(1.0,0.0);
|
||||
for(int nn=0;nn<Nd;nn++){
|
||||
random(pRNG,U[nn]);
|
||||
if (nn!=0) U[nn]=zero;
|
||||
else U[nn] = cone;
|
||||
pokeIndex<LorentzIndex>(Umu,U[nn],nn);
|
||||
}
|
||||
|
||||
@ -78,7 +82,7 @@ int main (int argc, char ** argv)
|
||||
}
|
||||
|
||||
RealD mass=0.1;
|
||||
WilsonMatrix Dw(Umu,mass);
|
||||
WilsonMatrix Dw(Umu,Grid,RBGrid,mass);
|
||||
|
||||
std::cout << "Calling Dw"<<std::endl;
|
||||
int ncall=1000;
|
||||
@ -93,7 +97,7 @@ int main (int argc, char ** argv)
|
||||
std::cout << "norm result "<< norm2(result)<<std::endl;
|
||||
std::cout << "norm ref "<< norm2(ref)<<std::endl;
|
||||
std::cout << "mflop/s = "<< flops/(t1-t0)<<std::endl;
|
||||
err = ref -result;
|
||||
err = ref-result;
|
||||
std::cout << "norm diff "<< norm2(err)<<std::endl;
|
||||
|
||||
|
||||
@ -129,9 +133,8 @@ int main (int argc, char ** argv)
|
||||
std::cout << "Called DwDag"<<std::endl;
|
||||
std::cout << "norm result "<< norm2(result)<<std::endl;
|
||||
std::cout << "norm ref "<< norm2(ref)<<std::endl;
|
||||
err = ref -result;
|
||||
err = ref-result;
|
||||
std::cout << "norm diff "<< norm2(err)<<std::endl;
|
||||
|
||||
|
||||
Grid_finalize();
|
||||
}
|
||||
|
61
benchmarks/Grid_wilson_cg_prec.cc
Normal file
61
benchmarks/Grid_wilson_cg_prec.cc
Normal file
@ -0,0 +1,61 @@
|
||||
#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
|
||||
};
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
|
||||
std::vector<int> latt_size = GridDefaultLatt();
|
||||
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplexF::Nsimd());
|
||||
std::vector<int> mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(seeds);
|
||||
|
||||
LatticeFermion src(&Grid); random(pRNG,src);
|
||||
RealD nrm = norm2(src);
|
||||
LatticeFermion result(&Grid); result=zero;
|
||||
LatticeGaugeField Umu(&Grid); random(pRNG,Umu);
|
||||
|
||||
std::vector<LatticeColourMatrix> U(4,&Grid);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = peekIndex<LorentzIndex>(Umu,mu);
|
||||
}
|
||||
|
||||
RealD mass=0.5;
|
||||
WilsonMatrix Dw(Umu,Grid,RBGrid,mass);
|
||||
|
||||
// HermitianOperator<WilsonMatrix,LatticeFermion> HermOp(Dw);
|
||||
// ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||
// CG(HermOp,src,result);
|
||||
|
||||
LatticeFermion src_o(&RBGrid);
|
||||
LatticeFermion result_o(&RBGrid);
|
||||
pickCheckerboard(Odd,src_o,src);
|
||||
result_o=zero;
|
||||
|
||||
HermitianCheckerBoardedOperator<WilsonMatrix,LatticeFermion> HermOpEO(Dw);
|
||||
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||
CG(HermOpEO,src_o,result_o);
|
||||
|
||||
Grid_finalize();
|
||||
}
|
48
benchmarks/Grid_wilson_cg_schur.cc
Normal file
48
benchmarks/Grid_wilson_cg_schur.cc
Normal file
@ -0,0 +1,48 @@
|
||||
#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
|
||||
};
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
|
||||
std::vector<int> latt_size = GridDefaultLatt();
|
||||
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplexF::Nsimd());
|
||||
std::vector<int> mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(seeds);
|
||||
|
||||
LatticeGaugeField Umu(&Grid); random(pRNG,Umu);
|
||||
|
||||
LatticeFermion src(&Grid); random(pRNG,src);
|
||||
LatticeFermion result(&Grid); result=zero;
|
||||
LatticeFermion resid(&Grid);
|
||||
|
||||
RealD mass=0.5;
|
||||
WilsonMatrix Dw(Umu,Grid,RBGrid,mass);
|
||||
|
||||
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||
SchurRedBlackSolve<LatticeFermion> SchurSolver(CG);
|
||||
|
||||
SchurSolver(Dw,src,result);
|
||||
|
||||
Grid_finalize();
|
||||
}
|
@ -24,7 +24,8 @@ int main (int argc, char ** argv)
|
||||
std::vector<int> latt_size = GridDefaultLatt();
|
||||
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplexF::Nsimd());
|
||||
std::vector<int> mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
GridParallelRNG pRNG(&Grid); pRNG.SeedFixedIntegers(seeds);
|
||||
@ -46,11 +47,11 @@ int main (int argc, char ** argv)
|
||||
}
|
||||
|
||||
RealD mass=0.5;
|
||||
WilsonMatrix Dw(Umu,mass);
|
||||
WilsonMatrix Dw(Umu,Grid,RBGrid,mass);
|
||||
|
||||
HermitianOperator<WilsonMatrix,LatticeFermion> HermOp(Dw);
|
||||
ConjugateGradient<LatticeFermion> CG(1.0e-8,10000);
|
||||
CG(HermOp,src,result);
|
||||
|
||||
|
||||
Grid_finalize();
|
||||
}
|
||||
|
201
benchmarks/Grid_wilson_evenodd.cc
Normal file
201
benchmarks/Grid_wilson_evenodd.cc
Normal file
@ -0,0 +1,201 @@
|
||||
#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
|
||||
};
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
std::vector<int> latt_size = GridDefaultLatt();
|
||||
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplexF::Nsimd());
|
||||
std::vector<int> mpi_layout = GridDefaultMpi();
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
||||
|
||||
int threads = GridThread::GetThreads();
|
||||
std::cout << "Grid is setup to use "<<threads<<" threads"<<std::endl;
|
||||
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
|
||||
GridParallelRNG pRNG(&Grid);
|
||||
// std::vector<int> seeds({1,2,3,4});
|
||||
// pRNG.SeedFixedIntegers(seeds);
|
||||
pRNG.SeedRandomDevice();
|
||||
|
||||
LatticeFermion src (&Grid); random(pRNG,src);
|
||||
LatticeFermion phi (&Grid); random(pRNG,phi);
|
||||
LatticeFermion chi (&Grid); random(pRNG,chi);
|
||||
LatticeFermion result(&Grid); result=zero;
|
||||
LatticeFermion ref(&Grid); ref=zero;
|
||||
LatticeFermion tmp(&Grid); tmp=zero;
|
||||
LatticeFermion err(&Grid); tmp=zero;
|
||||
LatticeGaugeField Umu(&Grid); random(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)
|
||||
Umu=zero;
|
||||
for(int nn=0;nn<Nd;nn++){
|
||||
random(pRNG,U[nn]);
|
||||
pokeIndex<LorentzIndex>(Umu,U[nn],nn);
|
||||
}
|
||||
|
||||
RealD mass=0.1;
|
||||
|
||||
WilsonMatrix Dw(Umu,Grid,RBGrid,mass);
|
||||
|
||||
LatticeFermion src_e (&RBGrid);
|
||||
LatticeFermion src_o (&RBGrid);
|
||||
LatticeFermion r_e (&RBGrid);
|
||||
LatticeFermion r_o (&RBGrid);
|
||||
LatticeFermion r_eo (&Grid);
|
||||
|
||||
const int Even=0;
|
||||
const int Odd=1;
|
||||
std::cout<<"=========================================================="<<std::endl;
|
||||
std::cout<<"= Testing that Deo + Doe = Dunprec "<<std::endl;
|
||||
std::cout<<"=========================================================="<<std::endl;
|
||||
|
||||
pickCheckerboard(Even,src_e,src);
|
||||
pickCheckerboard(Odd,src_o,src);
|
||||
|
||||
Dw.Meooe(src_e,r_o); std::cout<<"Applied Meo"<<std::endl;
|
||||
Dw.Meooe(src_o,r_e); std::cout<<"Applied Moe"<<std::endl;
|
||||
Dw.Dhop (src,ref,0);
|
||||
|
||||
setCheckerboard(r_eo,r_o);
|
||||
setCheckerboard(r_eo,r_e);
|
||||
|
||||
ref = (-0.5)*ref;
|
||||
err= ref - r_eo;
|
||||
std::cout << "EO norm diff "<< norm2(err)<< " "<<norm2(ref)<< " " << norm2(r_eo) <<std::endl;
|
||||
|
||||
LatticeComplex cerr(&Grid);
|
||||
cerr = localInnerProduct(err,err);
|
||||
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
std::cout<<"= Test Ddagger is the dagger of D by requiring "<<std::endl;
|
||||
std::cout<<"= < phi | Deo | chi > * = < chi | Deo^dag| phi> "<<std::endl;
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
|
||||
LatticeFermion chi_e (&RBGrid);
|
||||
LatticeFermion chi_o (&RBGrid);
|
||||
|
||||
LatticeFermion dchi_e (&RBGrid);
|
||||
LatticeFermion dchi_o (&RBGrid);
|
||||
|
||||
LatticeFermion phi_e (&RBGrid);
|
||||
LatticeFermion phi_o (&RBGrid);
|
||||
|
||||
LatticeFermion dphi_e (&RBGrid);
|
||||
LatticeFermion dphi_o (&RBGrid);
|
||||
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
pickCheckerboard(Even,phi_e,phi);
|
||||
pickCheckerboard(Odd ,phi_o,phi);
|
||||
|
||||
Dw.Meooe(chi_e,dchi_o);
|
||||
Dw.Meooe(chi_o,dchi_e);
|
||||
Dw.MeooeDag(phi_e,dphi_o);
|
||||
Dw.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 <<"e "<<pDce<<" "<<cDpe <<std::endl;
|
||||
std::cout <<"o "<<pDco<<" "<<cDpo <<std::endl;
|
||||
|
||||
std::cout <<"pDce - conj(cDpo) "<< pDce-conj(cDpo) <<std::endl;
|
||||
std::cout <<"pDco - conj(cDpe) "<< pDco-conj(cDpe) <<std::endl;
|
||||
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
std::cout<<"= Test MeeInv Mee = 1 "<<std::endl;
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
|
||||
Dw.Mooee(chi_e,src_e);
|
||||
Dw.MooeeInv(src_e,phi_e);
|
||||
|
||||
Dw.Mooee(chi_o,src_o);
|
||||
Dw.MooeeInv(src_o,phi_o);
|
||||
|
||||
setCheckerboard(phi,phi_e);
|
||||
setCheckerboard(phi,phi_o);
|
||||
|
||||
err = phi-chi;
|
||||
std::cout << "norm diff "<< norm2(err)<< std::endl;
|
||||
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
std::cout<<"= Test MeeInvDag MeeDag = 1 "<<std::endl;
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
|
||||
pickCheckerboard(Even,chi_e,chi);
|
||||
pickCheckerboard(Odd ,chi_o,chi);
|
||||
|
||||
Dw.MooeeDag(chi_e,src_e);
|
||||
Dw.MooeeInvDag(src_e,phi_e);
|
||||
|
||||
Dw.MooeeDag(chi_o,src_o);
|
||||
Dw.MooeeInvDag(src_o,phi_o);
|
||||
|
||||
setCheckerboard(phi,phi_e);
|
||||
setCheckerboard(phi,phi_o);
|
||||
|
||||
err = phi-chi;
|
||||
std::cout << "norm diff "<< norm2(err)<< std::endl;
|
||||
|
||||
std::cout<<"=============================================================="<<std::endl;
|
||||
std::cout<<"= Test MpcDagMpc is Hermitian "<<std::endl;
|
||||
std::cout<<"=============================================================="<<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);
|
||||
RealD t1,t2;
|
||||
|
||||
Dw.MpcDagMpc(chi_e,dchi_e,t1,t2);
|
||||
Dw.MpcDagMpc(chi_o,dchi_o,t1,t2);
|
||||
|
||||
Dw.MpcDagMpc(phi_e,dphi_e,t1,t2);
|
||||
Dw.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 <<"e "<<pDce<<" "<<cDpe <<std::endl;
|
||||
std::cout <<"o "<<pDco<<" "<<cDpo <<std::endl;
|
||||
|
||||
std::cout <<"pDce - conj(cDpo) "<< pDco-conj(cDpo) <<std::endl;
|
||||
std::cout <<"pDco - conj(cDpe) "<< pDce-conj(cDpe) <<std::endl;
|
||||
|
||||
Grid_finalize();
|
||||
}
|
@ -283,6 +283,7 @@ namespace Optimization {
|
||||
//////////////////////////////////////////////////////////////////////////////////////
|
||||
// Here assign types
|
||||
namespace Grid {
|
||||
|
||||
typedef __m128 SIMD_Ftype; // Single precision type
|
||||
typedef __m128d SIMD_Dtype; // Double precision type
|
||||
typedef __m128i SIMD_Itype; // Integer type
|
||||
|
@ -13,31 +13,24 @@
|
||||
namespace Grid {
|
||||
|
||||
// To take the floating point type of real/complex type
|
||||
template <typename T>
|
||||
struct RealPart {
|
||||
typedef T type;
|
||||
};
|
||||
template <typename T>
|
||||
struct RealPart< std::complex<T> >{
|
||||
template <typename T> struct RealPart {
|
||||
typedef T type;
|
||||
};
|
||||
template <typename T> struct RealPart< std::complex<T> >{
|
||||
typedef T type;
|
||||
};
|
||||
|
||||
// type alias used to simplify the syntax of std::enable_if
|
||||
template <typename T> using Invoke =
|
||||
typename T::type;
|
||||
template <typename Condition, typename ReturnType> using EnableIf =
|
||||
Invoke<std::enable_if<Condition::value, ReturnType>>;
|
||||
template <typename Condition, typename ReturnType> using NotEnableIf =
|
||||
Invoke<std::enable_if<!Condition::value, ReturnType>>;
|
||||
template <typename T> using Invoke = typename T::type;
|
||||
template <typename Condition, typename ReturnType> using EnableIf = Invoke<std::enable_if<Condition::value, ReturnType>>;
|
||||
template <typename Condition, typename ReturnType> using NotEnableIf= Invoke<std::enable_if<!Condition::value, ReturnType>>;
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////
|
||||
// Check for complexity with type traits
|
||||
template <typename T>
|
||||
struct is_complex : std::false_type {};
|
||||
template < typename T >
|
||||
struct is_complex< std::complex<T> >: std::true_type {};
|
||||
template <typename T> struct is_complex : std::false_type {};
|
||||
template < typename T > struct is_complex< std::complex<T> >: std::true_type {};
|
||||
////////////////////////////////////////////////////////
|
||||
// Define the operation templates functors
|
||||
// general forms to allow for vsplat syntax
|
||||
@ -86,8 +79,6 @@ namespace Grid {
|
||||
Grid_simd(Real a){
|
||||
vsplat(*this,Scalar_type(a));
|
||||
};
|
||||
|
||||
|
||||
|
||||
///////////////////////////////////////////////
|
||||
// mac, mult, sub, add, adj
|
||||
@ -126,10 +117,6 @@ namespace Grid {
|
||||
friend inline void vtrue (Grid_simd &ret){vsplat(ret,0xFFFFFFFF);}
|
||||
template < class S = Scalar_type, EnableIf<std::is_integral < S >, int> = 0 >
|
||||
friend inline void vfalse(vInteger &ret){vsplat(ret,0);}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// Arithmetic operator overloads +,-,*
|
||||
@ -165,7 +152,6 @@ namespace Grid {
|
||||
ret.v = binary<Vector_type>(a.v,b.v, MultSIMD());
|
||||
return ret;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
// FIXME: gonna remove these load/store, get, set, prefetch
|
||||
|
@ -1,8 +1,9 @@
|
||||
#include "Grid.h"
|
||||
|
||||
//DEBUG
|
||||
#ifdef SSE4
|
||||
#include "simd/Grid_vector_types.h"
|
||||
|
||||
#endif
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
|
Loading…
Reference in New Issue
Block a user