]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Improve advance() operation and comparison operation a bit.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 May 2013 08:03:31 +0000 (08:03 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Wed, 8 May 2013 08:03:31 +0000 (08:03 +0000)
git-svn-id: https://svn.dealii.org/trunk@29480 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/chunk_sparse_matrix.h
deal.II/include/deal.II/lac/chunk_sparsity_pattern.h
deal.II/include/deal.II/lac/sparsity_pattern.h

index 3d7a5c2fc3518606c90d4676b3d1df72ded2e8ea..8ceb359cfa6717d624e9e2c535312b9974fcad7c 100644 (file)
@@ -1920,7 +1920,7 @@ namespace ChunkSparseMatrixIterators
     if (*this < other)
       {
         Iterator copy = *this;
-        while (copy < other)
+        while (copy != other)
           {
             ++copy;
             --difference;
@@ -1929,7 +1929,7 @@ namespace ChunkSparseMatrixIterators
     else
       {
         Iterator copy = other;
-        while (copy < *this)
+        while (copy != *this)
           {
             ++copy;
             ++difference;
index 655c0ba406483a2e7304e1745cc19db39f20844b..200c80303d7a2ad8fe62856b2701f91de0c761fa 100644 (file)
@@ -75,12 +75,6 @@ namespace ChunkSparsityPatternIterators
      */
     unsigned int row () const;
 
-    /**
-     * Index in row of the element represented by this object. This function
-     * can only be called for entries for which is_valid_entry() is true.
-     */
-    unsigned int index () const;
-
     /**
      * Returns the global index from the reduced sparsity pattern.
      */
@@ -131,12 +125,12 @@ namespace ChunkSparsityPatternIterators
     SparsityPatternIterators::Accessor reduced_accessor;
 
     /**
-     * Current row number.
+     * Current chunk row number.
      */
     unsigned int chunk_row;
 
     /**
-     * Current index in row.
+     * Current chunk col number.
      */
     unsigned int chunk_col;
 
@@ -964,7 +958,8 @@ namespace ChunkSparsityPatternIterators
   {
     Assert (is_valid_entry() == true, ExcInvalidIterator());
 
-    return sparsity_pattern->get_chunk_size()*reduced_accessor.row()+chunk_row;
+    return sparsity_pattern->get_chunk_size()*reduced_accessor.row() +
+      chunk_row;
   }
 
 
@@ -981,18 +976,6 @@ namespace ChunkSparsityPatternIterators
 
 
 
-  inline
-  unsigned int
-  Accessor::index() const
-  {
-    Assert (is_valid_entry() == true, ExcInvalidIterator());
-
-    return sparsity_pattern->get_chunk_size()*reduced_accessor.index() +
-      chunk_col;
-  }
-
-
-
   inline
   std::size_t
   Accessor::reduced_index() const
@@ -1026,17 +1009,7 @@ namespace ChunkSparsityPatternIterators
     Assert (sparsity_pattern == other.sparsity_pattern,
             ExcInternalError());
 
-    // comparison is a bit messy because of the way ChunkSparsityPattern
-    // stores entry: chunk rows run faster than the indices of the reduced
-    // sparsity pattern, but the accessors should of course compare less based
-    // on the actual row, not the reduced one.
-    if (chunk_row == other.chunk_row)
-      return (reduced_accessor.index_within_sparsity <
-              other.reduced_accessor.index_within_sparsity ||
-              (reduced_accessor.index_within_sparsity ==
-               other.reduced_accessor.index_within_sparsity &&
-               chunk_col < other.chunk_col));
-    else
+    if (chunk_row != other.chunk_row)
       {
         if (reduced_accessor.index_within_sparsity ==
             reduced_accessor.sparsity_pattern->n_nonzero_elements())
@@ -1044,24 +1017,23 @@ namespace ChunkSparsityPatternIterators
         if (other.reduced_accessor.index_within_sparsity ==
             reduced_accessor.sparsity_pattern->n_nonzero_elements())
           return true;
-        const unsigned int row = reduced_accessor.row(),
-          other_row = other.reduced_accessor.row();
-        return (row < other_row
-                ||
-                (row == other_row
-                 &&
-                 (chunk_row < other.chunk_row
-                  ||
-                  (chunk_row == other.chunk_row
-                   &&
-                   (reduced_accessor.index_within_sparsity <
-                    other.reduced_accessor.index_within_sparsity
-                    ||
-                    (reduced_accessor.index_within_sparsity ==
-                     other.reduced_accessor.index_within_sparsity
-                     &&
-                     chunk_col < other.chunk_col))))));
+
+        const unsigned int
+          global_row = sparsity_pattern->get_chunk_size()*reduced_accessor.row()
+          +chunk_row,
+          other_global_row = sparsity_pattern->get_chunk_size()*
+          other.reduced_accessor.row()+other.chunk_row;
+        if (global_row < other_global_row)
+          return true;
+        else if (global_row > other_global_row)
+          return false;
       }
+
+    return (reduced_accessor.index_within_sparsity <
+            other.reduced_accessor.index_within_sparsity ||
+            (reduced_accessor.index_within_sparsity ==
+             other.reduced_accessor.index_within_sparsity &&
+             chunk_col < other.chunk_col));
   }
 
 
@@ -1078,6 +1050,11 @@ namespace ChunkSparsityPatternIterators
             reduced_accessor.column() * chunk_size + chunk_col <
             sparsity_pattern->n_cols(),
             ExcIteratorPastEnd());
+    if (chunk_size == 1)
+      {
+        reduced_accessor.advance();
+        return;
+      }
 
     ++chunk_col;
 
@@ -1087,34 +1064,30 @@ namespace ChunkSparsityPatternIterators
         reduced_accessor.column() * chunk_size + chunk_col ==
         sparsity_pattern->n_cols())
       {
+        const unsigned int reduced_row = reduced_accessor.row();
         // end of row
-        if (reduced_accessor.index() + 1 ==
-            reduced_accessor.sparsity_pattern->row_length(reduced_accessor.row()))
+        if (reduced_accessor.index_within_sparsity + 1 ==
+            reduced_accessor.sparsity_pattern->rowstart[reduced_row+1])
           {
             ++chunk_row;
+
             chunk_col = 0;
-            const unsigned int old_reduced_row = reduced_accessor.row();
 
-            // end of matrix
-            if (old_reduced_row * chunk_size + chunk_row ==
-                sparsity_pattern->n_rows())
-              {
-                chunk_row = 0;
-                reduced_accessor =
-                  SparsityPatternIterators::Accessor(&sparsity_pattern->sparsity_pattern,
-                                                     sparsity_pattern->sparsity_pattern.n_nonzero_elements());
-              }
-            // end of chunk rows
-            else if (chunk_row == chunk_size)
+            // end of chunk rows or end of matrix
+            if (chunk_row == chunk_size ||
+                (reduced_row * chunk_size + chunk_row ==
+                 sparsity_pattern->n_rows()))
               {
-                reduced_accessor =
-                  *sparsity_pattern->sparsity_pattern.begin(old_reduced_row+1);
                 chunk_row = 0;
+                reduced_accessor.advance();
               }
+            // go back to the beginning of the same reduced row but with
+            // chunk_row increased by one
             else
-              reduced_accessor =
-                *sparsity_pattern->sparsity_pattern.begin(old_reduced_row);
+              reduced_accessor.index_within_sparsity =
+                reduced_accessor.sparsity_pattern->rowstart[reduced_row];
           }
+        // advance within chunk
         else
           {
             reduced_accessor.advance();
@@ -1185,7 +1158,7 @@ namespace ChunkSparsityPatternIterators
   bool
   Iterator::operator != (const Iterator &other) const
   {
-    return ! (*this == other);
+    return ! (accessor == other.accessor);
   }
 
 
index 17c5599b267d04983262cc597d1f74a185650183..212038578d0130fa2aee1fd0280ac79528447049 100644 (file)
@@ -1419,6 +1419,7 @@ private:
    */
   friend class SparsityPatternIterators::Iterator;
   friend class SparsityPatternIterators::Accessor;
+  friend class ChunkSparsityPatternIterators::Accessor;
 };
 
 

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.