/************************************************************************************* Grid physics library, www.github.com/paboyle/Grid Source file: ./tests/debug/Test_coarse_v2_coarsen.cc Copyright (C) 2026 Author: Peter Boyle 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 */ // // Coarsen the same fine operator two ways and compare the matrix elements. // // V1 : existing mrhs CoarsenOperator, vectorised coarse space matched to // the fine SIMD layout, single RHS fine applications // V2 : D+1 CoarsenOperator, unvectorised sComplexD coarse space, the batch // of phased basis vectors carried in the rhs direction and applied // through MrhsPromotedOperator // // BLAS_A is written by GridtoBLAS in lSite order, which does not depend on // the SIMD layout, so the two are directly comparable. // #include using namespace Grid; const int nbasis = 8; const int batch = 9; typedef vSpinColourVector FineObj; typedef vTComplex CComplexV; // vectorised coarse space, V1 reference typedef sTComplexD CComplexS; // unvectorised coarse space, V2 typedef MultiGeneralCoarsenedMatrix MrhsV1; typedef MultiGeneralCoarsenedOperatorV2 MrhsV2; template void ReadMatrix(Op &O,int npoint,std::vector > &host) { typedef typename Op::calcMatrix calcMatrix; host.resize(npoint); for(int p=0;pNsimd() << " coarse V1 "<Nsimd() << " coarse V2 "<Nsimd()<({1,2,3,4})); LatticeGaugeFieldD Umu(FineGrid); SU::HotConfiguration(pRNG,Umu); RealD mass = 0.1; WilsonFermionD Dw(Umu,*FineGrid,*FrbGrid,mass); MdagMLinearOperator HermOp(Dw); //////////////////////////////////////////////// // One random subspace, two copies: CoarsenOperator orthogonalises in place //////////////////////////////////////////////// Aggregation Subspace(CoarseV,FineGrid,0); std::vector subspace(nbasis,FineGrid); for(int i=0;i MrhsHermOp(HermOp,FineGrid,batch); std::cout << GridLogMessage << "V2 CoarsenOperator (D+1)" << std::endl; OpV2.CoarsenOperator(MrhsHermOp,FineGridMulti,subspace,CoarseS); //////////////////////////////////////////////// // Compare matrix elements //////////////////////////////////////////////// int npoint = OpV1.geom.npoint; GRID_ASSERT(npoint == OpV2.geom.npoint); typedef MrhsV1::calcMatrix calcMatrix; std::vector > A1,A2; ReadMatrix(OpV1,npoint,A1); ReadMatrix(OpV2,npoint,A2); RealD num=0.0, den=0.0; for(int p=0;p > A3; ReadMatrix(OpV2s,npoint,A3); RealD nums=0.0; for(int p=0;p