From f0229025e2e513f86258e5a25724446b4e7d3e3c Mon Sep 17 00:00:00 2001 From: Peter Boyle Date: Sat, 13 Oct 2018 19:55:03 +0100 Subject: [PATCH] MADWF working across a range of actions --- Grid/algorithms/iterative/ConjugateGradient.h | 14 +- Grid/qcd/action/fermion/CayleyFermion5D.cc | 6 +- Grid/qcd/action/fermion/CayleyFermion5D.h | 11 +- Grid/qcd/action/fermion/Fermion.h | 1 + .../qcd/action/fermion/FourierAcceleratedPV.h | 2 +- Grid/qcd/action/fermion/MADWF.h | 179 ++++++++++++++++++ tests/debug/Test_cayley_cg.cc | 35 +++- 7 files changed, 237 insertions(+), 11 deletions(-) create mode 100644 Grid/qcd/action/fermion/MADWF.h diff --git a/Grid/algorithms/iterative/ConjugateGradient.h b/Grid/algorithms/iterative/ConjugateGradient.h index ff4ba8ac..8a6a4bae 100644 --- a/Grid/algorithms/iterative/ConjugateGradient.h +++ b/Grid/algorithms/iterative/ConjugateGradient.h @@ -150,13 +150,13 @@ class ConjugateGradient : public OperatorFunction { std::cout << GridLogMessage << "\tTrue residual " << true_residual<::SetCoefficientsInternal(RealD zolo_hi,std::vector _gamma; + RealD _zolo_hi; + RealD _b; + RealD _c; + // Cayley form Moebius (tanh and zolotarev) std::vector omega; std::vector bs; // S dependent coeffs diff --git a/Grid/qcd/action/fermion/Fermion.h b/Grid/qcd/action/fermion/Fermion.h index d0200ae7..77a4681f 100644 --- a/Grid/qcd/action/fermion/Fermion.h +++ b/Grid/qcd/action/fermion/Fermion.h @@ -91,6 +91,7 @@ Author: Peter Boyle #include #include #include +#include //////////////////////////////////////////////////////////////////////////////////////////////////// // More maintainable to maintain the following typedef list centrally, as more "impl" targets diff --git a/Grid/qcd/action/fermion/FourierAcceleratedPV.h b/Grid/qcd/action/fermion/FourierAcceleratedPV.h index d8441cf2..d6196eee 100644 --- a/Grid/qcd/action/fermion/FourierAcceleratedPV.h +++ b/Grid/qcd/action/fermion/FourierAcceleratedPV.h @@ -7,7 +7,7 @@ Copyright (C) 2015 -Author: Christoph Lehner +Author: Christoph Lehner (lifted with permission by Peter Boyle, brought back to Grid) Author: Peter Boyle This program is free software; you can redistribute it and/or modify diff --git a/Grid/qcd/action/fermion/MADWF.h b/Grid/qcd/action/fermion/MADWF.h new file mode 100644 index 00000000..f7ffea2f --- /dev/null +++ b/Grid/qcd/action/fermion/MADWF.h @@ -0,0 +1,179 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./lib/algorithms/iterative/MADWF.h + + Copyright (C) 2015 + +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 */ +#pragma once + +namespace Grid { +namespace QCD { + +template +class MADWF +{ + private: + typedef typename Matrixo::FermionField FermionFieldo; + typedef typename Matrixi::FermionField FermionFieldi; + + PVinverter & PauliVillarsSolvero;// For the outer field + SchurSolver & SchurSolveri; // For the inner approx field + Guesser & Guesseri; // To deflate the inner approx solves + + Matrixo & Mato; // Action object for outer + Matrixi & Mati; // Action object for inner + + RealD target_resid; + int maxiter; + public: + + MADWF(Matrixo &_Mato, + Matrixi &_Mati, + PVinverter &_PauliVillarsSolvero, + SchurSolver &_SchurSolveri, + Guesser & _Guesseri, + RealD resid, + int _maxiter) : + + Mato(_Mato),Mati(_Mati), + SchurSolveri(_SchurSolveri), + PauliVillarsSolvero(_PauliVillarsSolvero),Guesseri(_Guesseri) + { + target_resid=resid; + maxiter =_maxiter; + }; + + void operator() (const FermionFieldo &src4,FermionFieldo &sol5) + { + std::cout << GridLogMessage<< " ************************************************" << std::endl; + std::cout << GridLogMessage<< " MADWF-like algorithm " << std::endl; + std::cout << GridLogMessage<< " ************************************************" << std::endl; + + FermionFieldo c0(Mato.GaugeGrid()); // 4d + FermionFieldo y0(Mato.GaugeGrid()); // 4d + + FermionFieldo A(Mato.FermionGrid()); // Temporary outer + FermionFieldo B(Mato.FermionGrid()); // Temporary outer + FermionFieldo b(Mato.FermionGrid()); // 5d source + + FermionFieldo c(Mato.FermionGrid()); // PVinv source; reused so store + FermionFieldo defect(Mato.FermionGrid()); // 5d source + + FermionFieldi ci(Mati.FermionGrid()); + FermionFieldi yi(Mati.FermionGrid()); + FermionFieldi xi(Mati.FermionGrid()); + FermionFieldi srci(Mati.FermionGrid()); + FermionFieldi Ai(Mati.FermionGrid()); + + RealD m=Mati.Mass(); + + /////////////////////////////////////// + //Import source, include Dminus factors + /////////////////////////////////////// + Mato.ImportPhysicalFermionSource(src4,b); + std::cout << GridLogMessage << " src4 " < HermOp(Ddwf); double Resid = 1.0e-12; + double Residi = 1.0e-6; ConjugateGradient CG(Resid,10000); + ConjugateGradient CGi(Residi,10000); Ddwf.ImportPhysicalFermionSource(src4,src); Ddwf.Mdag(src,src_NE); @@ -271,7 +274,8 @@ void TestReconstruct5D(What & Ddwf, // RBprec PV inverse //////////////////////////// typedef LatticeFermion Field; - typedef SchurRedBlackDiagMooeeSolve SchurSolverType; + typedef SchurRedBlackDiagTwoSolve SchurSolverType; + typedef SchurRedBlackDiagTwoSolve SchurSolverTypei; typedef PauliVillarsSolverRBprec PVinverter; SchurSolverType SchurSolver(CG); PVinverter PVinverse(SchurSolver); @@ -286,6 +290,19 @@ void TestReconstruct5D(What & Ddwf, result_rec = result_rec - result; std::cout < Guess; + MADWF > + madwf(Ddwf,Ddwf,PVinverse,SchurSolveri,Guess,Resid,10); + + madwf(src4,result_madwf); + result_madwf = result_madwf - result; + std::cout < void TestReconstruct5DFA(What & Ddwf, @@ -303,10 +320,13 @@ void TestReconstruct5DFA(What & Ddwf, LatticeFermion src_NE(FGrid); LatticeFermion result(FGrid); LatticeFermion result_rec(FGrid); + LatticeFermion result_madwf(FGrid); MdagMLinearOperator HermOp(Ddwf); double Resid = 1.0e-12; + double Residi = 1.0e-5; ConjugateGradient CG(Resid,10000); + ConjugateGradient CGi(Residi,10000); Ddwf.ImportPhysicalFermionSource(src4,src); Ddwf.Mdag(src,src_NE); @@ -324,6 +344,7 @@ void TestReconstruct5DFA(What & Ddwf, // Fourier accel PV inverse //////////////////////////// typedef LatticeFermion Field; + typedef SchurRedBlackDiagTwoSolve SchurSolverTypei; typedef PauliVillarsSolverFourierAccel PVinverter; PVinverter PVinverse(Umu,CG); @@ -337,6 +358,18 @@ void TestReconstruct5DFA(What & Ddwf, result_rec = result_rec - result; std::cout < Guess; + MADWF > + madwf(Ddwf,Ddwf,PVinverse,SchurSolver,Guess,Resid,10); + + madwf(src4,result_madwf); + result_madwf = result_madwf - result; + std::cout <