]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Follow the documented advice of not looping over all elements of a matrix but do...
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 15:14:35 +0000 (15:14 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 12 Feb 2013 15:14:35 +0000 (15:14 +0000)
git-svn-id: https://svn.dealii.org/trunk@28323 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/lac/chunk_sparsity_pattern.cc

index 4fdc3389c0882c9b7ff92a80aff2a715ce88fcba..49fd1bc3a5b78cf04d2f29d7c880c68ac8d30712 100644 (file)
@@ -480,37 +480,43 @@ ChunkSparsityPattern::n_nonzero_elements () const
 
       else
         {
-          // if columns don't align, then
-          // just iterate over all chunks and
-          // see what this leads to
-          SparsityPattern::const_iterator p = sparsity_pattern.begin();
-          unsigned int n = 0;
-          for (; p!=sparsity_pattern.end(); ++p)
-            if ((p->row() != sparsity_pattern.n_rows() - 1)
-                &&
-                (p->column() != sparsity_pattern.n_cols() - 1))
-              n += chunk_size * chunk_size;
-            else if ((p->row() == sparsity_pattern.n_rows() - 1)
-                     &&
-                     (p->column() != sparsity_pattern.n_cols() - 1))
-              // last chunk row, but not
-              // last chunk column. only a
-              // smaller number (n_rows %
-              // chunk_size) of rows
-              // actually exist
-              n += (n_rows() % chunk_size) * chunk_size;
-            else if ((p->row() != sparsity_pattern.n_rows() - 1)
-                     &&
-                     (p->column() == sparsity_pattern.n_cols() - 1))
-              // last chunk column, but
-              // not row
-              n += (n_cols() % chunk_size) * chunk_size;
-            else
-              // bottom right chunk
-              n += (n_cols() % chunk_size) *
-                   (n_rows() % chunk_size);
-
-          return n;
+         // if columns don't align, then
+         // just iterate over all chunks and
+         // see what this leads to. follow the advice in the documentation of
+         // the sparsity pattern iterators to do the loop over individual rows,
+         // rather than all elements
+         unsigned int n = 0;
+
+         for (int row = 0; row < n_rows(); ++row)
+           {
+             SparsityPattern::const_iterator p = sparsity_pattern.begin(row);
+             for (; p!=sparsity_pattern.end(row); ++p)
+               if ((row != sparsity_pattern.n_rows() - 1)
+                   &&
+                   (p->column() != sparsity_pattern.n_cols() - 1))
+                 n += chunk_size * chunk_size;
+               else if ((row == sparsity_pattern.n_rows() - 1)
+                   &&
+                   (p->column() != sparsity_pattern.n_cols() - 1))
+                 // last chunk row, but not
+                 // last chunk column. only a
+                 // smaller number (n_rows %
+                 // chunk_size) of rows
+                 // actually exist
+                 n += (n_rows() % chunk_size) * chunk_size;
+               else if ((row != sparsity_pattern.n_rows() - 1)
+                   &&
+                   (p->column() == sparsity_pattern.n_cols() - 1))
+                 // last chunk column, but
+                 // not row
+                 n += (n_cols() % chunk_size) * chunk_size;
+               else
+                 // bottom right chunk
+                 n += (n_cols() % chunk_size) *
+                 (n_rows() % chunk_size);
+           }
+
+         return n;
         }
     }
 }

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.