mirror of
https://github.com/paboyle/Grid.git
synced 2025-06-14 13:57:07 +01:00
Big updates with progress towards wilson matrix
This commit is contained in:
@ -5,6 +5,11 @@ using namespace std;
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
|
||||
template<class d>
|
||||
struct scal {
|
||||
d internal;
|
||||
};
|
||||
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
@ -22,22 +27,33 @@ int main (int argc, char ** argv)
|
||||
GridSerialRNG sRNG;
|
||||
sRNG.SeedRandomDevice();
|
||||
|
||||
SpinMatrix ident=zero;
|
||||
SpinMatrix ident; ident=zero;
|
||||
SpinMatrix rnd ; random(sRNG,rnd);
|
||||
|
||||
SpinMatrix ll=zero;
|
||||
SpinMatrix rr=zero;
|
||||
SpinMatrix ll; ll=zero;
|
||||
SpinMatrix rr; rr=zero;
|
||||
SpinMatrix result;
|
||||
|
||||
SpinVector lv; random(sRNG,lv);
|
||||
SpinVector rv; random(sRNG,rv);
|
||||
|
||||
std::cout << " Is pod " << std::is_pod<SpinVector>::value << std::endl;
|
||||
std::cout << " Is pod double " << std::is_pod<double>::value << std::endl;
|
||||
std::cout << " Is pod ComplexF " << std::is_pod<ComplexF>::value << std::endl;
|
||||
std::cout << " Is pod scal<double> " << std::is_pod<scal<double> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<double> " << std::is_pod<iScalar<double> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<ComplexF> " << std::is_pod<iScalar<ComplexF> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<vComplexF> " << std::is_pod<iScalar<vComplexF> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<vComplexD> " << std::is_pod<iScalar<vComplexD> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<vRealF> " << std::is_pod<iScalar<vRealF> >::value << std::endl;
|
||||
std::cout << " Is pod Scalar<vRealD> " << std::is_pod<iScalar<vRealD> >::value << std::endl;
|
||||
|
||||
for(int a=0;a<Ns;a++){
|
||||
ident()(a,a) = 1.0;
|
||||
}
|
||||
|
||||
const Gamma::GammaMatrix *g = Gamma::GammaMatrices;
|
||||
const char **list = Gamma::GammaMatrixNames;
|
||||
const char **list = Gamma::GammaMatrixNames;
|
||||
|
||||
result =ll*Gamma(g[0])*rr;
|
||||
result =ll*Gamma(g[0]);
|
||||
|
@ -49,7 +49,6 @@ int main (int argc, char ** argv)
|
||||
Plaq = Plaq + trace(U[mu]*Cshift(U[nu],mu,1)*adj(Cshift(U[mu],nu,1))*adj(U[nu]));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
double vol = Fine.gSites();
|
||||
Complex PlaqScale(1.0/vol/6.0/3.0);
|
||||
@ -58,7 +57,8 @@ int main (int argc, char ** argv)
|
||||
sliceSum(Plaq,Plaq_T,Nd-1);
|
||||
int Nt = Plaq_T.size();
|
||||
|
||||
TComplex Plaq_T_sum=zero;
|
||||
TComplex Plaq_T_sum;
|
||||
Plaq_T_sum=zero;
|
||||
for(int t=0;t<Nt;t++){
|
||||
Plaq_T_sum = Plaq_T_sum+Plaq_T[t];
|
||||
Complex Pt=TensorRemove(Plaq_T[t]);
|
||||
|
166
tests/Grid_simd.cc
Normal file
166
tests/Grid_simd.cc
Normal file
@ -0,0 +1,166 @@
|
||||
#include <Grid.h>
|
||||
#include <parallelIO/GridNerscIO.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
|
||||
class funcPlus {
|
||||
public:
|
||||
funcPlus() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = i1+i2;}
|
||||
std::string name(void) const { return std::string("Plus"); }
|
||||
};
|
||||
class funcMinus {
|
||||
public:
|
||||
funcMinus() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = i1-i2;}
|
||||
std::string name(void) const { return std::string("Minus"); }
|
||||
};
|
||||
class funcTimes {
|
||||
public:
|
||||
funcTimes() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = i1*i2;}
|
||||
std::string name(void) const { return std::string("Times"); }
|
||||
};
|
||||
class funcConj {
|
||||
public:
|
||||
funcConj() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = conj(i1);}
|
||||
std::string name(void) const { return std::string("Conj"); }
|
||||
};
|
||||
class funcAdj {
|
||||
public:
|
||||
funcAdj() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = adj(i1);}
|
||||
std::string name(void) const { return std::string("Adj"); }
|
||||
};
|
||||
|
||||
class funcTimesI {
|
||||
public:
|
||||
funcTimesI() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = timesI(i1);}
|
||||
std::string name(void) const { return std::string("timesI"); }
|
||||
};
|
||||
|
||||
class funcTimesMinusI {
|
||||
public:
|
||||
funcTimesMinusI() {};
|
||||
template<class vec> void operator()(vec &rr,vec &i1,vec &i2) const { rr = timesMinusI(i1);}
|
||||
std::string name(void) const { return std::string("timesMinusI"); }
|
||||
};
|
||||
|
||||
template<class scal, class vec,class functor >
|
||||
void Tester(const functor &func)
|
||||
{
|
||||
GridSerialRNG sRNG;
|
||||
sRNG.SeedRandomDevice();
|
||||
|
||||
int Nsimd = vec::Nsimd();
|
||||
|
||||
std::vector<scal> input1(Nsimd);
|
||||
std::vector<scal> input2(Nsimd);
|
||||
std::vector<scal> result(Nsimd);
|
||||
std::vector<scal> reference(Nsimd);
|
||||
|
||||
std::vector<vec,alignedAllocator<vec> > buf(3);
|
||||
vec & v_input1 = buf[0];
|
||||
vec & v_input2 = buf[1];
|
||||
vec & v_result = buf[2];
|
||||
|
||||
|
||||
for(int i=0;i<Nsimd;i++){
|
||||
random(sRNG,input1[i]);
|
||||
random(sRNG,input2[i]);
|
||||
random(sRNG,result[i]);
|
||||
}
|
||||
|
||||
Gmerge(v_input1,input1);
|
||||
Gmerge(v_input2,input2);
|
||||
Gmerge(v_result,result);
|
||||
|
||||
func(v_result,v_input1,v_input2);
|
||||
|
||||
for(int i=0;i<Nsimd;i++) {
|
||||
func(reference[i],input1[i],input2[i]);
|
||||
}
|
||||
|
||||
Gextract(v_result,result);
|
||||
std::cout << " " << func.name()<<std::endl;
|
||||
|
||||
int ok=0;
|
||||
for(int i=0;i<Nsimd;i++){
|
||||
if ( abs(reference[i]-result[i])>0){
|
||||
std::cout<< "*****" << std::endl;
|
||||
std::cout<< "["<<i<<"] "<< abs(reference[i]-result[i]) << " " <<reference[i]<< " " << result[i]<<std::endl;
|
||||
ok++;
|
||||
}
|
||||
}
|
||||
if ( ok==0 ) std::cout << " OK!" <<std::endl;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
std::vector<int> simd_layout({1,1,2,2});
|
||||
std::vector<int> mpi_layout ({1,1,1,1});
|
||||
std::vector<int> latt_size ({8,8,8,8});
|
||||
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
|
||||
// Insist that operations on random scalars gives
|
||||
// identical results to on vectors.
|
||||
|
||||
Tester<RealD,vRealD>(funcPlus());
|
||||
|
||||
std::cout << "==================================="<< std::endl;
|
||||
std::cout << "Testing vComplexF "<<std::endl;
|
||||
std::cout << "==================================="<< std::endl;
|
||||
|
||||
Tester<ComplexF,vComplexF>(funcTimesI());
|
||||
Tester<ComplexF,vComplexF>(funcTimesMinusI());
|
||||
Tester<ComplexF,vComplexF>(funcPlus());
|
||||
Tester<ComplexF,vComplexF>(funcMinus());
|
||||
Tester<ComplexF,vComplexF>(funcTimes());
|
||||
Tester<ComplexF,vComplexF>(funcConj());
|
||||
Tester<ComplexF,vComplexF>(funcAdj());
|
||||
|
||||
std::cout << "==================================="<< std::endl;
|
||||
std::cout << "Testing vComplexD "<<std::endl;
|
||||
std::cout << "==================================="<< std::endl;
|
||||
|
||||
|
||||
Tester<ComplexD,vComplexD>(funcTimesI());
|
||||
Tester<ComplexD,vComplexD>(funcTimesMinusI());
|
||||
Tester<ComplexD,vComplexD>(funcPlus());
|
||||
Tester<ComplexD,vComplexD>(funcMinus());
|
||||
Tester<ComplexD,vComplexD>(funcTimes());
|
||||
Tester<ComplexD,vComplexD>(funcConj());
|
||||
Tester<ComplexD,vComplexD>(funcAdj());
|
||||
|
||||
std::cout << "==================================="<< std::endl;
|
||||
std::cout << "Testing vRealF "<<std::endl;
|
||||
std::cout << "==================================="<< std::endl;
|
||||
|
||||
|
||||
Tester<RealF,vRealF>(funcPlus());
|
||||
Tester<RealF,vRealF>(funcMinus());
|
||||
Tester<RealF,vRealF>(funcTimes());
|
||||
Tester<RealF,vRealF>(funcAdj());
|
||||
|
||||
std::cout << "==================================="<< std::endl;
|
||||
std::cout << "Testing vRealD "<<std::endl;
|
||||
std::cout << "==================================="<< std::endl;
|
||||
|
||||
Tester<RealD,vRealD>(funcPlus());
|
||||
Tester<RealD,vRealD>(funcMinus());
|
||||
Tester<RealD,vRealD>(funcTimes());
|
||||
Tester<RealD,vRealD>(funcAdj());
|
||||
|
||||
Grid_finalize();
|
||||
}
|
@ -4,60 +4,37 @@ using namespace std;
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
|
||||
template<class vobj>
|
||||
class SimpleCompressor {
|
||||
public:
|
||||
void Point(int) {};
|
||||
|
||||
vobj operator() (vobj &arg) {
|
||||
return arg;
|
||||
}
|
||||
};
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
std::vector<int> latt_size (4);
|
||||
std::vector<int> simd_layout(4);
|
||||
std::vector<int> mpi_layout (4);
|
||||
std::vector<int> simd_layout({1,1,2,2});
|
||||
std::vector<int> mpi_layout ({2,2,2,2});
|
||||
std::vector<int> latt_size ({8,8,8,8});
|
||||
|
||||
int omp=1;
|
||||
int lat=8;
|
||||
|
||||
mpi_layout[0]=1;
|
||||
mpi_layout[1]=1;
|
||||
mpi_layout[2]=1;
|
||||
mpi_layout[3]=1;
|
||||
|
||||
latt_size[0] = lat;
|
||||
latt_size[1] = lat;
|
||||
latt_size[2] = lat;
|
||||
latt_size[3] = lat;
|
||||
double volume = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3];
|
||||
double volume = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3];
|
||||
|
||||
#ifdef AVX512
|
||||
simd_layout[0] = 1;
|
||||
simd_layout[1] = 2;
|
||||
simd_layout[2] = 2;
|
||||
simd_layout[3] = 2;
|
||||
#endif
|
||||
#if defined (AVX1)|| defined (AVX2)
|
||||
simd_layout[0] = 1;
|
||||
simd_layout[1] = 1;
|
||||
simd_layout[2] = 2;
|
||||
simd_layout[3] = 2;
|
||||
#endif
|
||||
#if defined (SSE2)
|
||||
simd_layout[0] = 1;
|
||||
simd_layout[1] = 1;
|
||||
simd_layout[2] = 1;
|
||||
simd_layout[3] = 2;
|
||||
#endif
|
||||
|
||||
GridCartesian Fine(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian rbFine(latt_size,simd_layout,mpi_layout);
|
||||
GridParallelRNG fRNG(&Fine);
|
||||
fRNG.SeedRandomDevice();
|
||||
|
||||
LatticeColourMatrix Foo(&Fine);
|
||||
LatticeColourMatrix Bar(&Fine);
|
||||
LatticeColourMatrix Check(&Fine);
|
||||
LatticeColourMatrix Diff(&Fine);
|
||||
|
||||
random(fRNG,Foo);
|
||||
gaussian(fRNG,Bar);
|
||||
GridCartesian Fine(latt_size,simd_layout,mpi_layout);
|
||||
GridRedBlackCartesian rbFine(latt_size,simd_layout,mpi_layout);
|
||||
GridParallelRNG fRNG(&Fine);
|
||||
fRNG.SeedRandomDevice();
|
||||
|
||||
LatticeColourMatrix Foo(&Fine);
|
||||
LatticeColourMatrix Bar(&Fine);
|
||||
LatticeColourMatrix Check(&Fine);
|
||||
LatticeColourMatrix Diff(&Fine);
|
||||
|
||||
random(fRNG,Foo);
|
||||
gaussian(fRNG,Bar);
|
||||
|
||||
|
||||
for(int dir=0;dir<4;dir++){
|
||||
@ -86,7 +63,8 @@ int main (int argc, char ** argv)
|
||||
fflush(stdout);
|
||||
std::vector<vColourMatrix,alignedAllocator<vColourMatrix> > comm_buf(myStencil._unified_buffer_size);
|
||||
printf("calling halo exchange\n");fflush(stdout);
|
||||
myStencil.HaloExchange(Foo,comm_buf);
|
||||
SimpleCompressor<vColourMatrix> compress;
|
||||
myStencil.HaloExchange(Foo,comm_buf,compress);
|
||||
|
||||
Bar = Cshift(Foo,dir,disp);
|
||||
|
||||
|
69
tests/Grid_wilson.cc
Normal file
69
tests/Grid_wilson.cc
Normal file
@ -0,0 +1,69 @@
|
||||
#include <Grid.h>
|
||||
#include <parallelIO/GridNerscIO.h>
|
||||
|
||||
using namespace std;
|
||||
using namespace Grid;
|
||||
using namespace Grid::QCD;
|
||||
|
||||
template<class d>
|
||||
struct scal {
|
||||
d internal;
|
||||
};
|
||||
|
||||
|
||||
int main (int argc, char ** argv)
|
||||
{
|
||||
Grid_init(&argc,&argv);
|
||||
|
||||
std::vector<int> simd_layout({1,1,2,2});
|
||||
std::vector<int> mpi_layout ({1,1,1,1});
|
||||
std::vector<int> latt_size ({8,8,8,8});
|
||||
|
||||
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
||||
std::vector<int> seeds({1,2,3,4});
|
||||
|
||||
GridParallelRNG pRNG(&Grid);
|
||||
// pRNG.SeedFixedIntegers(seeds);
|
||||
pRNG.SeedRandomDevice();
|
||||
|
||||
LatticeFermion src(&Grid); random(pRNG,src);
|
||||
LatticeFermion result(&Grid); result=zero;
|
||||
LatticeFermion ref(&Grid); ref=zero;
|
||||
LatticeGaugeField Umu(&Grid); random(pRNG,Umu);
|
||||
std::vector<LatticeColourMatrix> U(4,&Grid);
|
||||
|
||||
for(int mu=0;mu<Nd;mu++){
|
||||
U[mu] = 1.0;
|
||||
pokeIndex<3>(Umu,U[mu],mu);
|
||||
}
|
||||
|
||||
{
|
||||
int mu=0;
|
||||
// ref = src + Gamma(Gamma::GammaX)* src ; // 1-gamma_x
|
||||
ref = src;
|
||||
ref = U[0]*Cshift(ref,0,1);
|
||||
}
|
||||
|
||||
RealD mass=0.1;
|
||||
WilsonMatrix Dw(Umu,mass);
|
||||
std::cout << "Calling Dw"<<std::endl;
|
||||
Dw.multiply(src,result);
|
||||
std::cout << "Called Dw"<<std::endl;
|
||||
std::cout << "norm result "<< norm2(result)<<std::endl;
|
||||
std::cout << "norm ref "<< norm2(ref)<<std::endl;
|
||||
|
||||
for(int ss=0;ss<10;ss++ ){
|
||||
for(int i=0;i<Ns;i++){
|
||||
for(int j=0;j<Nc;j++){
|
||||
ComplexF * ref_p = (ComplexF *)&ref._odata[ss]()(i)(j);
|
||||
ComplexF * res_p = (ComplexF *)&result._odata[ss]()(i)(j);
|
||||
std::cout << ss<< " "<<i<<" "<<j<<" "<< (*ref_p)<<" " <<(*res_p)<<std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
ref = ref -result;
|
||||
std::cout << "norm diff "<< norm2(ref)<<std::endl;
|
||||
|
||||
Grid_finalize();
|
||||
}
|
@ -5,7 +5,7 @@ AM_LDFLAGS = -L$(top_srcdir)/lib
|
||||
#
|
||||
# Test code
|
||||
#
|
||||
bin_PROGRAMS = Grid_main Grid_stencil Grid_nersc_io Grid_cshift Grid_gamma
|
||||
bin_PROGRAMS = Grid_main Grid_stencil Grid_nersc_io Grid_cshift Grid_gamma Grid_wilson Grid_simd
|
||||
|
||||
Grid_main_SOURCES = Grid_main.cc
|
||||
Grid_main_LDADD = -lGrid
|
||||
@ -21,3 +21,9 @@ Grid_gamma_LDADD = -lGrid
|
||||
|
||||
Grid_stencil_SOURCES = Grid_stencil.cc
|
||||
Grid_stencil_LDADD = -lGrid
|
||||
|
||||
Grid_wilson_SOURCES = Grid_wilson.cc
|
||||
Grid_wilson_LDADD = -lGrid
|
||||
|
||||
Grid_simd_SOURCES = Grid_simd.cc
|
||||
Grid_simd_LDADD = -lGrid
|
||||
|
Reference in New Issue
Block a user