2016-01-02 14:51:32 +00:00
|
|
|
/*************************************************************************************
|
|
|
|
|
|
|
|
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 */
|
2015-04-26 15:51:09 +01:00
|
|
|
#include <Grid.h>
|
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
using namespace Grid;
|
|
|
|
using namespace Grid::QCD;
|
|
|
|
|
|
|
|
template<class d>
|
|
|
|
struct scal {
|
|
|
|
d internal;
|
|
|
|
};
|
|
|
|
|
2015-04-27 13:45:07 +01:00
|
|
|
Gamma::GammaMatrix Gmu [] = {
|
|
|
|
Gamma::GammaX,
|
|
|
|
Gamma::GammaY,
|
|
|
|
Gamma::GammaZ,
|
|
|
|
Gamma::GammaT
|
|
|
|
};
|
2015-04-26 15:51:09 +01:00
|
|
|
|
2016-01-04 14:18:40 +00:00
|
|
|
bool overlapComms = false;
|
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
int main (int argc, char ** argv)
|
|
|
|
{
|
|
|
|
Grid_init(&argc,&argv);
|
|
|
|
|
2016-01-04 14:18:40 +00:00
|
|
|
if( GridCmdOptionExists(argv,argv+argc,"--asynch") ){
|
|
|
|
overlapComms = true;
|
|
|
|
}
|
2015-05-11 12:43:10 +01:00
|
|
|
|
2015-05-11 18:59:03 +01:00
|
|
|
std::vector<int> latt_size = GridDefaultLatt();
|
2015-07-01 22:45:15 +01:00
|
|
|
std::vector<int> simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd());
|
2015-05-11 18:59:03 +01:00
|
|
|
std::vector<int> mpi_layout = GridDefaultMpi();
|
2015-05-25 13:47:12 +01:00
|
|
|
GridCartesian Grid(latt_size,simd_layout,mpi_layout);
|
|
|
|
GridRedBlackCartesian RBGrid(latt_size,simd_layout,mpi_layout);
|
2015-05-11 18:59:03 +01:00
|
|
|
|
2015-05-19 14:54:42 +01:00
|
|
|
int threads = GridThread::GetThreads();
|
2015-07-23 17:31:13 +01:00
|
|
|
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;
|
2015-05-19 14:54:42 +01:00
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
std::vector<int> seeds({1,2,3,4});
|
|
|
|
GridParallelRNG pRNG(&Grid);
|
2015-05-26 19:54:03 +01:00
|
|
|
pRNG.SeedFixedIntegers(seeds);
|
|
|
|
// pRNG.SeedRandomDevice();
|
2015-04-26 15:51:09 +01:00
|
|
|
|
2015-05-25 13:47:12 +01:00
|
|
|
LatticeFermion src (&Grid); random(pRNG,src);
|
2015-04-26 15:51:09 +01:00
|
|
|
LatticeFermion result(&Grid); result=zero;
|
|
|
|
LatticeFermion ref(&Grid); ref=zero;
|
2015-04-27 13:45:07 +01:00
|
|
|
LatticeFermion tmp(&Grid); tmp=zero;
|
2015-05-25 13:47:12 +01:00
|
|
|
LatticeFermion err(&Grid); tmp=zero;
|
2015-04-26 15:51:09 +01:00
|
|
|
LatticeGaugeField Umu(&Grid); random(pRNG,Umu);
|
|
|
|
std::vector<LatticeColourMatrix> U(4,&Grid);
|
|
|
|
|
2015-04-29 06:50:18 +01:00
|
|
|
double volume=1;
|
|
|
|
for(int mu=0;mu<Nd;mu++){
|
|
|
|
volume=volume*latt_size[mu];
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:57:35 +01:00
|
|
|
// Only one non-zero (y)
|
2015-05-31 15:09:02 +01:00
|
|
|
#if 0
|
2015-05-19 13:57:35 +01:00
|
|
|
Umu=zero;
|
2015-05-25 13:47:12 +01:00
|
|
|
Complex cone(1.0,0.0);
|
2015-05-19 13:57:35 +01:00
|
|
|
for(int nn=0;nn<Nd;nn++){
|
|
|
|
random(pRNG,U[nn]);
|
2016-01-03 01:38:11 +00:00
|
|
|
if(1) {
|
|
|
|
if (nn!=2) { U[nn]=zero; std::cout<<GridLogMessage << "zeroing gauge field in dir "<<nn<<std::endl; }
|
|
|
|
// else { U[nn]= cone;std::cout<<GridLogMessage << "unit gauge field in dir "<<nn<<std::endl; }
|
|
|
|
else { std::cout<<GridLogMessage << "random gauge field in dir "<<nn<<std::endl; }
|
2015-05-26 19:54:03 +01:00
|
|
|
}
|
2016-01-03 01:38:11 +00:00
|
|
|
PokeIndex<LorentzIndex>(Umu,U[nn],nn);
|
2015-05-19 13:57:35 +01:00
|
|
|
}
|
2015-05-31 15:09:02 +01:00
|
|
|
#endif
|
2015-05-19 13:57:35 +01:00
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
for(int mu=0;mu<Nd;mu++){
|
2015-06-30 15:01:44 +01:00
|
|
|
U[mu] = PeekIndex<LorentzIndex>(Umu,mu);
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
|
2015-04-27 13:45:07 +01:00
|
|
|
{ // Naive wilson implementation
|
|
|
|
ref = zero;
|
|
|
|
for(int mu=0;mu<Nd;mu++){
|
|
|
|
// ref = src + Gamma(Gamma::GammaX)* src ; // 1-gamma_x
|
2015-05-15 11:51:15 +01:00
|
|
|
tmp = U[mu]*Cshift(src,mu,1);
|
|
|
|
for(int i=0;i<ref._odata.size();i++){
|
2015-12-10 22:55:00 +00:00
|
|
|
ref._odata[i]+= tmp._odata[i] - Gamma(Gmu[mu])*tmp._odata[i]; ;
|
2015-04-27 13:45:07 +01:00
|
|
|
}
|
|
|
|
|
2015-05-15 11:51:15 +01:00
|
|
|
tmp =adj(U[mu])*src;
|
|
|
|
tmp =Cshift(tmp,mu,-1);
|
|
|
|
for(int i=0;i<ref._odata.size();i++){
|
2015-12-10 22:55:00 +00:00
|
|
|
ref._odata[i]+= tmp._odata[i] + Gamma(Gmu[mu])*tmp._odata[i]; ;
|
2015-04-27 13:45:07 +01:00
|
|
|
}
|
|
|
|
}
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
2015-05-31 15:09:02 +01:00
|
|
|
ref = -0.5*ref;
|
2015-04-26 15:51:09 +01:00
|
|
|
RealD mass=0.1;
|
2016-01-04 14:18:40 +00:00
|
|
|
|
|
|
|
typename WilsonFermionR::ImplParams params;
|
|
|
|
params.overlapCommsCompute = overlapComms;
|
|
|
|
|
|
|
|
WilsonFermionR Dw(Umu,Grid,RBGrid,mass,params);
|
2015-04-29 06:50:18 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Calling Dw"<<std::endl;
|
2015-11-04 09:55:21 +00:00
|
|
|
int ncall=1000;
|
2015-04-29 06:50:18 +01:00
|
|
|
double t0=usecond();
|
|
|
|
for(int i=0;i<ncall;i++){
|
2015-05-19 13:57:35 +01:00
|
|
|
Dw.Dhop(src,result,0);
|
2015-04-29 06:50:18 +01:00
|
|
|
}
|
|
|
|
double t1=usecond();
|
2015-05-31 15:09:02 +01:00
|
|
|
double flops=1344*volume*ncall;
|
2015-04-29 06:50:18 +01:00
|
|
|
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Called Dw"<<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;
|
2015-05-25 13:47:12 +01:00
|
|
|
err = ref-result;
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<<std::endl;
|
2015-05-02 23:42:30 +01:00
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
|
2015-04-29 06:23:56 +01:00
|
|
|
// for(int ss=0;ss<10;ss++ ){
|
|
|
|
for(int ss=0;ss<0;ss++ ){
|
2015-04-26 15:51:09 +01:00
|
|
|
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);
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << ss<< " "<<i<<" "<<j<<" "<< (*ref_p)<<" " <<(*res_p)<<std::endl;
|
2015-04-26 15:51:09 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:57:35 +01:00
|
|
|
{ // Naive wilson dag implementation
|
|
|
|
ref = zero;
|
|
|
|
for(int mu=0;mu<Nd;mu++){
|
|
|
|
|
|
|
|
// ref = src - Gamma(Gamma::GammaX)* src ; // 1+gamma_x
|
|
|
|
tmp = U[mu]*Cshift(src,mu,1);
|
|
|
|
for(int i=0;i<ref._odata.size();i++){
|
2015-12-10 22:55:00 +00:00
|
|
|
ref._odata[i]+= tmp._odata[i] + Gamma(Gmu[mu])*tmp._odata[i]; ;
|
2015-05-19 13:57:35 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
tmp =adj(U[mu])*src;
|
|
|
|
tmp =Cshift(tmp,mu,-1);
|
|
|
|
for(int i=0;i<ref._odata.size();i++){
|
2015-12-10 22:55:00 +00:00
|
|
|
ref._odata[i]+= tmp._odata[i] - Gamma(Gmu[mu])*tmp._odata[i]; ;
|
2015-05-19 13:57:35 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-05-31 15:09:02 +01:00
|
|
|
ref = -0.5*ref;
|
2015-05-19 13:57:35 +01:00
|
|
|
Dw.Dhop(src,result,1);
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "Called DwDag"<<std::endl;
|
|
|
|
std::cout<<GridLogMessage << "norm result "<< norm2(result)<<std::endl;
|
|
|
|
std::cout<<GridLogMessage << "norm ref "<< norm2(ref)<<std::endl;
|
2015-05-25 13:47:12 +01:00
|
|
|
err = ref-result;
|
2015-07-23 17:31:13 +01:00
|
|
|
std::cout<<GridLogMessage << "norm diff "<< norm2(err)<<std::endl;
|
2015-05-19 13:57:35 +01:00
|
|
|
|
2015-04-26 15:51:09 +01:00
|
|
|
Grid_finalize();
|
|
|
|
}
|