diff --git a/Grid/algorithms/GeneralCoarsenedMatrix.h b/Grid/algorithms/GeneralCoarsenedMatrix.h index 21c75c8b..90074e09 100644 --- a/Grid/algorithms/GeneralCoarsenedMatrix.h +++ b/Grid/algorithms/GeneralCoarsenedMatrix.h @@ -191,7 +191,8 @@ public: template class GeneralCoarsenedMatrix : public SparseMatrixBase > > { public: - + + typedef GeneralCoarsenedMatrix GeneralCoarseOp; typedef iVector siteVector; typedef iMatrix siteMatrix; typedef Lattice > CoarseComplexField; @@ -222,27 +223,22 @@ public: GridCartesian * CoarseGrid(void) { return _CoarseGrid; }; // this is all the linalg routines need to know - void ProjectNearestNeighbour(RealD shift) + void ProjectNearestNeighbour(RealD shift, GeneralCoarseOp &CopyMe) { - int Nd = geom.grid->Nd(); - int point; - std::cout << "ProjectNearestNeighbour "<1) { - std::cout << "setting geom "<_permute); - ////////////////////////////// - auto SE = Stencil_v.GetEntry(point,ss); - int o = SE->_offset; - coalescedWrite(out_v[ss],out_v(ss) + A_v(ss)*in_v(o)); - }); -#else - prof_accelerator_for(sss, osites*nbasis, Nsimd, { + accelerator_for(sss, osites*nbasis, Nsimd, { typedef decltype(coalescedRead(in_v[0])) calcVector; @@ -352,10 +334,9 @@ public: } coalescedWrite(out_v[ss](b),res); }); -#endif + tmult+=usecond(); } - std::cout << "Called accelerator for loop " < > &linop, - Aggregation & Subspace) - { - RealD tproj=0.0; - RealD tpick=0.0; - RealD tmat=0.0; - RealD tpeek=0.0; - std::cout << GridLogMessage<< "CoarsenMatrix "<< std::endl; - GridBase *grid = FineGrid(); - - //////////////////////////////////////////////// - // Orthogonalise the subblocks over the basis - //////////////////////////////////////////////// - CoarseScalar InnerProd(CoarseGrid()); - blockOrthogonalise(InnerProd,Subspace.subspace); - - //////////////////////////////////////////////// - // Now compute the matrix elements of linop between this orthonormal - // set of vectors. - //////////////////////////////////////////////// - FineField bV(grid); - FineField MbV(grid); - FineField tmp(grid); - CoarseVector coarseInner(CoarseGrid()); - - // Very inefficient loop of order coarse volume. - // First pass hack - // Could replace with a coloring scheme our phase scheme - // as in BFM - for(int bidx=0;bidxgSites() ;bidx++){ - Coordinate bcoor; - CoarseGrid()->GlobalIndexToGlobalCoor(bidx,bcoor); - - for(int b=0;bGlobalDimensions()[mu]; - scoor[mu] = (bcoor[mu] - geom.shifts[p][mu] + L) % L; // Modulo arithmetic - } - // Flip to peekLocalSite - // Flip to pokeLocalSite - auto ip = peekSite(coarseInner,scoor); - auto Ab = peekSite(_A[p],scoor); - int pp = geom.Reverse(p); - auto Adagb = peekSite(_Adag[pp],bcoor); - for(int bb=0;bb NAMESPACE_BEGIN(Grid); template -class TwoLevelFlexiblePcg : public LinearFunction +class TwoLevelADEF2 : public LinearFunction { public: RealD Tolerance; @@ -64,14 +64,14 @@ class TwoLevelFlexiblePcg : public LinearFunction Aggregation &_Aggregates; // more most opertor functions - TwoLevelFlexiblePcg(RealD tol, - Integer maxit, - LinearOperatorBase &FineLinop, - LinearFunction &Smoother, - LinearFunction &CoarseSolver, - LinearFunction &CoarseSolverPrecise, - Aggregation &Aggregates - ) : + TwoLevelADEF2(RealD tol, + Integer maxit, + LinearOperatorBase &FineLinop, + LinearFunction &Smoother, + LinearFunction &CoarseSolver, + LinearFunction &CoarseSolverPrecise, + Aggregation &Aggregates + ) : Tolerance(tol), MaxIterations(maxit), _FineLinop(FineLinop), @@ -84,7 +84,7 @@ class TwoLevelFlexiblePcg : public LinearFunction grid = Aggregates.FineGrid; }; - void Inflexible(const Field &src,Field &psi) + virtual void operator() (const Field &src, Field &psi) { Field resid(grid); RealD f; @@ -192,10 +192,6 @@ class TwoLevelFlexiblePcg : public LinearFunction return ; } - virtual void operator() (const Field &in, Field &out) - { - this->Inflexible(in,out); - } public: @@ -285,5 +281,49 @@ class TwoLevelFlexiblePcg : public LinearFunction } }; +template +class TwoLevelADEF1ev : public TwoLevelADEF2 +{ + TwoLevelADEF1ev(RealD tol, + Integer maxit, + LinearOperatorBase &FineLinop, + LinearFunction &Smoother, + LinearFunction &CoarseSolver, + LinearFunction &CoarseSolverPrecise, + Aggregation &Aggregates ) : + TwoLevelADEF2(tol,maxit,FineLinop,Smoother,CoarseSolver,CoarseSolverPrecise,Aggregates) + {}; + + // Can just inherit existing Vstart + // Can just inherit existing Vout + // Can just inherit existing M2 + // Can just inherit existing M3 + // Override PcgM1 + virtual void PcgM1(Field & in, Field & out) + { + CoarseField PleftProj(this->coarsegrid); + CoarseField PleftMss_proj(this->coarsegrid); + Field tmp(this->grid); + Field Pin(this->grid); + + //MP + Q = M(1-AQ) + Q = M + // // If we are eigenvector deflating in coarse space + // // Q = Sum_i |phi_i> 1/lambda_i _Aggregates.ProjectToSubspace(PleftProj,in); + this->_Aggregates.PromoteFromSubspace(PleftProj,tmp);// tmp = Qin + + Pin = in - tmp; + this->_Smoother(Pin,out); + + this->_CoarseSolver(PleftProj,PleftMss_proj); + this->_Aggregates.PromoteFromSubspace(PleftMss_proj,tmp);// tmp = Qin + + out = out + tmp; + } +}; + NAMESPACE_END(Grid); + #endif diff --git a/tests/debug/Test_general_coarse_hdcg.cc b/tests/debug/Test_general_coarse_hdcg.cc index 7372785f..03b93fca 100644 --- a/tests/debug/Test_general_coarse_hdcg.cc +++ b/tests/debug/Test_general_coarse_hdcg.cc @@ -149,6 +149,7 @@ int main (int argc, char ** argv) typedef LittleDiracOperator::CoarseVector CoarseVector; NextToNextToNextToNearestStencilGeometry5D geom(Coarse5d); + NearestStencilGeometry5D geom_nn(Coarse5d); // Warning: This routine calls PVdagM.Op, not PVdagM.HermOp typedef Aggregation Subspace; @@ -178,8 +179,8 @@ int main (int argc, char ** argv) LittleDiracOp.CoarsenOperatorColoured(FineHermOp,Aggregates); // Try projecting to one hop only - LittleDiracOperator LittleDiracOpProj(LittleDiracOp); - LittleDiracOpProj.ProjectNearestNeighbour(0.5); + LittleDiracOperator LittleDiracOpProj(geom_nn,FrbGrid,Coarse5d); + LittleDiracOpProj.ProjectNearestNeighbour(0.5,LittleDiracOp); typedef HermitianLinearOperator HermMatrix; HermMatrix CoarseOp (LittleDiracOp); @@ -260,7 +261,7 @@ int main (int argc, char ** argv) ////////////////////////////////////////// // Build a HDCG solver ////////////////////////////////////////// - TwoLevelFlexiblePcg + TwoLevelADEF2 HDCG(1.0e-8, 3000, FineHermOp, Smoother, @@ -268,11 +269,8 @@ int main (int argc, char ** argv) HPDSolve, Aggregates); - // result=Zero(); - // HDCG(src,result); - result=Zero(); - HDCG.Inflexible(src,result); + HDCG(src,result); } }