From: Wolfgang Bangerth Date: Sat, 25 Jul 2020 23:16:15 +0000 (-0600) Subject: Improve memory behavior of the BiCGStab solver. X-Git-Tag: v9.3.0-rc1~1228^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F10752%2Fhead;p=dealii.git Improve memory behavior of the BiCGStab solver. --- 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