From 236868d2e9becea2418c64db1848d86577993cee Mon Sep 17 00:00:00 2001 From: Chulwoo Jung Date: Mon, 21 May 2018 18:51:59 -0400 Subject: [PATCH] Checking in vectorized Blocked CG --- .../iterative/BlockConjugateGradient.h | 196 +++++++++++++++++- tests/solver/Test_dwf_mrhs_cg.cc | 54 +---- tests/solver/Test_dwf_mrhs_cg_mpi.cc | 18 +- 3 files changed, 212 insertions(+), 56 deletions(-) diff --git a/lib/algorithms/iterative/BlockConjugateGradient.h b/lib/algorithms/iterative/BlockConjugateGradient.h index e0eeddcb..72bc1d85 100644 --- a/lib/algorithms/iterative/BlockConjugateGradient.h +++ b/lib/algorithms/iterative/BlockConjugateGradient.h @@ -33,7 +33,7 @@ directory namespace Grid { -enum BlockCGtype { BlockCG, BlockCGrQ, CGmultiRHS }; +enum BlockCGtype { BlockCG, BlockCGrQ, CGmultiRHS, BlockCGVec }; ////////////////////////////////////////////////////////////////////////// // Block conjugate gradient. Dimension zero should be the block direction @@ -127,6 +127,14 @@ void operator()(LinearOperatorBase &Linop, const Field &Src, Field &Psi) assert(0); } } +void operator()(LinearOperatorBase &Linop, const std::vector &Src, std::vector &Psi) +{ + if ( CGtype == BlockCGVec ) { + BlockCGVecsolve(Linop,Src,Psi); + } else { + assert(0); + } +} //////////////////////////////////////////////////////////////////////////// // BlockCGrQ implementation: @@ -600,6 +608,192 @@ void CGmultiRHSsolve(LinearOperatorBase &Linop, const Field &Src, Field & IterationsToComplete = k; } +void BlockCGVecsolve(LinearOperatorBase &Linop, const std::vector &Src, std::vector &Psi) +{ +// int Orthog = blockDim; // First dimension is block dim; this is an assumption +// Nblock = Src._grid->_fdimensions[Orthog]; + Nblock = Src.size(); + assert(Nblock == Psi.size()); + + std::cout< P(Nblock,Fake); +// P.resize(Nblock); + std::vector AP(Nblock,Fake); +//AP.resize(Nblock); + std::vector R(Nblock,Fake); +//R.resize(Nblock); + + Eigen::MatrixXcd m_pAp = Eigen::MatrixXcd::Identity(Nblock,Nblock); + Eigen::MatrixXcd m_pAp_inv= Eigen::MatrixXcd::Identity(Nblock,Nblock); + Eigen::MatrixXcd m_rr = Eigen::MatrixXcd::Zero(Nblock,Nblock); + Eigen::MatrixXcd m_rr_inv = Eigen::MatrixXcd::Zero(Nblock,Nblock); + + Eigen::MatrixXcd m_alpha = Eigen::MatrixXcd::Zero(Nblock,Nblock); + Eigen::MatrixXcd m_beta = Eigen::MatrixXcd::Zero(Nblock,Nblock); + + // Initial residual computation & set up + std::vector residuals(Nblock); + std::vector ssq(Nblock); + +// sliceNorm(ssq,Src,Orthog); + for(int b=0;b max_resid ) max_resid = rr; + } + + if ( max_resid < Tolerance*Tolerance ) { + + SolverTimer.Stop(); + + std::cout << GridLogMessage<<"BlockCG converged in "<Barrier(); - ScidacWriter _ScidacWriter(FGrid->IsBoss()); - _ScidacWriter.open(file); - std::cout << GridLogMessage << "****************************************************************** "<Barrier(); - std::cout << GridLogMessage << "****************************************************************** "<Barrier(); - std::cout << GridLogMessage << "****************************************************************** "<IsBoss()); - _ScidacWriter.open(filefn.str()); - _ScidacWriter.writeScidacFieldRecord(src[n],record); - _ScidacWriter.close(); - } - - FGrid->Barrier(); - - std::cout << GridLogMessage << "****************************************************************** "<Barrier(); } diff --git a/tests/solver/Test_dwf_mrhs_cg_mpi.cc b/tests/solver/Test_dwf_mrhs_cg_mpi.cc index aa36ebbc..41999b60 100644 --- a/tests/solver/Test_dwf_mrhs_cg_mpi.cc +++ b/tests/solver/Test_dwf_mrhs_cg_mpi.cc @@ -90,7 +90,7 @@ int main (int argc, char ** argv) /////////////////////////////////////////////// std::vector seeds({1,2,3,4}); - std::vector src(nrhs,FGrid); + std::vector src(nrhs,FGrid); std::vector src_chk(nrhs,FGrid); std::vector result(nrhs,FGrid); FermionField tmp(FGrid); @@ -197,7 +197,7 @@ int main (int argc, char ** argv) MdagMLinearOperator HermOp(Ddwf); MdagMLinearOperator HermOpCk(Dchk); - ConjugateGradient CG((1.0e-2),10000); + ConjugateGradient CG((1.0e-5),10000); s_res = zero; CG(HermOp,s_src,s_res); @@ -227,5 +227,19 @@ int main (int argc, char ** argv) std::cout << GridLogMessage<<" resid["< CG(1.0e-8,10000); + int blockDim = 0; +// BlockConjugateGradient BCGrQ(BlockCGrQ,blockDim,1.0e-8,10000); + BlockConjugateGradient BCG (BlockCG,blockDim,1.0e-8,10000); +// BlockConjugateGradient mCG (CGmultiRHS,blockDim,1.0e-8,10000); + BlockConjugateGradient BCGV (BlockCGVec,blockDim,1.0e-8,10000); +{ +// BCG(HermOpCk,src[0],result[0]); + BCGV(HermOpCk,src,result); +} + + Grid_finalize(); }