From: kronbichler Date: Sat, 27 Sep 2008 11:12:43 +0000 (+0000) Subject: Introduce a temporary vector in the Trilinos SparseMatrix class that is used for... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=762047cf810c2e4be03102f7c481b84bcb73c398;p=dealii-svn.git Introduce a temporary vector in the Trilinos SparseMatrix class that is used for faster vmult_add and matrix_scalar_product operations. git-svn-id: https://svn.dealii.org/trunk@17018 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/trilinos_sparse_matrix.h b/deal.II/lac/include/lac/trilinos_sparse_matrix.h index 315f6e3d1b..3ea0425fa3 100755 --- a/deal.II/lac/include/lac/trilinos_sparse_matrix.h +++ b/deal.II/lac/include/lac/trilinos_sparse_matrix.h @@ -1461,6 +1461,16 @@ namespace TrilinosWrappers */ bool compressed; + /** + * An internal Trilinos vector + * that is used for + * accelerating vmult_add + * functions (do not need to + * allocate too many temporary + * vectors). + */ + mutable VectorBase temp_vector; + public: /** * A sparse matrix object in diff --git a/deal.II/lac/source/trilinos_sparse_matrix.cc b/deal.II/lac/source/trilinos_sparse_matrix.cc index 0f8a43f187..9e3ef01181 100755 --- a/deal.II/lac/source/trilinos_sparse_matrix.cc +++ b/deal.II/lac/source/trilinos_sparse_matrix.cc @@ -914,9 +914,10 @@ namespace TrilinosWrappers { Assert (&src != &dst, ExcSourceEqualsDestination()); - VectorBase tmp(dst); + temp_vector.reinit(dst); + vmult (dst, src); - dst += tmp; + dst += temp_vector; } @@ -927,9 +928,10 @@ namespace TrilinosWrappers { Assert (&src != &dst, ExcSourceEqualsDestination()); - VectorBase tmp(dst); + temp_vector.reinit(dst); + vmult (dst, src); - dst += tmp; + dst += temp_vector; } @@ -937,9 +939,14 @@ namespace TrilinosWrappers TrilinosScalar SparseMatrix::matrix_norm_square (const VectorBase &v) const { - VectorBase tmp (v); - vmult (tmp, v); - return tmp*v; + Assert (row_map.SameAs(col_map), + ExcDimensionMismatch(row_map.NumGlobalElements(), + col_map.NumGlobalElements())); + + temp_vector.reinit(v); + + vmult (temp_vector, v); + return temp_vector*v; } @@ -948,9 +955,14 @@ namespace TrilinosWrappers SparseMatrix::matrix_scalar_product (const VectorBase &u, const VectorBase &v) const { - VectorBase tmp (v); - vmult (tmp, v); - return u*tmp; + Assert (row_map.SameAs(col_map), + ExcDimensionMismatch(row_map.NumGlobalElements(), + col_map.NumGlobalElements())); + + temp_vector.reinit(v); + + vmult (temp_vector, v); + return u*temp_vector; }