From 96be526cf1dbba4029ab6cac19ecf67a5d3c674c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 20 May 1998 09:27:18 +0000 Subject: [PATCH] Performance tweak to vmult (gain: approx. 20 per cent). This makes things a bit unreadable, but since these are parts of the library which need never to be modified if they work, that's not so much of a problem. git-svn-id: https://svn.dealii.org/trunk@323 0785d39b-7218-0410-832d-ea1e28bc413d --- deal.II/lac/source/dsmatrix.cc | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/deal.II/lac/source/dsmatrix.cc b/deal.II/lac/source/dsmatrix.cc index 4ecbafdb51..95c0525077 100644 --- a/deal.II/lac/source/dsmatrix.cc +++ b/deal.II/lac/source/dsmatrix.cc @@ -406,11 +406,14 @@ dSMatrix::vmult (dVector& dst, const dVector& src) const Assert(n() == src.size(), ExcDimensionsDontMatch(n(),src.size())); const unsigned int n_rows = m(); + const double *val_ptr = &val[cols->rowstart[0]]; + const int *colnum_ptr = &cols->colnums[cols->rowstart[0]]; for (unsigned int row=0; rowrowstart[row]; jrowstart[row+1]; ++j) - s += val[j] * src(cols->colnums[j]); + const double *val_end_of_row = &val[cols->rowstart[row+1]]; + while (val_ptr != val_end_of_row) + s += *val_ptr++ * src(*colnum_ptr++); dst(row) = s; } } @@ -445,12 +448,17 @@ dSMatrix::matrix_norm (const dVector& v) const Assert(n() == v.size(), ExcDimensionsDontMatch(n(),v.size())); double sum = 0.; - for (unsigned int i=0;irowstart[0]]; + const int *colnum_ptr = &cols->colnums[cols->rowstart[0]]; + for (unsigned int row=0; rowrowstart[i]; jrowstart[i+1]; ++j) - s += val[j] * v(cols->colnums[j]); - sum += s*v(i); + const double *val_end_of_row = &val[cols->rowstart[row+1]]; + while (val_ptr != val_end_of_row) + s += *val_ptr++ * v(*colnum_ptr++); + + sum += s*v(row); }; return sum; -- 2.39.5