From 31aa9cb4ab7fb75df36f89d96dfa540ebf8a00b3 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Sat, 25 Jul 2020 17:16:15 -0600 Subject: [PATCH] Improve memory behavior of the BiCGStab solver. --- include/deal.II/lac/solver_bicgstab.h | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/include/deal.II/lac/solver_bicgstab.h b/include/deal.II/lac/solver_bicgstab.h index 1c132063e4..a8705964f8 100644 --- a/include/deal.II/lac/solver_bicgstab.h +++ b/include/deal.II/lac/solver_bicgstab.h @@ -188,7 +188,7 @@ public: protected: /** - * Auxiliary vector. + * A pointer to the solution vector passed to solve(). */ VectorType *Vx; @@ -228,7 +228,7 @@ protected: typename VectorMemory::Pointer Vv; /** - * Right hand side vector. + * A pointer to the right hand side vector passed to solve(). */ const VectorType *Vb; @@ -456,10 +456,12 @@ SolverBicgstab::iterate(const MatrixType & A, print_vectors(step, *Vx, r, y); } while (state == SolverControl::iterate); + return IterationResult(false, state, step, res); } + template template void @@ -469,6 +471,8 @@ SolverBicgstab::solve(const MatrixType & A, const PreconditionerType &preconditioner) { LogStream::Prefix prefix("Bicgstab"); + + // Allocate temporary memory. Vr = typename VectorMemory::Pointer(this->memory); Vrbar = typename VectorMemory::Pointer(this->memory); Vp = typename VectorMemory::Pointer(this->memory); @@ -492,7 +496,8 @@ SolverBicgstab::solve(const MatrixType & A, IterationResult state(false, SolverControl::failure, 0, 0); - // iterate while the inner iteration returns a breakdown + // Iterate while the inner iteration returns a breakdown, i.e., try and try + // until we succeed. do { if (step != 0) @@ -507,11 +512,20 @@ SolverBicgstab::solve(const MatrixType & A, } while (state.breakdown == true); - // in case of failure: throw exception + // Release the temporary memory again. + Vr.reset(); + Vrbar.reset(); + Vp.reset(); + Vy.reset(); + Vz.reset(); + Vt.reset(); + Vv.reset(); + + // In case of failure: throw exception AssertThrow(state.state == SolverControl::success, SolverControl::NoConvergence(state.last_step, state.last_residual)); - // otherwise exit as normal + // Otherwise exit as normal } #endif // DOXYGEN -- 2.39.5