]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add extract_row_copy method to chunk sparse matrix since iterators are very slow
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 20 Jan 2014 20:01:30 +0000 (20:01 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Mon, 20 Jan 2014 20:01:30 +0000 (20:01 +0000)
git-svn-id: https://svn.dealii.org/trunk@32267 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/chunk_sparse_matrix.h
deal.II/include/deal.II/lac/chunk_sparse_matrix.templates.h

index e9ef398417eb8d98e7c1af9ddf544de35ab8ad38..f44a0318d096af93809c9337576e007708aa0623 100644 (file)
@@ -791,11 +791,8 @@ public:
              const size_type j) const;
 
   /**
-   * Return the main diagonal
-   * element in the <i>i</i>th
-   * row. This function throws an
-   * error if the matrix is not
-   * quadratic.
+   * Return the main diagonal element in the <i>i</i>th row. This function
+   * throws an error if the matrix is not quadratic.
    *
    * This function is considerably faster than the operator()(), since for
    * quadratic matrices, the diagonal entry may be the first to be stored in
@@ -810,6 +807,21 @@ public:
    */
   number &diag_element (const size_type i);
 
+  /**
+   * Extracts a copy of the values and indices in the given matrix row.
+   *
+   * The user is expected to pass the length of the arrays column_indices and
+   * values, which gives a means for checking that we do not write to
+   * unallocated memory. This method is motivated by a similar method in
+   * Trilinos row matrices and gives faster access to entries in the matrix as
+   * compared to iterators which are quite slow for this matrix type.
+   */
+  void extract_row_copy (const size_type row,
+                         const size_type array_length,
+                         size_type      &row_length,
+                         size_type      *column_indices,
+                         number         *values) const;
+
 //@}
   /**
    * @name Matrix vector multiplications
index 62f8409c8f3092877c5eac733c4d017c204551b2..b493ed3f26b460843fdfb50cf5023ff04e5ad16f 100644 (file)
@@ -596,6 +596,38 @@ ChunkSparseMatrix<number>::add (const number factor,
 }
 
 
+
+template <typename number>
+void
+ChunkSparseMatrix<number>::extract_row_copy (const size_type row,
+                                             const size_type array_length,
+                                             size_type &row_length,
+                                             size_type *column_indices,
+                                             number *values) const
+{
+  row_length = cols->row_length(row);
+  const unsigned int chunk_size = cols->get_chunk_size();
+  const size_type reduced_row = row/chunk_size;
+  AssertIndexRange(cols->sparsity_pattern.row_length(reduced_row)*chunk_size,
+                   array_length+1);
+
+  SparsityPattern::iterator it = cols->sparsity_pattern.begin(reduced_row),
+    itend = cols->sparsity_pattern.end(reduced_row);
+  const number *val_ptr = &val[(it-cols->sparsity_pattern.begin(0))*chunk_size*chunk_size
+                               +(row%chunk_size)*chunk_size];
+  for ( ; it < itend; ++it)
+    {
+      for (unsigned int c=0; c<chunk_size; ++c)
+        {
+          *values++ = val_ptr[c];
+          *column_indices++ = it->column()*chunk_size+c;
+        }
+      val_ptr += chunk_size*chunk_size;
+    }
+}
+
+
+
 template <typename number>
 template <class OutVector, class InVector>
 void

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.