]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Use a cache of column indices to improve the speed of the Trilinos sparsity pattern...
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 28 Dec 2008 14:04:26 +0000 (14:04 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Sun, 28 Dec 2008 14:04:26 +0000 (14:04 +0000)
git-svn-id: https://svn.dealii.org/trunk@18036 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/lac/include/lac/trilinos_sparsity_pattern.h
deal.II/lac/source/trilinos_sparsity_pattern.cc

index 11707a96db32b9ef7600e238385b84a34699870d..71a9508bf1119538d028eae4e7fcafb3498527f1 100755 (executable)
@@ -957,6 +957,28 @@ namespace TrilinosWrappers
                                         */
       std::auto_ptr<Epetra_FECrsGraph> graph;
 
+                                       /**
+                                       * Scratch array that holds several
+                                       * indices that should be written
+                                       * into the same row of the sparsity
+                                       * pattern. This is to increase the
+                                       * speed of this function.
+                                       */
+      std::vector<unsigned int> cached_row_indices;
+
+                                      /**
+                                       * A number that tells how many
+                                       * indices currently are active in
+                                       * the cache.
+                                       */
+      unsigned int n_cached_elements;
+
+                                      /**
+                                       * The row that is currently in the
+                                       * cache.
+                                       */
+      unsigned int row_in_cache;
+
       friend class SparseMatrix;
       friend class SparsityPatternIterators::const_iterator;
   };
@@ -1205,10 +1227,32 @@ namespace TrilinosWrappers
 
   inline
   void
-  SparsityPattern::add (const unsigned int   i,
-                       const unsigned int   j)
+  SparsityPattern::add (const unsigned int i,
+                       const unsigned int j)
   {
-    add (i, 1, &j);
+                                  // if we want to write an element to the
+                                  // row the cache is currently pointed to,
+                                  // we just append the data to the cache
+    if (i == row_in_cache)
+      {
+                                  // if the size is too small, extend the
+                                  // cache by 10 elements
+       if (n_cached_elements > cached_row_indices.size())
+         cached_row_indices.resize(cached_row_indices.size() + 10);
+
+       cached_row_indices[n_cached_elements] = j;
+       ++n_cached_elements;
+       return;
+      }
+
+                                  // if we are to write another row data,
+                                  // we write the cache data into the
+                                  // sparsity pattern, and then call this
+                                  // function again
+    add (row_in_cache, n_cached_elements, &cached_row_indices[0]);
+    row_in_cache = i;
+    n_cached_elements = 0;
+    add (i,j);
   }
 
 
@@ -1219,6 +1263,9 @@ namespace TrilinosWrappers
                        const unsigned int    n_cols,
                        const unsigned int   *col_indices)
   {
+    if (n_cols == 0)
+      return;
+
     int * col_index_ptr = (int*)col_indices;
     compressed = false;
 
index 5de4418625c4a7946f167a4f492cb00580bc32df..49bdefb7bee69aa05c2e712ef58bb89d4e533f0f 100755 (executable)
@@ -90,7 +90,10 @@ namespace TrilinosWrappers
                  col_map (row_map),
                  compressed (true),
                  graph (std::auto_ptr<Epetra_FECrsGraph>
-                                 (new Epetra_FECrsGraph(View, row_map, 0)))
+                        (new Epetra_FECrsGraph(View, row_map, 0))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {
     graph->FillComplete();
   }
@@ -103,7 +106,10 @@ namespace TrilinosWrappers
                  compressed (false),
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                                  (new Epetra_FECrsGraph(Copy, row_map, 
-                                       int(n_entries_per_row), false)))
+                                       int(n_entries_per_row), false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
   SparsityPattern::SparsityPattern (const Epetra_Map                &InputMap,
@@ -115,7 +121,10 @@ namespace TrilinosWrappers
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                    (new Epetra_FECrsGraph(Copy, row_map, 
                      (int*)const_cast<unsigned int*>(&(n_entries_per_row[0])),
-                                           false)))
+                                           false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
   SparsityPattern::SparsityPattern (const Epetra_Map  &InputRowMap,
@@ -127,7 +136,10 @@ namespace TrilinosWrappers
                  compressed (false),
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                                  (new Epetra_FECrsGraph(Copy, row_map, 
-                                       int(n_entries_per_row), false)))
+                                       int(n_entries_per_row), false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
   SparsityPattern::SparsityPattern (const Epetra_Map                &InputRowMap,
@@ -140,7 +152,10 @@ namespace TrilinosWrappers
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                    (new Epetra_FECrsGraph(Copy, row_map, 
                      (int*)const_cast<unsigned int*>(&(n_entries_per_row[0])),
-                                           false)))
+                                           false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
   SparsityPattern::SparsityPattern (const unsigned int m,
@@ -157,7 +172,10 @@ namespace TrilinosWrappers
                  compressed (false),
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                                (new Epetra_FECrsGraph(Copy, row_map, 
-                                       int(n_entries_per_row), false)))
+                                       int(n_entries_per_row), false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
   SparsityPattern::SparsityPattern (const unsigned int               m,
@@ -175,7 +193,10 @@ namespace TrilinosWrappers
                  graph (std::auto_ptr<Epetra_FECrsGraph>
                     (new Epetra_FECrsGraph(Copy, row_map, 
                        (int*)const_cast<unsigned int*>(&(n_entries_per_row[0])), 
-                                            false)))
+                                            false))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
 
                                   // Copy function is currently not working
@@ -190,7 +211,10 @@ namespace TrilinosWrappers
                  col_map (InputSP.col_map),
                  compressed (false),
                  graph (std::auto_ptr<Epetra_FECrsGraph>
-                         (new Epetra_FECrsGraph(*InputSP.graph)))
+                         (new Epetra_FECrsGraph(*InputSP.graph))),
+                 cached_row_indices (1),
+                 n_cached_elements (0),
+                 row_in_cache (0)
   {}
   */
 
@@ -239,6 +263,9 @@ namespace TrilinosWrappers
 
     graph = std::auto_ptr<Epetra_FECrsGraph>
       (new Epetra_FECrsGraph(Copy, row_map, n_entries_per_row, false));
+
+    n_cached_elements = 0;
+    row_in_cache = 0;
   }
 
 
@@ -289,6 +316,9 @@ namespace TrilinosWrappers
       (new Epetra_FECrsGraph(Copy, row_map, 
                             n_entries_per_row[input_row_map.MinMyGID()], 
                             false));
+
+    n_cached_elements = 0;
+    row_in_cache = 0;
   }
 
 
@@ -473,6 +503,9 @@ namespace TrilinosWrappers
 
     graph->FillComplete();
 
+    n_cached_elements = 0;
+    row_in_cache = 0;
+
     compressed = true;
   }
 
@@ -482,6 +515,13 @@ namespace TrilinosWrappers
   SparsityPattern::compress ()
   {
                                  // flush buffers
+    if (n_cached_elements > 0)
+      {
+       add (row_in_cache, n_cached_elements, &cached_row_indices[0]);
+       n_cached_elements = 0;
+       row_in_cache = 0;
+      }
+
     int ierr;
     ierr = graph->GlobalAssemble (col_map, row_map, true);
     
@@ -630,7 +670,7 @@ namespace TrilinosWrappers
   unsigned int
   SparsityPattern::max_entries_per_row () const
   {
-    int nnz = graph->MaxRowDim();
+    int nnz = graph->MaxNumIndices();
 
     return static_cast<unsigned int>(nnz);
   }

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.