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

WilsonMG: Add functionality to report timings to MG preconditioner

This commit is contained in:
Daniel Richtmann 2018-04-03 17:26:49 +02:00
parent 57a49ed22f
commit f69008edf1
No known key found for this signature in database
GPG Key ID: B33C490AF0772057

View File

@ -157,6 +157,7 @@ public:
virtual void setup() = 0; virtual void setup() = 0;
virtual void operator()(Field const &in, Field &out) = 0; virtual void operator()(Field const &in, Field &out) = 0;
virtual void runChecks() = 0; virtual void runChecks() = 0;
virtual void reportTimings() = 0;
}; };
template<class Fobj, class CoarseScalar, int nCoarseSpins, int nBasis, int nCoarserLevels, class Matrix> template<class Fobj, class CoarseScalar, int nCoarseSpins, int nBasis, int nCoarserLevels, class Matrix>
@ -180,16 +181,27 @@ public:
// Member Data // Member Data
///////////////////////////////////////////// /////////////////////////////////////////////
int _CurrentLevel; int _CurrentLevel;
int _NextCoarserLevel; int _NextCoarserLevel;
MultiGridParams & _MultiGridParams;
LevelInfo & _LevelInfo; MultiGridParams &_MultiGridParams;
FineMatrix & _FineMatrix; LevelInfo & _LevelInfo;
FineMatrix & _SmootherMatrix;
Aggregates _Aggregates; FineMatrix & _FineMatrix;
CoarseMatrix _CoarseMatrix; FineMatrix & _SmootherMatrix;
Aggregates _Aggregates;
CoarseMatrix _CoarseMatrix;
std::unique_ptr<NextPreconditionerLevel> _NextPreconditionerLevel; std::unique_ptr<NextPreconditionerLevel> _NextPreconditionerLevel;
GridStopWatch _SetupTotalTimer;
GridStopWatch _SetupNextLevelTimer;
GridStopWatch _SolveTotalTimer;
GridStopWatch _SolveRestrictionTimer;
GridStopWatch _SolveProlongationTimer;
GridStopWatch _SolveSmootherTimer;
GridStopWatch _SolveNextLevelTimer;
///////////////////////////////////////////// /////////////////////////////////////////////
// Member Functions // Member Functions
///////////////////////////////////////////// /////////////////////////////////////////////
@ -203,12 +215,17 @@ public:
, _SmootherMatrix(SmootherMat) , _SmootherMatrix(SmootherMat)
, _Aggregates(_LevelInfo.Grids[_NextCoarserLevel], _LevelInfo.Grids[_CurrentLevel], 0) , _Aggregates(_LevelInfo.Grids[_NextCoarserLevel], _LevelInfo.Grids[_CurrentLevel], 0)
, _CoarseMatrix(*_LevelInfo.Grids[_NextCoarserLevel]) { , _CoarseMatrix(*_LevelInfo.Grids[_NextCoarserLevel]) {
_NextPreconditionerLevel _NextPreconditionerLevel
= std::unique_ptr<NextPreconditionerLevel>(new NextPreconditionerLevel(_MultiGridParams, _LevelInfo, _CoarseMatrix, _CoarseMatrix)); = std::unique_ptr<NextPreconditionerLevel>(new NextPreconditionerLevel(_MultiGridParams, _LevelInfo, _CoarseMatrix, _CoarseMatrix));
resetTimers();
} }
void setup() { void setup() {
_SetupTotalTimer.Start();
Gamma g5(Gamma::Algebra::Gamma5); Gamma g5(Gamma::Algebra::Gamma5);
MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix); MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix);
@ -228,7 +245,11 @@ public:
_CoarseMatrix.CoarsenOperator(_LevelInfo.Grids[_CurrentLevel], fineMdagMOp, _Aggregates); _CoarseMatrix.CoarsenOperator(_LevelInfo.Grids[_CurrentLevel], fineMdagMOp, _Aggregates);
_SetupNextLevelTimer.Start();
_NextPreconditionerLevel->setup(); _NextPreconditionerLevel->setup();
_SetupNextLevelTimer.Stop();
_SetupTotalTimer.Stop();
} }
virtual void operator()(Lattice<Fobj> const &in, Lattice<Fobj> &out) { virtual void operator()(Lattice<Fobj> const &in, Lattice<Fobj> &out) {
@ -245,6 +266,8 @@ public:
void vCycle(Lattice<Fobj> const &in, Lattice<Fobj> &out) { void vCycle(Lattice<Fobj> const &in, Lattice<Fobj> &out) {
_SolveTotalTimer.Start();
RealD inputNorm = norm2(in); RealD inputNorm = norm2(in);
CoarseVector coarseSrc(_LevelInfo.Grids[_NextCoarserLevel]); CoarseVector coarseSrc(_LevelInfo.Grids[_NextCoarserLevel]);
@ -265,16 +288,26 @@ public:
MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix); MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix);
MdagMLinearOperator<FineMatrix, FineVector> fineSmootherMdagMOp(_SmootherMatrix); MdagMLinearOperator<FineMatrix, FineVector> fineSmootherMdagMOp(_SmootherMatrix);
_SolveRestrictionTimer.Start();
_Aggregates.ProjectToSubspace(coarseSrc, in); _Aggregates.ProjectToSubspace(coarseSrc, in);
_SolveRestrictionTimer.Stop();
_SolveNextLevelTimer.Start();
(*_NextPreconditionerLevel)(coarseSrc, coarseSol); (*_NextPreconditionerLevel)(coarseSrc, coarseSol);
_SolveNextLevelTimer.Stop();
_SolveProlongationTimer.Start();
_Aggregates.PromoteFromSubspace(coarseSol, out); _Aggregates.PromoteFromSubspace(coarseSol, out);
_SolveProlongationTimer.Stop();
fineMdagMOp.Op(out, fineTmp); fineMdagMOp.Op(out, fineTmp);
fineTmp = in - fineTmp; fineTmp = in - fineTmp;
auto r = norm2(fineTmp); auto r = norm2(fineTmp);
auto residualAfterCoarseGridCorrection = std::sqrt(r / inputNorm); auto residualAfterCoarseGridCorrection = std::sqrt(r / inputNorm);
_SolveSmootherTimer.Start();
fineFGMRES(fineSmootherMdagMOp, in, out); fineFGMRES(fineSmootherMdagMOp, in, out);
_SolveSmootherTimer.Stop();
fineMdagMOp.Op(out, fineTmp); fineMdagMOp.Op(out, fineTmp);
fineTmp = in - fineTmp; fineTmp = in - fineTmp;
@ -284,10 +317,14 @@ public:
std::cout << GridLogMG << " Level " << _CurrentLevel << ": V-cycle: Input norm = " << std::sqrt(inputNorm) std::cout << GridLogMG << " Level " << _CurrentLevel << ": V-cycle: Input norm = " << std::sqrt(inputNorm)
<< " Coarse residual = " << residualAfterCoarseGridCorrection << " Post-Smoother residual = " << residualAfterPostSmoother << " Coarse residual = " << residualAfterCoarseGridCorrection << " Post-Smoother residual = " << residualAfterPostSmoother
<< std::endl; << std::endl;
_SolveTotalTimer.Stop();
} }
void kCycle(Lattice<Fobj> const &in, Lattice<Fobj> &out) { void kCycle(Lattice<Fobj> const &in, Lattice<Fobj> &out) {
_SolveTotalTimer.Start();
RealD inputNorm = norm2(in); RealD inputNorm = norm2(in);
CoarseVector coarseSrc(_LevelInfo.Grids[_NextCoarserLevel]); CoarseVector coarseSrc(_LevelInfo.Grids[_NextCoarserLevel]);
@ -315,16 +352,26 @@ public:
MdagMLinearOperator<FineMatrix, FineVector> fineSmootherMdagMOp(_SmootherMatrix); MdagMLinearOperator<FineMatrix, FineVector> fineSmootherMdagMOp(_SmootherMatrix);
MdagMLinearOperator<CoarseMatrix, CoarseVector> coarseMdagMOp(_CoarseMatrix); MdagMLinearOperator<CoarseMatrix, CoarseVector> coarseMdagMOp(_CoarseMatrix);
_SolveRestrictionTimer.Start();
_Aggregates.ProjectToSubspace(coarseSrc, in); _Aggregates.ProjectToSubspace(coarseSrc, in);
_SolveRestrictionTimer.Stop();
_SolveNextLevelTimer.Start();
coarseFGMRES(coarseMdagMOp, coarseSrc, coarseSol); coarseFGMRES(coarseMdagMOp, coarseSrc, coarseSol);
_SolveNextLevelTimer.Stop();
_SolveProlongationTimer.Start();
_Aggregates.PromoteFromSubspace(coarseSol, out); _Aggregates.PromoteFromSubspace(coarseSol, out);
_SolveProlongationTimer.Stop();
fineMdagMOp.Op(out, fineTmp); fineMdagMOp.Op(out, fineTmp);
fineTmp = in - fineTmp; fineTmp = in - fineTmp;
auto r = norm2(fineTmp); auto r = norm2(fineTmp);
auto residualAfterCoarseGridCorrection = std::sqrt(r / inputNorm); auto residualAfterCoarseGridCorrection = std::sqrt(r / inputNorm);
_SolveSmootherTimer.Start();
fineFGMRES(fineSmootherMdagMOp, in, out); fineFGMRES(fineSmootherMdagMOp, in, out);
_SolveSmootherTimer.Stop();
fineMdagMOp.Op(out, fineTmp); fineMdagMOp.Op(out, fineTmp);
fineTmp = in - fineTmp; fineTmp = in - fineTmp;
@ -334,6 +381,8 @@ public:
std::cout << GridLogMG << " Level " << _CurrentLevel << ": K-cycle: Input norm = " << std::sqrt(inputNorm) std::cout << GridLogMG << " Level " << _CurrentLevel << ": K-cycle: Input norm = " << std::sqrt(inputNorm)
<< " Coarse residual = " << residualAfterCoarseGridCorrection << " Post-Smoother residual = " << residualAfterPostSmoother << " Coarse residual = " << residualAfterCoarseGridCorrection << " Post-Smoother residual = " << residualAfterPostSmoother
<< std::endl; << std::endl;
_SolveTotalTimer.Stop();
} }
void runChecks() { void runChecks() {
@ -477,6 +526,34 @@ public:
_NextPreconditionerLevel->runChecks(); _NextPreconditionerLevel->runChecks();
} }
void reportTimings() {
// clang-format off
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Setup total " << _SetupTotalTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Setup next level " << _SetupNextLevelTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve total " << _SolveTotalTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve restriction " << _SolveRestrictionTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve prolongation " << _SolveProlongationTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve smoother " << _SolveSmootherTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve next level " << _SolveNextLevelTimer.Elapsed() << std::endl;
// clang-format on
_NextPreconditionerLevel->reportTimings();
}
void resetTimers() {
_SetupTotalTimer.Reset();
_SetupNextLevelTimer.Reset();
_SolveTotalTimer.Reset();
_SolveRestrictionTimer.Reset();
_SolveProlongationTimer.Reset();
_SolveSmootherTimer.Reset();
_SolveNextLevelTimer.Reset();
_NextPreconditionerLevel->resetTimers();
}
}; };
// Specialization for the coarsest level // Specialization for the coarsest level
@ -494,11 +571,16 @@ public:
// Member Data // Member Data
///////////////////////////////////////////// /////////////////////////////////////////////
int _CurrentLevel; int _CurrentLevel;
MultiGridParams &_MultiGridParams; MultiGridParams &_MultiGridParams;
LevelInfo & _LevelInfo; LevelInfo & _LevelInfo;
FineMatrix & _FineMatrix;
FineMatrix & _SmootherMatrix; FineMatrix &_FineMatrix;
FineMatrix &_SmootherMatrix;
GridStopWatch _SolveTotalTimer;
GridStopWatch _SolveSmootherTimer;
///////////////////////////////////////////// /////////////////////////////////////////////
// Member Functions // Member Functions
@ -509,12 +591,17 @@ public:
, _MultiGridParams(mgParams) , _MultiGridParams(mgParams)
, _LevelInfo(LvlInfo) , _LevelInfo(LvlInfo)
, _FineMatrix(FineMat) , _FineMatrix(FineMat)
, _SmootherMatrix(SmootherMat) {} , _SmootherMatrix(SmootherMat) {
resetTimers();
}
void setup() {} void setup() {}
virtual void operator()(Lattice<Fobj> const &in, Lattice<Fobj> &out) { virtual void operator()(Lattice<Fobj> const &in, Lattice<Fobj> &out) {
_SolveTotalTimer.Start();
conformable(_LevelInfo.Grids[_CurrentLevel], in._grid); conformable(_LevelInfo.Grids[_CurrentLevel], in._grid);
conformable(in, out); conformable(in, out);
@ -527,10 +614,28 @@ public:
MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix); MdagMLinearOperator<FineMatrix, FineVector> fineMdagMOp(_FineMatrix);
_SolveSmootherTimer.Start();
fineFGMRES(fineMdagMOp, in, out); fineFGMRES(fineMdagMOp, in, out);
_SolveSmootherTimer.Stop();
_SolveTotalTimer.Stop();
} }
void runChecks() {} void runChecks() {}
void reportTimings() {
// clang-format off
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve total " << _SolveTotalTimer.Elapsed() << std::endl;
std::cout << GridLogMG << " Level " << _CurrentLevel << ": Time elapsed: Solve smoother " << _SolveSmootherTimer.Elapsed() << std::endl;
// clang-format on
}
void resetTimers() {
_SolveTotalTimer.Reset();
_SolveSmootherTimer.Reset();
}
}; };
template<class Fobj, class CoarseScalar, int nCoarseSpins, int nbasis, int nLevels, class Matrix> template<class Fobj, class CoarseScalar, int nCoarseSpins, int nbasis, int nLevels, class Matrix>
@ -680,6 +785,8 @@ int main(int argc, char **argv) {
std::cout << std::endl; std::cout << std::endl;
} }
MGPreconDw->reportTimings();
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
std::cout << GridLogMessage << "Testing Multigrid for Wilson Clover" << std::endl; std::cout << GridLogMessage << "Testing Multigrid for Wilson Clover" << std::endl;
std::cout << GridLogMessage << "**************************************************" << std::endl; std::cout << GridLogMessage << "**************************************************" << std::endl;
@ -701,5 +808,7 @@ int main(int argc, char **argv) {
std::cout << std::endl; std::cout << std::endl;
} }
MGPreconDwc->reportTimings();
Grid_finalize(); Grid_finalize();
} }