/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: tests/core/Test_meson_field.cc Copyright (C) 2015-2018 Author: Felix Erben 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 #include using namespace Grid; 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; int main(int argc, char *argv[]) { // initialization Grid_init(&argc, &argv); std::cout << GridLogMessage << "Grid initialized" << std::endl; // Lattice and rng setup Coordinate latt_size = GridDefaultLatt(); Coordinate simd_layout = GridDefaultSimd(4, vComplex::Nsimd()); Coordinate mpi_layout = GridDefaultMpi(); GridCartesian grid(latt_size,simd_layout,mpi_layout); int Nt = GridDefaultLatt()[Tp]; Lattice> t(&grid); LatticeCoordinate(t, Tp); std::vector seeds({1,2,3,4}); GridParallelRNG pRNG(&grid); pRNG.SeedFixedIntegers(seeds); // MesonField lhs and rhs vectors std::vector phi(VDIM,&grid); std::cout << GridLogMessage << "Initialising random meson fields" << std::endl; for (unsigned int i = 0; i < VDIM; ++i){ random(pRNG,phi[i]); } std::cout << GridLogMessage << "Meson fields initialised, rho non-zero only for t = " << TSRC << std::endl; // Gamma matrices used in the contraction std::vector Gmu = { Gamma::Algebra::GammaX, Gamma::Algebra::GammaY, Gamma::Algebra::GammaZ, Gamma::Algebra::GammaT }; // momentum phases e^{ipx} std::vector> momenta = { {0.,0.,0.}, {1.,0.,0.}, {1.,1.,0.}, {1.,1.,1.}, {2.,0.,0.} }; // 5 momenta x VDIMxVDIM = 125 calls (x 16 spins) 1.4s => 1400/125 ~10ms per call 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; std::vector 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]); } std::cout << GridLogMessage << "Computing complex phases done." << std::endl; Eigen::Tensor Mpp(momenta.size(),Gmu.size(),Nt,VDIM,VDIM); Eigen::Tensor Mpp_gpu(momenta.size(),Gmu.size(),Nt,VDIM,VDIM); // timer double start,stop; //execute meson field routine std::cout << GridLogMessage << "Meson Field Warmup Begin" << std::endl; A2Autils::MesonField(Mpp,&phi[0],&phi[0],Gmu,phases,Tp); std::cout << GridLogMessage << "Meson Field Timing Begin" << std::endl; start = usecond(); A2Autils::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; std::cout << GridLogMessage << "Meson Field GPU Warmup Begin" << std::endl; A2Autils::MesonFieldGPU(Mpp_gpu,&phi[0],&phi[0],Gmu,phases,Tp); std::cout << GridLogMessage << "Meson Field GPU Timing Begin" << std::endl; start = usecond(); A2Autils::MesonFieldGPU(Mpp_gpu,&phi[0],&phi[0],Gmu,phases,Tp); stop = usecond(); std::cout << GridLogMessage << "M_gpu(phi,phi) created, execution time " << stop-start << " us" << std::endl; for(int mom=0;mom