From: kanschat Date: Wed, 14 Apr 2010 02:59:49 +0000 (+0000) Subject: update memory handling X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=be00230cd9b8fb5fe4b54b5753f5e76bf5ae66ac;p=dealii-svn.git update memory handling git-svn-id: https://svn.dealii.org/trunk@20981 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/multigrid/mg_smoother.h b/deal.II/deal.II/include/multigrid/mg_smoother.h index 5d9743a492..ee61655ec2 100644 --- a/deal.II/deal.II/include/multigrid/mg_smoother.h +++ b/deal.II/deal.II/include/multigrid/mg_smoother.h @@ -134,7 +134,7 @@ class MGSmoother : public MGSmootherBase /** * Memory for auxiliary vectors. */ - VectorMemory& mem; + SmartPointer, MGSmoother > mem; }; @@ -547,7 +547,7 @@ MGSmoother::MGSmoother( symmetric(symmetric), transpose(transpose), debug(0), - mem(mem) + mem(&mem) {} @@ -726,9 +726,10 @@ MGSmootherRelaxation::smooth( if (this->variable) steps2 *= (1<<(maxlevel-level)); - - VECTOR* r = this->mem.alloc(); - VECTOR* d = this->mem.alloc(); + + GrowingVectorMemory mem2; + typename VectorMemory::Pointer r((this->mem) ? *this->mem : mem2); + typename VectorMemory::Pointer d((this->mem) ? *this->mem : mem2); r->reinit(u); d->reinit(u); @@ -768,9 +769,6 @@ MGSmootherRelaxation::smooth( } if (this->debug > 0) deallog << std::endl; - - this->mem.free(r); - this->mem.free(d); } #else @@ -816,7 +814,7 @@ memory_consumption () const return sizeof(*this) + matrices.memory_consumption() + smoothers.memory_consumption() - + this->mem.memory_consumption(); + + this->mem->memory_consumption(); } @@ -965,63 +963,49 @@ MGSmootherPrecondition::smooth( if (this->variable) steps2 *= (1<<(maxlevel-level)); - VECTOR* r = this->mem.alloc(); - VECTOR* d = this->mem.alloc(); + GrowingVectorMemory mem2; + typename VectorMemory::Pointer r((this->mem) ? *this->mem : mem2); + typename VectorMemory::Pointer d((this->mem) ? *this->mem : mem2); - try + r->reinit(u,true); + d->reinit(u,true); + + bool T = this->transpose; + if (this->symmetric && (steps2 % 2 == 0)) + T = false; + if (this->debug > 0) + deallog << 'S' << level << ' '; + + for (unsigned int i=0; ireinit(u,true); - d->reinit(u,true); - - bool T = this->transpose; - if (this->symmetric && (steps2 % 2 == 0)) - T = false; - if (this->debug > 0) - deallog << 'S' << level << ' '; - - for (unsigned int i=0; idebug > 0) - deallog << 'T'; - matrices[level].Tvmult(*r,u); - r->sadd(-1.,1.,rhs); - if (this->debug > 2) - deallog << ' ' << r->l2_norm() << ' '; - smoothers[level].Tvmult(*d, *r); - if (this->debug > 1) - deallog << ' ' << d->l2_norm() << ' '; - } else { - if (this->debug > 0) - deallog << 'N'; - matrices[level].vmult(*r,u); - r->sadd(-1.,rhs); - if (this->debug > 2) - deallog << ' ' << r->l2_norm() << ' '; - smoothers[level].vmult(*d, *r); - if (this->debug > 1) - deallog << ' ' << d->l2_norm() << ' '; - } - u += *d; - if (this->symmetric) - T = !T; - } - if (this->debug > 0) - deallog << std::endl; - - this->mem.free(r); - this->mem.free(d); - } - catch (...) - { - // make sure we don't produce a - // memory leak - this->mem.free(r); - this->mem.free(d); - - throw; + if (this->debug > 0) + deallog << 'T'; + matrices[level].Tvmult(*r,u); + r->sadd(-1.,1.,rhs); + if (this->debug > 2) + deallog << ' ' << r->l2_norm() << ' '; + smoothers[level].Tvmult(*d, *r); + if (this->debug > 1) + deallog << ' ' << d->l2_norm() << ' '; + } else { + if (this->debug > 0) + deallog << 'N'; + matrices[level].vmult(*r,u); + r->sadd(-1.,rhs); + if (this->debug > 2) + deallog << ' ' << r->l2_norm() << ' '; + smoothers[level].vmult(*d, *r); + if (this->debug > 1) + deallog << ' ' << d->l2_norm() << ' '; + } + u += *d; + if (this->symmetric) + T = !T; } + if (this->debug > 0) + deallog << std::endl; } @@ -1034,7 +1018,7 @@ memory_consumption () const return sizeof(*this) + matrices.memory_consumption() + smoothers.memory_consumption() - + this->mem.memory_consumption(); + + this->mem->memory_consumption(); }