From cf6057d5e4b6545b2183917b077facd3d1c7a085 Mon Sep 17 00:00:00 2001 From: Thomas Fischer <thomas.fischer@ufz.de> Date: Wed, 18 Jan 2012 10:49:28 +0100 Subject: [PATCH] fixed memory leak in solver CGParallel fixed a warning in CGParallel --- MathLib/LinAlg/Solvers/CG.h | 2 +- MathLib/LinAlg/Solvers/CGParallel.cpp | 13 +++++++++++-- .../ConjugateGradientDiagonalPreconditioned.cpp | 2 +- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/MathLib/LinAlg/Solvers/CG.h b/MathLib/LinAlg/Solvers/CG.h index 60961d003b5..9996a872cbe 100644 --- a/MathLib/LinAlg/Solvers/CG.h +++ b/MathLib/LinAlg/Solvers/CG.h @@ -18,7 +18,7 @@ unsigned CG(CRSMatrix<double,unsigned> const * mat, double const * const b, #ifdef _OPENMP unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const b, - double* const x, double& eps, unsigned& nsteps, unsigned num_threads = 1); + double* const x, double& eps, unsigned& nsteps); #endif } // end namespace MathLib diff --git a/MathLib/LinAlg/Solvers/CGParallel.cpp b/MathLib/LinAlg/Solvers/CGParallel.cpp index e5fc627ec83..f14824dc4af 100644 --- a/MathLib/LinAlg/Solvers/CGParallel.cpp +++ b/MathLib/LinAlg/Solvers/CGParallel.cpp @@ -33,9 +33,9 @@ namespace MathLib { #ifdef _OPENMP unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const b, - double* const x, double& eps, unsigned& nsteps, unsigned num_threads) + double* const x, double& eps, unsigned& nsteps) { - unsigned N = mat->getNRows(); + const unsigned N(mat->getNRows()); double * __restrict__ p(new double[N]); double * __restrict__ q(new double[N]); double * __restrict__ r(new double[N]); @@ -63,6 +63,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const eps = resid / nrmb; nsteps = 0; delete[] p; + delete[] q; + delete[] r; + delete[] rhat; return 0; } @@ -128,6 +131,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const eps = resid / nrmb; nsteps = l; delete[] p; + delete[] q; + delete[] r; + delete[] rhat; return 0; } @@ -135,6 +141,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const } eps = resid / nrmb; delete[] p; + delete[] q; + delete[] r; + delete[] rhat; return 1; } #endif diff --git a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp index 30700aa9524..bfb4333f459 100644 --- a/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp +++ b/SimpleTests/SolverTests/ConjugateGradientDiagonalPreconditioned.cpp @@ -68,7 +68,7 @@ int main(int argc, char *argv[]) MathLib::CG(mat, b, x, eps, steps); } else { #ifdef _OPENMP - MathLib::CGParallel(mat, b, x, eps, steps, num_omp_threads); + MathLib::CGParallel(mat, b, x, eps, steps); #else std::cout << "OpenMP is not switched on" << std::endl; #endif -- GitLab