Skip to content
Snippets Groups Projects
Commit cf6057d5 authored by Tom Fischer's avatar Tom Fischer
Browse files

fixed memory leak in solver CGParallel

fixed a warning in CGParallel
parent 8eccf8b9
No related branches found
No related tags found
No related merge requests found
...@@ -18,7 +18,7 @@ unsigned CG(CRSMatrix<double,unsigned> const * mat, double const * const b, ...@@ -18,7 +18,7 @@ unsigned CG(CRSMatrix<double,unsigned> const * mat, double const * const b,
#ifdef _OPENMP #ifdef _OPENMP
unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const b, 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 #endif
} // end namespace MathLib } // end namespace MathLib
......
...@@ -33,9 +33,9 @@ namespace MathLib { ...@@ -33,9 +33,9 @@ namespace MathLib {
#ifdef _OPENMP #ifdef _OPENMP
unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const b, 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__ p(new double[N]);
double * __restrict__ q(new double[N]); double * __restrict__ q(new double[N]);
double * __restrict__ r(new double[N]); double * __restrict__ r(new double[N]);
...@@ -63,6 +63,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const ...@@ -63,6 +63,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const
eps = resid / nrmb; eps = resid / nrmb;
nsteps = 0; nsteps = 0;
delete[] p; delete[] p;
delete[] q;
delete[] r;
delete[] rhat;
return 0; return 0;
} }
...@@ -128,6 +131,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const ...@@ -128,6 +131,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const
eps = resid / nrmb; eps = resid / nrmb;
nsteps = l; nsteps = l;
delete[] p; delete[] p;
delete[] q;
delete[] r;
delete[] rhat;
return 0; return 0;
} }
...@@ -135,6 +141,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const ...@@ -135,6 +141,9 @@ unsigned CGParallel(CRSMatrix<double,unsigned> const * mat, double const * const
} }
eps = resid / nrmb; eps = resid / nrmb;
delete[] p; delete[] p;
delete[] q;
delete[] r;
delete[] rhat;
return 1; return 1;
} }
#endif #endif
......
...@@ -68,7 +68,7 @@ int main(int argc, char *argv[]) ...@@ -68,7 +68,7 @@ int main(int argc, char *argv[])
MathLib::CG(mat, b, x, eps, steps); MathLib::CG(mat, b, x, eps, steps);
} else { } else {
#ifdef _OPENMP #ifdef _OPENMP
MathLib::CGParallel(mat, b, x, eps, steps, num_omp_threads); MathLib::CGParallel(mat, b, x, eps, steps);
#else #else
std::cout << "OpenMP is not switched on" << std::endl; std::cout << "OpenMP is not switched on" << std::endl;
#endif #endif
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment