/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/Test_stencil.cc Copyright (C) 2015 Author: Peter Boyle Author: Peter Boyle Author: paboyle 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 */ #include using namespace std; using namespace Grid; using namespace Grid::QCD; int main (int argc, char ** argv) { Grid_init(&argc,&argv); // typedef LatticeColourMatrix Field; typedef LatticeComplex Field; typedef typename Field::vector_object vobj; typedef typename vobj::scalar_object sobj; std::vector latt_size = GridDefaultLatt(); std::vector simd_layout = GridDefaultSimd(Nd,vComplex::Nsimd()); std::vector mpi_layout = GridDefaultMpi(); double volume = latt_size[0]*latt_size[1]*latt_size[2]*latt_size[3]; GridCartesian Fine(latt_size,simd_layout,mpi_layout); GridRedBlackCartesian rbFine(latt_size,simd_layout,mpi_layout); GridParallelRNG fRNG(&Fine); // fRNG.SeedRandomDevice(); std::vector seeds({1,2,3,4}); fRNG.SeedFixedIntegers(seeds); Field Foo(&Fine); Field Bar(&Fine); Field Check(&Fine); Field Diff(&Fine); LatticeComplex lex(&Fine); lex = zero; random(fRNG,Foo); gaussian(fRNG,Bar); Integer stride =1000; { double nrm; LatticeComplex coor(&Fine); for(int d=0;d Stencil; for(int dir=0;dir<4;dir++){ for(int disp=0;disp directions(npoint,dir); std::vector displacements(npoint,disp); Stencil myStencil(&Fine,npoint,0,directions,displacements); std::vector ocoor(4); for(int o=0;o compress; myStencil.HaloExchange(Foo,compress); Bar = Cshift(Foo,dir,disp); // Implement a stencil code that should agree with cshift! for(int i=0;ioSites();i++){ int permute_type; StencilEntry *SE; SE = myStencil.GetEntry(permute_type,0,i); if ( SE->_is_local && SE->_permute ) permute(Check._odata[i],Foo._odata[SE->_offset],permute_type); else if (SE->_is_local) Check._odata[i] = Foo._odata[SE->_offset]; else Check._odata[i] = myStencil.CommBuf()[SE->_offset]; } Real nrmC = norm2(Check); Real nrmB = norm2(Bar); Diff = Check-Bar; Real nrm = norm2(Diff); std::cout< coor(4); for(coor[3]=0;coor[3] 0){ std::cout <<"Coor (" << coor[0]<<","< 1.0e-4) exit(-1); } } std::cout< directions(npoint,dir); std::vector displacements(npoint,disp); Stencil EStencil(&rbFine,npoint,Even,directions,displacements); Stencil OStencil(&rbFine,npoint,Odd,directions,displacements); std::vector ocoor(4); for(int o=0;o compress; Bar = Cshift(Foo,dir,disp); if ( disp & 0x1 ) { ECheck.checkerboard = Even; OCheck.checkerboard = Odd; } else { ECheck.checkerboard = Odd; OCheck.checkerboard = Even; } // Implement a stencil code that should agree with that darn cshift! EStencil.HaloExchange(EFoo,compress); for(int i=0;ioSites();i++){ int permute_type; StencilEntry *SE; SE = EStencil.GetEntry(permute_type,0,i); // std::cout << "Even source "<< i<<" -> " <_offset << " "<< SE->_is_local<_is_local && SE->_permute ) permute(OCheck._odata[i],EFoo._odata[SE->_offset],permute_type); else if (SE->_is_local) OCheck._odata[i] = EFoo._odata[SE->_offset]; else OCheck._odata[i] = EStencil.CommBuf()[SE->_offset]; } OStencil.HaloExchange(OFoo,compress); for(int i=0;ioSites();i++){ int permute_type; StencilEntry *SE; SE = OStencil.GetEntry(permute_type,0,i); // std::cout << "ODD source "<< i<<" -> " <_offset << " "<< SE->_is_local<_is_local && SE->_permute ) permute(ECheck._odata[i],OFoo._odata[SE->_offset],permute_type); else if (SE->_is_local) ECheck._odata[i] = OFoo._odata[SE->_offset]; else ECheck._odata[i] = OStencil.CommBuf()[SE->_offset]; } setCheckerboard(Check,ECheck); setCheckerboard(Check,OCheck); Real nrmC = norm2(Check); Real nrmB = norm2(Bar); Diff = Check-Bar; Real nrm = norm2(Diff); std::cout< coor(4); for(coor[3]=0;coor[3] 0){ std::cout <<"Coor (" << coor[0]<<","< 1.0e-4) exit(-1); } } Grid_finalize(); }