From 14a1406f54bc66774e0a7bb1db8306dbe6141cab Mon Sep 17 00:00:00 2001 From: Guido Cossu Date: Thu, 8 Dec 2016 06:14:20 +0000 Subject: [PATCH] More cleanup --- lib/algorithms/iterative/ConjugateGradient.h | 7 +- lib/lattice/Lattice_reduction.h | 5 +- tests/debug/Test_cayley_cg_reproducibility.cc | 209 ++++++++++++++++++ 3 files changed, 219 insertions(+), 2 deletions(-) create mode 100644 tests/debug/Test_cayley_cg_reproducibility.cc diff --git a/lib/algorithms/iterative/ConjugateGradient.h b/lib/algorithms/iterative/ConjugateGradient.h index 583178ff..3fe0a893 100644 --- a/lib/algorithms/iterative/ConjugateGradient.h +++ b/lib/algorithms/iterative/ConjugateGradient.h @@ -214,7 +214,12 @@ class ConjugateGradient : public OperatorFunction { ReprTest.do_check = true; ReprTest.reset_counter(); this->operator()(Linop, src, psi_start);// run the repro test - std::cout << GridLogMessage << "Test passed" << std::endl; + if (ReprTest.success) + std::cout << GridLogMessage << "Reproducibility test passed" << std::endl; + else{ + std::cout << GridLogMessage << "Reproducibility test failed" << std::endl; + exit(1); + } } // Clear state diff --git a/lib/lattice/Lattice_reduction.h b/lib/lattice/Lattice_reduction.h index 7f3a7c3c..befa470f 100644 --- a/lib/lattice/Lattice_reduction.h +++ b/lib/lattice/Lattice_reduction.h @@ -40,6 +40,7 @@ class ReproducibilityState { unsigned int n_call; bool do_check; bool enable_reprocheck; + bool success; sum_type th_states; void reset_counter() { n_call = 0; } @@ -47,6 +48,7 @@ class ReproducibilityState { th_states.clear(); do_check = false; enable_reprocheck = false; + success = true; n_call = 0; }; @@ -131,7 +133,8 @@ class ReproducibilityState { std::cout << GridLogMessage << "Current state" << std::endl; show_binaryrep(sumarray[thread]); std::cout << GridLogMessage << "Xor result" << std::endl; - show_binaryrep(xors, words); + show_binaryrep(xors, words); + repr.success = false; } } repr.n_call++; diff --git a/tests/debug/Test_cayley_cg_reproducibility.cc b/tests/debug/Test_cayley_cg_reproducibility.cc new file mode 100644 index 00000000..a0bb16f2 --- /dev/null +++ b/tests/debug/Test_cayley_cg_reproducibility.cc @@ -0,0 +1,209 @@ + /************************************************************************************* + + Grid physics library, www.github.com/paboyle/Grid + + Source file: ./tests/Test_cayley_cg.cc + + Copyright (C) 2015 + +Author: Peter Boyle +Author: paboyle + + 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 */ +#include + +using namespace std; +using namespace Grid; +using namespace Grid::QCD; + +template +struct scal { + d internal; +}; + + Gamma::GammaMatrix Gmu [] = { + Gamma::GammaX, + Gamma::GammaY, + Gamma::GammaZ, + Gamma::GammaT + }; + +template +void TestCGinversions(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5); +template +void TestCGschur(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5); + +template +void TestCGunprec(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5); + +template +void TestCGprec(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5); + +int main (int argc, char ** argv) +{ + Grid_init(&argc,&argv); + + int threads = GridThread::GetThreads(); + std::cout< seeds4({1,2,3,4}); + std::vector seeds5({5,6,7,8}); + GridParallelRNG RNG5(FGrid); RNG5.SeedFixedIntegers(seeds5); + GridParallelRNG RNG4(UGrid); RNG4.SeedFixedIntegers(seeds4); + + LatticeGaugeField Umu(UGrid); + SU3::HotConfiguration(RNG4,Umu); + std::vector U(4,UGrid); + + RealD mass=0.1; + RealD M5 =1.8; + std::cout<(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + RealD b=1.5;// Scale factor b+c=2, b-c=1 + RealD c=0.5; + std::cout<(Dmob,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + std::cout<(Dzolo,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + std::cout<(Dsham,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + std::cout<(Dshamz,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + std::cout<(Dov,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + std::cout<(Dovz,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,&RNG4,&RNG5); + + Grid_finalize(); +} +template +void TestCGinversions(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5) +{ + std::cout<(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5); + std::cout<(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5); + std::cout<(Ddwf,FGrid,FrbGrid,UGrid,UrbGrid,mass,M5,RNG4,RNG5); +} + +template +void TestCGunprec(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5) +{ + LatticeFermion src (FGrid); random(*RNG5,src); + LatticeFermion result(FGrid); result=zero; + + MdagMLinearOperator HermOp(Ddwf); + ConjugateGradient CG(1.0e-8,10000, false, true); + CG(HermOp,src,result); + +} +template +void TestCGprec(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5) +{ + LatticeFermion src (FGrid); random(*RNG5,src); + LatticeFermion src_o(FrbGrid); + LatticeFermion result_o(FrbGrid); + pickCheckerboard(Odd,src_o,src); + result_o=zero; + + SchurDiagMooeeOperator HermOpEO(Ddwf); + ConjugateGradient CG(1.0e-8,10000, false, true); + CG(HermOpEO,src_o,result_o); +} + + +template +void TestCGschur(What & Ddwf, + GridCartesian * FGrid, GridRedBlackCartesian * FrbGrid, + GridCartesian * UGrid, GridRedBlackCartesian * UrbGrid, + RealD mass, RealD M5, + GridParallelRNG *RNG4, + GridParallelRNG *RNG5) +{ + LatticeFermion src (FGrid); random(*RNG5,src); + LatticeFermion result(FGrid); result=zero; + + ConjugateGradient CG(1.0e-8,10000, false, true); + SchurRedBlackDiagMooeeSolve SchurSolver(CG); + SchurSolver(Ddwf,src,result); +}