1
0
mirror of https://github.com/paboyle/Grid.git synced 2025-04-18 09:45:55 +01:00

Apply clang-format to Wilson MG

I can provide the configuration file I used if people want that.
This commit is contained in:
Daniel Richtmann 2018-01-18 12:38:28 +01:00
parent fa4eeb28c4
commit 9732519c41
No known key found for this signature in database
GPG Key ID: B33C490AF0772057

View File

@ -25,6 +25,7 @@ Author: Daniel Richtmann <daniel.richtmann@ur.de>
See the full license in the file "LICENSE" in the top level distribution directory See the full license in the file "LICENSE" in the top level distribution directory
*************************************************************************************/ *************************************************************************************/
/* END LEGAL */ /* END LEGAL */
#include <Grid/Grid.h> #include <Grid/Grid.h>
#include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h> #include <Grid/algorithms/iterative/PrecGeneralisedConjugateResidual.h>
//#include <algorithms/iterative/PrecConjugateResidual.h> //#include <algorithms/iterative/PrecConjugateResidual.h>
@ -33,11 +34,9 @@ using namespace std;
using namespace Grid; using namespace Grid;
using namespace Grid::QCD; using namespace Grid::QCD;
template<class Field, int nbasis> template<class Field, int nbasis> class TestVectorAnalyzer {
class TestVectorAnalyzer {
public: public:
void operator()(LinearOperatorBase<Field> &Linop, std::vector<Field> const & vectors, int nn=nbasis) void operator()(LinearOperatorBase<Field> &Linop, std::vector<Field> const &vectors, int nn = nbasis) {
{
// this function corresponds to testvector_analysis_PRECISION from the // this function corresponds to testvector_analysis_PRECISION from the
// DD-αAMG codebase // DD-αAMG codebase
@ -66,16 +65,16 @@ public:
positiveOnes++; positiveOnes++;
std::cout << GridLogMessage << std::scientific << std::setprecision(2) << std::setw(2) << std::showpos << "vector " << i << ": " std::cout << GridLogMessage << std::scientific << std::setprecision(2) << std::setw(2) << std::showpos << "vector " << i << ": "
<< "singular value: " << lambda << "singular value: " << lambda << ", singular vector precision: " << mu << ", norm: " << nrm << std::endl;
<< ", singular vector precision: " << mu << ", norm: " << nrm << std::endl;
} }
std::cout << GridLogMessage << std::scientific << std::setprecision(2) << std::setw(2) << std::showpos << positiveOnes << " out of " << nn << " vectors were positive" << std::endl; std::cout << GridLogMessage << std::scientific << std::setprecision(2) << std::setw(2) << std::showpos << positiveOnes << " out of "
<< nn << " vectors were positive" << std::endl;
} }
}; };
class myclass : Serializable { class myclass : Serializable {
public: public:
// clang-format off
GRID_SERIALIZABLE_CLASS_MEMBERS(myclass, GRID_SERIALIZABLE_CLASS_MEMBERS(myclass,
int, domaindecompose, int, domaindecompose,
int, domainsize, int, domainsize,
@ -86,9 +85,8 @@ public:
double, lo, double, lo,
double, hi, double, hi,
int, steps); int, steps);
// clang-format on
myclass(){}; myclass(){};
}; };
myclass params; myclass params;
@ -96,9 +94,7 @@ RealD InverseApproximation(RealD x){
return 1.0 / x; return 1.0 / x;
} }
template <int nbasis> template<int nbasis> struct CoarseGrids {
struct CoarseGrids
{
public: public:
// typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace; // typedef Aggregation<vSpinColourVector,vTComplex,nbasis> Subspace;
// typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis> // typedef CoarsenedMatrix<vSpinColourVector,vTComplex,nbasis>
@ -110,8 +106,8 @@ public:
std::vector<GridCartesian *> Grids; std::vector<GridCartesian *> Grids;
std::vector<GridParallelRNG> PRNGs; std::vector<GridParallelRNG> PRNGs;
CoarseGrids(std::vector<std::vector<int>> const &blockSizes,int coarsegrids = 1) CoarseGrids(std::vector<std::vector<int>> const &blockSizes, int coarsegrids = 1) {
{
assert(blockSizes.size() == coarsegrids); assert(blockSizes.size() == coarsegrids);
std::cout << GridLogMessage << "Constructing " << coarsegrids << " CoarseGrids" << std::endl; std::cout << GridLogMessage << "Constructing " << coarsegrids << " CoarseGrids" << std::endl;
@ -122,7 +118,8 @@ public:
for(int d = 0; d < LattSizes[cl].size(); ++d) { for(int d = 0; d < LattSizes[cl].size(); ++d) {
LattSizes[cl][d] = LattSizes[cl][d] / blockSizes[cl][d]; LattSizes[cl][d] = LattSizes[cl][d] / blockSizes[cl][d];
Seeds[cl][d] = (cl + 1) * LattSizes[cl].size() + d + 1; // unimportant, just to get. e.g., {5, // 6, 7, 8} for first coarse level and // so on Seeds[cl][d] = (cl + 1) * LattSizes[cl].size() + d + 1;
// calculation unimportant, just to get. e.g., {5, 6, 7, 8} for first coarse level and so on
} }
Grids.push_back(SpaceTimeGrid::makeFourDimGrid(LattSizes[cl], GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultMpi())); Grids.push_back(SpaceTimeGrid::makeFourDimGrid(LattSizes[cl], GridDefaultSimd(Nd, vComplex::Nsimd()), GridDefaultMpi()));
@ -138,10 +135,8 @@ public:
// template < class Fobj, class CComplex, int coarseSpins, int nbasis, class Matrix > // template < class Fobj, class CComplex, int coarseSpins, int nbasis, class Matrix >
// class MultiGridPreconditioner : public LinearFunction< Lattice< Fobj > > { // class MultiGridPreconditioner : public LinearFunction< Lattice< Fobj > > {
template<class Fobj,class CComplex,int nbasis, class Matrix> template<class Fobj, class CComplex, int nbasis, class Matrix> class MultiGridPreconditioner : public LinearFunction<Lattice<Fobj>> {
class MultiGridPreconditioner : public LinearFunction< Lattice<Fobj> > {
public: public:
typedef Aggregation<Fobj, CComplex, nbasis> Aggregates; typedef Aggregation<Fobj, CComplex, nbasis> Aggregates;
typedef CoarsenedMatrix<Fobj, CComplex, nbasis> CoarseOperator; typedef CoarsenedMatrix<Fobj, CComplex, nbasis> CoarseOperator;
@ -160,17 +155,18 @@ public:
FineOperator & _SmootherOperator; FineOperator & _SmootherOperator;
// Constructor // Constructor
MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse, MultiGridPreconditioner(Aggregates & Agg,
FineOperator &Fine,Matrix &FineMatrix, CoarseOperator &Coarse,
FineOperator &Smooth,Matrix &SmootherMatrix) FineOperator & Fine,
: _Aggregates(Agg), Matrix & FineMatrix,
_CoarseOperator(Coarse), FineOperator & Smooth,
_FineOperator(Fine), Matrix & SmootherMatrix)
_FineMatrix(FineMatrix), : _Aggregates(Agg)
_SmootherOperator(Smooth), , _CoarseOperator(Coarse)
_SmootherMatrix(SmootherMatrix) , _FineOperator(Fine)
{ , _FineMatrix(FineMatrix)
} , _SmootherOperator(Smooth)
, _SmootherMatrix(SmootherMatrix) {}
void PowerMethod(const FineField &in) { void PowerMethod(const FineField &in) {
@ -255,7 +251,6 @@ public:
_Aggregates.ProjectToSubspace(Csrc, res); _Aggregates.ProjectToSubspace(Csrc, res);
std::cout << GridLogMessage << "coarse space proj of residual " << norm2(Csrc) << std::endl; std::cout << GridLogMessage << "coarse space proj of residual " << norm2(Csrc) << std::endl;
out = out + Min; // additive coarse space correction out = out + Min; // additive coarse space correction
// out = Min; // no additive coarse space correction // out = Min; // no additive coarse space correction
@ -265,7 +260,6 @@ public:
std::cout << GridLogMessage << " Preconditioner in " << norm2(in) << std::endl; std::cout << GridLogMessage << " Preconditioner in " << norm2(in) << std::endl;
std::cout << GridLogMessage << " Preconditioner out " << norm2(out) << std::endl; std::cout << GridLogMessage << " Preconditioner out " << norm2(out) << std::endl;
std::cout << GridLogMessage << "preconditioner thinks residual is " << std::sqrt(norm2(tmp) / norm2(in)) << std::endl; std::cout << GridLogMessage << "preconditioner thinks residual is " << std::sqrt(norm2(tmp) / norm2(in)) << std::endl;
} }
#endif #endif
// ADEF1: [MP+Q ] in = M [1 - A Q] in + Q in // ADEF1: [MP+Q ] in = M [1 - A Q] in + Q in
@ -274,7 +268,8 @@ public:
CoarseVector Csrc(_CoarseOperator.Grid()); CoarseVector Csrc(_CoarseOperator.Grid());
CoarseVector Ctmp(_CoarseOperator.Grid()); CoarseVector Ctmp(_CoarseOperator.Grid());
CoarseVector Csol(_CoarseOperator.Grid()); Csol=zero; CoarseVector Csol(_CoarseOperator.Grid());
Csol = zero;
ConjugateGradient<CoarseVector> CG(1.0e-10, 100000); ConjugateGradient<CoarseVector> CG(1.0e-10, 100000);
ConjugateGradient<FineField> fCG(3.0e-2, 1000); ConjugateGradient<FineField> fCG(3.0e-2, 1000);
@ -310,7 +305,6 @@ public:
tmp = tmp - in; // tmp is new residual tmp = tmp - in; // tmp is new residual
std::cout << GridLogMessage << "preconditioner thinks residual is " << std::sqrt(norm2(tmp) / norm2(in)) << std::endl; std::cout << GridLogMessage << "preconditioner thinks residual is " << std::sqrt(norm2(tmp) / norm2(in)) << std::endl;
} }
#endif #endif
@ -320,7 +314,8 @@ public:
Lattice<iScalar<vInteger>> subset(src._grid); Lattice<iScalar<vInteger>> subset(src._grid);
FineField r(src._grid); FineField r(src._grid);
FineField zz(src._grid); zz=zero; FineField zz(src._grid);
zz = zero;
FineField vec1(src._grid); FineField vec1(src._grid);
FineField vec2(src._grid); FineField vec2(src._grid);
@ -369,15 +364,14 @@ public:
r = src - vec1; r = src - vec1;
resid = norm2(r) / norm2(src); resid = norm2(r) / norm2(src);
std::cout << "SAP " << i << " resid " << resid << std::endl; std::cout << "SAP " << i << " resid " << resid << std::endl;
} }
}; };
void SmootherTest(const FineField &in) { void SmootherTest(const FineField &in) {
FineField vec1(in._grid); FineField vec1(in._grid);
FineField vec2(in._grid); FineField vec2(in._grid);
RealD lo[3] = {0.5, 1.0, 2.0}; RealD lo[3] = {0.5, 1.0, 2.0};
// MdagMLinearOperator<Matrix,FineField> fMdagMOp(_FineMatrix); // MdagMLinearOperator<Matrix,FineField> fMdagMOp(_FineMatrix);
@ -399,7 +393,6 @@ public:
vec1 = in - vec1; // tmp = in - A Min vec1 = in - vec1; // tmp = in - A Min
r = norm2(vec1); r = norm2(vec1);
std::cout << GridLogMessage << "Smoother resid " << std::sqrt(r / Ni) << std::endl; std::cout << GridLogMessage << "Smoother resid " << std::sqrt(r / Ni) << std::endl;
} }
} }
} }
@ -408,7 +401,8 @@ public:
CoarseVector Csrc(_CoarseOperator.Grid()); CoarseVector Csrc(_CoarseOperator.Grid());
CoarseVector Ctmp(_CoarseOperator.Grid()); CoarseVector Ctmp(_CoarseOperator.Grid());
CoarseVector Csol(_CoarseOperator.Grid()); Csol=zero; CoarseVector Csol(_CoarseOperator.Grid());
Csol = zero;
ConjugateGradient<CoarseVector> CG(3.0e-3, 100000); ConjugateGradient<CoarseVector> CG(3.0e-3, 100000);
// ConjugateGradient<FineField> fCG(3.0e-2,1000); // ConjugateGradient<FineField> fCG(3.0e-2,1000);
@ -481,14 +475,14 @@ public:
vec1 = in - vec1; // tmp = in - A Min vec1 = in - vec1; // tmp = in - A Min
r = norm2(vec1); r = norm2(vec1);
std::cout << GridLogMessage << "Smoother resid " << std::sqrt(r / Ni) << std::endl; std::cout << GridLogMessage << "Smoother resid " << std::sqrt(r / Ni) << std::endl;
} }
void operatorSAP(const FineField &in, FineField &out) { void operatorSAP(const FineField &in, FineField &out) {
CoarseVector Csrc(_CoarseOperator.Grid()); CoarseVector Csrc(_CoarseOperator.Grid());
CoarseVector Ctmp(_CoarseOperator.Grid()); CoarseVector Ctmp(_CoarseOperator.Grid());
CoarseVector Csol(_CoarseOperator.Grid()); Csol=zero; CoarseVector Csol(_CoarseOperator.Grid());
Csol = zero;
ConjugateGradient<CoarseVector> CG(1.0e-3, 100000); ConjugateGradient<CoarseVector> CG(1.0e-3, 100000);
@ -502,7 +496,6 @@ public:
_Aggregates.PromoteFromSubspace(Csrc, out); _Aggregates.PromoteFromSubspace(Csrc, out);
std::cout << GridLogMessage << "Completeness: " << std::sqrt(norm2(out) / norm2(in)) << std::endl; std::cout << GridLogMessage << "Completeness: " << std::sqrt(norm2(out) / norm2(in)) << std::endl;
// To make a working smoother for indefinite operator // To make a working smoother for indefinite operator
// must multiply by "Mdag" (ouch loses all low mode content) // must multiply by "Mdag" (ouch loses all low mode content)
// and apply to poly approx of (mdagm)^-1. // and apply to poly approx of (mdagm)^-1.
@ -536,7 +529,6 @@ public:
SAP(vec1, vec2); SAP(vec1, vec2);
out = out + vec2; out = out + vec2;
// Update with residual for out // Update with residual for out
_FineOperator.Op(out, vec1); // this is the G5 herm bit _FineOperator.Op(out, vec1); // this is the G5 herm bit
vec1 = in - vec1; // tmp = in - A Min vec1 = in - vec1; // tmp = in - A Min
@ -544,13 +536,10 @@ public:
r = norm2(vec1); r = norm2(vec1);
Ni = norm2(in); Ni = norm2(in);
std::cout << GridLogMessage << "SAP resid(post) " << std::sqrt(r / Ni) << " " << r << " " << Ni << std::endl; std::cout << GridLogMessage << "SAP resid(post) " << std::sqrt(r / Ni) << " " << r << " " << Ni << std::endl;
} }
}; };
struct MGParams struct MGParams {
{
std::vector<std::vector<int>> blockSizes; std::vector<std::vector<int>> blockSizes;
const int nbasis; const int nbasis;
@ -558,13 +547,11 @@ struct MGParams
: blockSizes({{1, 1, 1, 2}}) : blockSizes({{1, 1, 1, 2}})
// : blockSizes({{1,1,1,2}, {1,1,1,2}}) // : blockSizes({{1,1,1,2}, {1,1,1,2}})
// : blockSizes({{1,1,1,2}, {1,1,1,2}, {1,1,1,2}}) // : blockSizes({{1,1,1,2}, {1,1,1,2}, {1,1,1,2}})
, nbasis( 20 ) , nbasis(20) {}
{
}
}; };
int main (int argc, char ** argv) int main(int argc, char **argv) {
{
Grid_init(&argc, &argv); Grid_init(&argc, &argv);
params.domainsize = 1; params.domainsize = 1;
@ -599,6 +586,7 @@ int main (int argc, char ** argv)
Gamma g5(Gamma::Algebra::Gamma5); Gamma g5(Gamma::Algebra::Gamma5);
// clang-format off
LatticeFermion src(FGrid); gaussian(fPRNG, src); // src=src + g5 * src; LatticeFermion src(FGrid); gaussian(fPRNG, src); // src=src + g5 * src;
LatticeFermion result(FGrid); result = zero; LatticeFermion result(FGrid); result = zero;
LatticeFermion ref(FGrid); ref = zero; LatticeFermion ref(FGrid); ref = zero;
@ -608,6 +596,7 @@ int main (int argc, char ** argv)
LatticeGaugeField UmuDD(FGrid); LatticeGaugeField UmuDD(FGrid);
LatticeColourMatrix U(FGrid); LatticeColourMatrix U(FGrid);
LatticeColourMatrix zz(FGrid); LatticeColourMatrix zz(FGrid);
// clang-format on
if(params.domaindecompose) { if(params.domaindecompose) {
Lattice<iScalar<vInteger>> coor(FGrid); Lattice<iScalar<vInteger>> coor(FGrid);
@ -629,7 +618,7 @@ int main (int argc, char ** argv)
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
std::vector<std::vector<int>> blockSizes({{1, 1, 1, 2}}); // corresponds to two level algorithm std::vector<std::vector<int>> blockSizes({{1, 1, 1, 2}}); // corresponds to two level algorithm
// std::vector< std::vector<int> > blockSizes({ {1,1,1,2}, // // corresponds to three level algorithm // std::vector<std::vector<int>> blockSizes({{1, 1, 1, 2}, // corresponds to three level algorithm
// {1, 1, 1, 2}}); // {1, 1, 1, 2}});
const int nbasis = 20; // we fix the number of test vector to the same const int nbasis = 20; // we fix the number of test vector to the same
@ -688,6 +677,7 @@ int main (int argc, char ** argv)
// CoarseOperator::CoarseG5PMatrix CoarseG5PMatrix; // CoarseOperator::CoarseG5PMatrix CoarseG5PMatrix;
#if 1 #if 1
// clang-format off
std::cout << std::endl; std::cout << std::endl;
std::cout << "type_name<decltype(vTComplex{})>() = " << type_name<decltype(vTComplex{})>() << std::endl; std::cout << "type_name<decltype(vTComplex{})>() = " << type_name<decltype(vTComplex{})>() << std::endl;
std::cout << "type_name<GridTypeMapper<vTComplex>::scalar_type>() = " << type_name<GridTypeMapper<vTComplex>::scalar_type>() << std::endl; std::cout << "type_name<GridTypeMapper<vTComplex>::scalar_type>() = " << type_name<GridTypeMapper<vTComplex>::scalar_type>() << std::endl;
@ -711,6 +701,7 @@ int main (int argc, char ** argv)
std::cout << "type_name<GridTypeMapper<TComplex>::Realified>() = " << type_name<GridTypeMapper<TComplex>::Realified>() << std::endl; std::cout << "type_name<GridTypeMapper<TComplex>::Realified>() = " << type_name<GridTypeMapper<TComplex>::Realified>() << std::endl;
std::cout << "type_name<GridTypeMapper<TComplex>::DoublePrecision>() = " << type_name<GridTypeMapper<TComplex>::DoublePrecision>() << std::endl; std::cout << "type_name<GridTypeMapper<TComplex>::DoublePrecision>() = " << type_name<GridTypeMapper<TComplex>::DoublePrecision>() << std::endl;
std::cout << std::endl; std::cout << std::endl;
// clang-format on
#endif #endif
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
@ -735,8 +726,10 @@ int main (int argc, char ** argv)
testVectorAnalyzer(HermOp, Aggregates.subspace, nb); testVectorAnalyzer(HermOp, Aggregates.subspace, nb);
for(int n = 0; n < nb; n++) { for(int n = 0; n < nb; n++) {
Aggregates.subspace[n+nb] = g5 * Aggregates.subspace[n]; // multiply with g5 normally instead of G5R5 since this specific to DWF // multiply with g5 normally instead of G5R5 since this specific to DWF
std::cout<<GridLogMessage<<n<<" subspace "<<norm2(Aggregates.subspace[n+nb])<<" "<<norm2(Aggregates.subspace[n]) <<std::endl; Aggregates.subspace[n + nb] = g5 * Aggregates.subspace[n];
std::cout << GridLogMessage << n << " subspace " << norm2(Aggregates.subspace[n + nb]) << " " << norm2(Aggregates.subspace[n])
<< std::endl;
} }
for(int n = 0; n < nbasis; n++) { for(int n = 0; n < nbasis; n++) {
std::cout << GridLogMessage << "vec[" << n << "] = " << norm2(Aggregates.subspace[n]) << std::endl; std::cout << GridLogMessage << "vec[" << n << "] = " << norm2(Aggregates.subspace[n]) << std::endl;
@ -752,7 +745,8 @@ int main (int argc, char ** argv)
std::cout << GridLogMessage << "Building coarse representation of Dirac operator" << std::endl; std::cout << GridLogMessage << "Building coarse representation of Dirac operator" << std::endl;
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
Gamma5HermitianLinearOperator<WilsonFermionR,LatticeFermion> HermIndefOp(Dw); // this corresponds to working with H = g5 * D // using Gamma5HermitianLinearOperator corresponds to working with H = g5 * D
Gamma5HermitianLinearOperator<WilsonFermionR, LatticeFermion> HermIndefOp(Dw);
Gamma5HermitianLinearOperator<WilsonFermionR, LatticeFermion> HermIndefOpDD(DwDD); Gamma5HermitianLinearOperator<WilsonFermionR, LatticeFermion> HermIndefOpDD(DwDD);
CoarsenedMatrix<vSpinColourVector, vTComplex, nbasis> CoarseOp(*cGrids.Grids[0]); CoarsenedMatrix<vSpinColourVector, vTComplex, nbasis> CoarseOp(*cGrids.Grids[0]);
CoarseOp.CoarsenOperator(FGrid, HermIndefOp, Aggregates); // uses only linop.OpDiag & linop.OpDir CoarseOp.CoarsenOperator(FGrid, HermIndefOp, Aggregates); // uses only linop.OpDiag & linop.OpDir
@ -815,13 +809,11 @@ int main (int argc, char ** argv)
std::cout << GridLogMessage << "Building deflation preconditioner " << std::endl; std::cout << GridLogMessage << "Building deflation preconditioner " << std::endl;
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
MultiGridPreconditioner <vSpinColourVector,vTComplex,nbasis,WilsonFermionR> Precon (Aggregates, CoarseOp, MultiGridPreconditioner<vSpinColourVector, vTComplex, nbasis, WilsonFermionR> Precon(
HermIndefOp,Dw, Aggregates, CoarseOp, HermIndefOp, Dw, HermIndefOp, Dw);
HermIndefOp,Dw);
MultiGridPreconditioner <vSpinColourVector,vTComplex,nbasis,WilsonFermionR> PreconDD(Aggregates, CoarseOp, MultiGridPreconditioner<vSpinColourVector, vTComplex, nbasis, WilsonFermionR> PreconDD(
HermIndefOp,Dw, Aggregates, CoarseOp, HermIndefOp, Dw, HermIndefOpDD, DwDD);
HermIndefOpDD,DwDD);
// MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse, // MultiGridPreconditioner(Aggregates &Agg, CoarseOperator &Coarse,
// FineOperator &Fine,Matrix &FineMatrix, // FineOperator &Fine,Matrix &FineMatrix,
// FineOperator &Smooth,Matrix &SmootherMatrix) // FineOperator &Smooth,Matrix &SmootherMatrix)