From fe65fa498813fbe068e91ee6427842596c6070e0 Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Tue, 27 Aug 2024 11:13:18 -0400 Subject: [PATCH] MulMatrix --- .../iterative/BlockConjugateGradient.h | 123 ++++++++++++------ 1 file changed, 83 insertions(+), 40 deletions(-) diff --git a/Grid/algorithms/iterative/BlockConjugateGradient.h b/Grid/algorithms/iterative/BlockConjugateGradient.h index 75a8be06..d194bb06 100644 --- a/Grid/algorithms/iterative/BlockConjugateGradient.h +++ b/Grid/algorithms/iterative/BlockConjugateGradient.h @@ -31,6 +31,58 @@ directory NAMESPACE_BEGIN(Grid); +template +void InnerProductMatrix(Eigen::MatrixXcd &m , const std::vector &X, const std::vector &Y){ + typedef typename Field::scalar_type scomplex; + int Nblock = X.size(); + for(int b=0;b +void MaddMatrix(std::vector &AP, Eigen::MatrixXcd &m , const std::vector &X,const std::vector &Y,RealD scale=1.0){ + // Should make this cache friendly with site outermost, parallel_for + // Deal with case AP aliases with either Y or X + // + //Could pack "X" and "AP" into a Nblock x Volume dense array. + // AP(Nrhs x vol) = Y(Nrhs x vol) + scale * m(nrhs x nrhs) * X(nrhs*vol) + typedef typename Field::scalar_type scomplex; + int Nblock = AP.size(); + std::vector tmp(Nblock,X[0]); + for(int b=0;b +void MulMatrix(std::vector &AP, Eigen::MatrixXcd &m , const std::vector &X){ + // Should make this cache friendly with site outermost, parallel_for + typedef typename Field::scalar_type scomplex; + int Nblock = AP.size(); + for(int b=0;b +double normv(const std::vector &P){ + int Nblock = P.size(); + double nn = 0.0; + for(int b=0;b & R) { InnerProductMatrix(m_rr,R,R); - + /* + int rank=m_rr.rows(); + for(int r=0;r &Linop, const Field &B, Field &X) sliceNorm(ssq,B,Orthog); RealD sssum=0; for(int b=0;b &Linop, const Field &B, Field &X) Linop.HermOp(X, AD); tmp = B - AD; + sliceNorm(residuals,tmp,Orthog); + for(int b=0;b &Linop, const Field &B, Field &X) GridStopWatch SolverTimer; SolverTimer.Start(); + RealD max_resid=0; + int k; for (k = 1; k <= MaxIterations; k++) { @@ -280,7 +356,7 @@ void BlockCGrQsolve(LinearOperatorBase &Linop, const Field &B, Field &X) */ m_rr = m_C.adjoint() * m_C; - RealD max_resid=0; + max_resid=0; RealD rrsum=0; RealD rr; @@ -322,7 +398,9 @@ void BlockCGrQsolve(LinearOperatorBase &Linop, const Field &B, Field &X) } } - std::cout << GridLogMessage << "BlockConjugateGradient(rQ) did NOT converge" << std::endl; + + std::cout << GridLogMessage << "BlockConjugateGradient(rQ) did NOT converge "< &Linop, const Field &Src, Field & IterationsToComplete = k; } -void InnerProductMatrix(Eigen::MatrixXcd &m , const std::vector &X, const std::vector &Y){ - for(int b=0;b &AP, Eigen::MatrixXcd &m , const std::vector &X,const std::vector &Y,RealD scale=1.0){ - // Should make this cache friendly with site outermost, parallel_for - // Deal with case AP aliases with either Y or X - std::vector tmp(Nblock,X[0]); - for(int b=0;b &AP, Eigen::MatrixXcd &m , const std::vector &X){ - // Should make this cache friendly with site outermost, parallel_for - for(int b=0;b &P){ - double nn = 0.0; - for(int b=0;b &Linop, const std::vector &Linop, const std::vector