1
0
mirror of https://github.com/paboyle/Grid.git synced 2024-11-15 02:05:37 +00:00
Grid/tests/Test_meson_field.cc

163 lines
5.5 KiB
C++
Raw Normal View History

2021-07-02 15:51:19 +01:00
/*************************************************************************************
Grid physics library, www.github.com/paboyle/Grid
Source file: tests/core/Test_meson_field.cc
Copyright (C) 2015-2018
Author: Felix Erben <felix.erben@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
*************************************************************************************/
#include <Grid/Grid.h>
#include <Grid/qcd/utils/A2Autils.h>
using namespace Grid;
2021-07-06 11:42:36 +01:00
const int TSRC = 0; //timeslice where rho is nonzero
const int VDIM = 5; //length of each vector
typedef typename DomainWallFermionD::ComplexField ComplexField;
typedef typename DomainWallFermionD::FermionField FermionField;
2021-07-02 15:51:19 +01:00
int main(int argc, char *argv[])
{
// initialization
Grid_init(&argc, &argv);
std::cout << GridLogMessage << "Grid initialized" << std::endl;
2021-07-06 11:42:36 +01:00
// Lattice and rng setup
2021-07-02 15:51:19 +01:00
Coordinate latt_size = GridDefaultLatt();
Coordinate simd_layout = GridDefaultSimd(4, vComplex::Nsimd());
Coordinate mpi_layout = GridDefaultMpi();
GridCartesian grid(latt_size,simd_layout,mpi_layout);
2021-07-06 11:42:36 +01:00
int Nt = GridDefaultLatt()[Tp];
Lattice<iScalar<vInteger>> t(&grid);
LatticeCoordinate(t, Tp);
2021-07-05 14:41:52 +01:00
std::vector<int> seeds({1,2,3,4});
GridParallelRNG pRNG(&grid);
pRNG.SeedFixedIntegers(seeds);
2021-07-06 11:42:36 +01:00
// MesonField lhs and rhs vectors
std::vector<FermionField> phi(VDIM,&grid);
std::cout << GridLogMessage << "Initialising random meson fields" << std::endl;
for (unsigned int i = 0; i < VDIM; ++i){
2021-07-05 14:41:52 +01:00
random(pRNG,phi[i]);
}
2021-07-06 11:42:36 +01:00
std::cout << GridLogMessage << "Meson fields initialised, rho non-zero only for t = " << TSRC << std::endl;
2021-07-02 15:51:19 +01:00
// Gamma matrices used in the contraction
2021-07-05 14:41:52 +01:00
std::vector<Gamma::Algebra> Gmu = {
2021-07-02 15:51:19 +01:00
Gamma::Algebra::GammaX,
Gamma::Algebra::GammaY,
Gamma::Algebra::GammaZ,
Gamma::Algebra::GammaT
};
// momentum phases e^{ipx}
std::vector<std::vector<double>> momenta = {
{0.,0.,0.},
{1.,0.,0.},
{1.,1.,0.},
{1.,1.,1.},
{2.,0.,0.}
};
2024-10-18 16:42:30 +01:00
// 5 momenta x VDIMxVDIM = 125 calls (x 16 spins) 1.4s => 1400/125 ~10ms per call
2021-07-06 11:42:36 +01:00
std::cout << GridLogMessage << "Meson fields will be created for " << Gmu.size() << " Gamma matrices and " << momenta.size() << " momenta." << std::endl;
std::cout << GridLogMessage << "Computing complex phases" << std::endl;
2021-07-02 15:51:19 +01:00
std::vector<ComplexField> phases(momenta.size(),&grid);
ComplexField coor(&grid);
Complex Ci(0.0,1.0);
for (unsigned int j = 0; j < momenta.size(); ++j)
{
phases[j] = Zero();
for(unsigned int mu = 0; mu < momenta[j].size(); mu++)
{
LatticeCoordinate(coor, mu);
phases[j] = phases[j] + momenta[j][mu]/GridDefaultLatt()[mu]*coor;
}
phases[j] = exp((Real)(2*M_PI)*Ci*phases[j]);
}
2021-07-06 11:42:36 +01:00
std::cout << GridLogMessage << "Computing complex phases done." << std::endl;
2021-07-02 15:51:19 +01:00
2021-07-06 11:42:36 +01:00
Eigen::Tensor<ComplexD,5, Eigen::RowMajor> Mpp(momenta.size(),Gmu.size(),Nt,VDIM,VDIM);
2024-10-18 16:42:30 +01:00
Eigen::Tensor<ComplexD,5, Eigen::RowMajor> Mpp_gpu(momenta.size(),Gmu.size(),Nt,VDIM,VDIM);
2021-07-02 15:51:19 +01:00
2021-07-06 11:42:36 +01:00
// timer
double start,stop;
2021-07-05 14:41:52 +01:00
2021-07-06 11:42:36 +01:00
//execute meson field routine
2024-10-18 16:42:30 +01:00
std::cout << GridLogMessage << "Meson Field Warmup Begin" << std::endl;
A2Autils<WilsonImplR>::MesonField(Mpp,&phi[0],&phi[0],Gmu,phases,Tp);
std::cout << GridLogMessage << "Meson Field Timing Begin" << std::endl;
2021-07-06 11:42:36 +01:00
start = usecond();
A2Autils<WilsonImplR>::MesonField(Mpp,&phi[0],&phi[0],Gmu,phases,Tp);
stop = usecond();
std::cout << GridLogMessage << "M(phi,phi) created, execution time " << stop-start << " us" << std::endl;
2024-10-18 16:42:30 +01:00
std::cout << GridLogMessage << "Meson Field GPU Warmup Begin" << std::endl;
A2Autils<WilsonImplR>::MesonFieldGPU(Mpp_gpu,&phi[0],&phi[0],Gmu,phases,Tp);
std::cout << GridLogMessage << "Meson Field GPU Timing Begin" << std::endl;
2021-07-06 11:42:36 +01:00
start = usecond();
2024-10-18 16:42:30 +01:00
A2Autils<WilsonImplR>::MesonFieldGPU(Mpp_gpu,&phi[0],&phi[0],Gmu,phases,Tp);
2021-07-06 11:42:36 +01:00
stop = usecond();
2024-10-18 16:42:30 +01:00
std::cout << GridLogMessage << "M_gpu(phi,phi) created, execution time " << stop-start << " us" << std::endl;
for(int mom=0;mom<momenta.size();mom++){
for(int mu=0;mu<Gmu.size();mu++){
for(int t=0;t<Nt;t++){
for(int v=0;v<VDIM;v++){
for(int w=0;w<VDIM;w++){
std::cout << GridLogMessage
<< " " << mom
<< " " << mu
<< " " << t
<< " " << v
<< " " << w
<< " " << Mpp_gpu(mom,mu,t,v,w)
<< " " << Mpp(mom,mu,t,v,w) << std::endl;
}
}
}
}
}
2021-07-05 14:52:00 +01:00
std::string FileName = "Meson_Fields";
#ifdef HAVE_HDF5
2021-07-06 11:42:36 +01:00
using Default_Reader = Grid::Hdf5Reader;
using Default_Writer = Grid::Hdf5Writer;
FileName.append(".h5");
2021-07-05 14:52:00 +01:00
#else
2021-07-06 11:42:36 +01:00
using Default_Reader = Grid::BinaryReader;
using Default_Writer = Grid::BinaryWriter;
FileName.append(".bin");
2021-07-05 14:52:00 +01:00
#endif
2024-10-18 16:42:30 +01:00
{
Default_Writer w(FileName);
write(w,"phi_phi",Mpp);
write(w,"phi_phi_gpu",Mpp_gpu);
}
2021-07-02 15:51:19 +01:00
// epilogue
std::cout << GridLogMessage << "Grid is finalizing now" << std::endl;
Grid_finalize();
return EXIT_SUCCESS;
}