]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
update memory handling
authorkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 14 Apr 2010 02:59:49 +0000 (02:59 +0000)
committerkanschat <kanschat@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 14 Apr 2010 02:59:49 +0000 (02:59 +0000)
git-svn-id: https://svn.dealii.org/trunk@20981 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_smoother.h

index 5d9743a492675569e1451eeaca9c7aada2924de3..ee61655ec2e8156c3a46426cb4da10c10254088c 100644 (file)
@@ -134,7 +134,7 @@ class MGSmoother : public MGSmootherBase<VECTOR>
                                     /**
                                      * Memory for auxiliary vectors.
                                      */
-    VectorMemory<VECTOR>& mem;
+    SmartPointer<VectorMemory<VECTOR>, MGSmoother<VECTOR> > mem;
 };
 
 
@@ -547,7 +547,7 @@ MGSmoother<VECTOR>::MGSmoother(
                symmetric(symmetric),
                transpose(transpose),
                debug(0),
-               mem(mem)
+               mem(&mem)
 {}
 
 
@@ -726,9 +726,10 @@ MGSmootherRelaxation<MATRIX, RELAX, VECTOR>::smooth(
 
   if (this->variable)
     steps2 *= (1<<(maxlevel-level));
-
-  VECTOR* r = this->mem.alloc();
-  VECTOR* d = this->mem.alloc();
+  
+  GrowingVectorMemory<VECTOR> mem2;
+  typename VectorMemory<VECTOR>::Pointer r((this->mem) ? *this->mem : mem2);
+  typename VectorMemory<VECTOR>::Pointer d((this->mem) ? *this->mem : mem2);
   r->reinit(u);
   d->reinit(u);
 
@@ -768,9 +769,6 @@ MGSmootherRelaxation<MATRIX, RELAX, VECTOR>::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<MATRIX, PRECONDITIONER, VECTOR>::smooth(
   if (this->variable)
     steps2 *= (1<<(maxlevel-level));
 
-  VECTOR* r = this->mem.alloc();
-  VECTOR* d = this->mem.alloc();
+  GrowingVectorMemory<VECTOR> mem2;
+  typename VectorMemory<VECTOR>::Pointer r((this->mem) ? *this->mem : mem2);
+  typename VectorMemory<VECTOR>::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; i<steps2; ++i)
     {
-      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; i<steps2; ++i)
+      if (T)
        {
-         if (T)
-           {
-             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;
-
-      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();
 }
 
 

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.