]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Fix high memory consumption in ChunkSparsityPattern::copy_from by creating the reduce...
authorMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 7 Aug 2013 09:47:47 +0000 (09:47 +0000)
committerMartin Kronbichler <kronbichler@lnm.mw.tum.de>
Wed, 7 Aug 2013 09:47:47 +0000 (09:47 +0000)
git-svn-id: https://svn.dealii.org/trunk@30244 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/examples/step-51/doc/results.dox
deal.II/examples/step-51/step-51.cc
deal.II/source/lac/chunk_sparsity_pattern.cc
deal.II/source/lac/sparsity_pattern.cc

index 1b7193f9dc1681a09ae3c4ac0edfacedcf409253..3ec10ba82d23615a27d3a0451b9083d87add27e8 100644 (file)
@@ -6,6 +6,7 @@ The program writes convergence tables to the screen while running:
 
 @code
 Q1 elements:
+cells dofs      val L2        grad L2      val L2-post   
    16    80 4.570e+00    - 1.221e+01    - 4.333e+00    -
    36   168 1.869e+00 2.20 7.299e+00 1.27 1.734e+00 2.26
    64   288 7.177e-01 3.33 4.218e+00 1.91 2.538e-01 6.68
@@ -18,6 +19,7 @@ Q1 elements:
  9216 37248 4.690e-03 1.97 3.228e-02 1.97 1.600e-04 2.96
 
 Q3 elements:
+cells dofs      val L2        grad L2      val L2-post   
    16   160 2.398e-01    - 1.873e+00    - 1.354e-01    -
    36   336 5.843e-02 3.48 5.075e-01 3.22 1.882e-02 4.87
    64   576 3.466e-02 1.82 2.534e-01 2.41 4.326e-03 5.11
index 41d3975d36f20a60dc93aa52ad1693297ffd673e..281dbfefdd9330f90272104b8f854d9d2a696bdd 100644 (file)
@@ -339,21 +339,13 @@ Step51<dim>::setup_system ()
 
   constraints.clear ();
   DoFTools::make_hanging_node_constraints (dof_handler, constraints);
-  std::map<unsigned int,double> boundary_values;
   typename FunctionMap<dim>::type boundary_functions;
   Solution<dim> solution;
   boundary_functions[0] = &solution;
   VectorTools::project_boundary_values (mapping, dof_handler,
                                         boundary_functions,
                                         QGauss<dim-1>(fe.degree+1),
-                                        boundary_values);
-  for (std::map<unsigned int,double>::iterator it = boundary_values.begin();
-       it != boundary_values.end(); ++it)
-    if (constraints.is_constrained(it->first) == false)
-      {
-        constraints.add_line(it->first);
-        constraints.set_inhomogeneity(it->first, it->second);
-      }
+                                        constraints);
   constraints.close ();
 
   {
index a9e5b9de0b1603e00c4d6051040cafca90349b9a..ef64577192aae77e580881e730172775741e8546 100644 (file)
@@ -265,22 +265,26 @@ namespace internal
     // distinguish between compressed sparsity types that define row_begin()
     // and SparsityPattern that uses begin() as iterator type
     template <typename Sparsity>
-    void copy_row (const Sparsity       &csp,
-                   const size_type       row,
-                   ChunkSparsityPattern &dst)
+    void copy_row (const Sparsity                  &csp,
+                   const size_type                  row,
+                   const unsigned int               chunk_size,
+                   CompressedSimpleSparsityPattern &dst)
     {
       typename Sparsity::row_iterator col_num = csp.row_begin (row);
+      const size_type reduced_row = row/chunk_size;
       for (; col_num != csp.row_end (row); ++col_num)
-        dst.add (row, *col_num);
+        dst.add (reduced_row, *col_num/chunk_size);
     }
 
-    void copy_row (const SparsityPattern &csp,
-                   const size_type        row,
-                   ChunkSparsityPattern  &dst)
+    void copy_row (const SparsityPattern           &csp,
+                   const size_type                  row,
+                   const unsigned int               chunk_size,
+                   CompressedSimpleSparsityPattern &dst)
     {
       SparsityPattern::iterator col_num = csp.begin (row);
+      const size_type reduced_row = row/chunk_size;
       for (; col_num != csp.end (row); ++col_num)
-        dst.add (row, col_num->column());
+        dst.add (reduced_row, col_num->column()/chunk_size);
     }
   }
 }
@@ -293,22 +297,27 @@ ChunkSparsityPattern::copy_from (const SparsityType &csp,
 {
   Assert (chunk_size > 0, ExcInvalidNumber (chunk_size));
 
-  // count number of entries per row, then initialize the underlying sparsity
-  // pattern
-  std::vector<size_type> entries_per_row (csp.n_rows(), 0);
-  for (size_type row = 0; row<csp.n_rows(); ++row)
-    entries_per_row[row] = csp.row_length(row);
+  // simple case: just use the other sparsity pattern
+  if (chunk_size == 1)
+    {
+      sparsity_pattern.copy_from (csp);
+      return;
+    }
 
-  reinit (csp.n_rows(), csp.n_cols(),
-          entries_per_row,
-          chunk_size);
+  // create a temporary compressed sparsity pattern that collects all entries
+  // from the input sparsity pattern and then initialize the underlying small
+  // sparsity pattern
+  this->chunk_size = chunk_size;
+  rows = csp.n_rows();
+  cols = csp.n_cols();
+  const size_type m_chunks = (csp.n_rows()+chunk_size-1) / chunk_size,
+                  n_chunks = (csp.n_cols()+chunk_size-1) / chunk_size;
+  CompressedSimpleSparsityPattern temporary_sp(m_chunks, n_chunks);
 
-  // then actually fill it
   for (size_type row = 0; row<csp.n_rows(); ++row)
-    internal::copy_row(csp, row, *this);
+    internal::copy_row(csp, row, chunk_size, temporary_sp);
 
-  // finally compress
-  compress ();
+  sparsity_pattern.copy_from (temporary_sp);
 }
 
 
index 18f2c1b0de777fd14dcc87c734eb9b9e5fcbf45c..edef0ca4efcb1db7beabdf8d57370af5db40c475 100644 (file)
@@ -1195,6 +1195,7 @@ template void SparsityPattern::copy_from<CompressedSimpleSparsityPattern> (const
 template void SparsityPattern::copy_from<float> (const FullMatrix<float> &, bool);
 template void SparsityPattern::copy_from<double> (const FullMatrix<double> &, bool);
 
+template void SparsityPattern::copy_from<SparsityPattern> (const SparsityPattern &);
 template void SparsityPattern::copy_from<CompressedSparsityPattern> (const CompressedSparsityPattern &);
 template void SparsityPattern::copy_from<CompressedSetSparsityPattern> (const CompressedSetSparsityPattern &);
 template void SparsityPattern::copy_from<CompressedSimpleSparsityPattern> (const CompressedSimpleSparsityPattern &);

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.