From: Wolfgang Bangerth Date: Wed, 11 Mar 1998 15:24:32 +0000 (+0000) Subject: Add dvector::norm_sqr and use modern processor architectures better. X-Git-Tag: v8.0.0~23196 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=193c66ad670322ee9f1ebdae7024b41fc9a51a40;p=dealii.git Add dvector::norm_sqr and use modern processor architectures better. git-svn-id: https://svn.dealii.org/trunk@55 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/dvector.h b/deal.II/lac/include/lac/dvector.h index 7dd9252740..ecf150f6b5 100644 --- a/deal.II/lac/include/lac/dvector.h +++ b/deal.II/lac/include/lac/dvector.h @@ -88,6 +88,11 @@ class dVector : public VectorBase * U = U * V . Scalar Produkt */ double operator*(const dVector& V) const; + + /** + * Return square of the norm. + */ + double norm_sqr () const; /** * Change Dimension.

@@ -260,6 +265,13 @@ class dVector : public VectorBase void print (ostream &) const; //@} + /** + * Exception + */ + DeclException2 (ExcDimensionsDontMatch, + int, int, + << "The dimensions " << arg1 << " and " << arg2 + << " do not match here."); /** * Exception */ diff --git a/deal.II/lac/source/dvector.cc b/deal.II/lac/source/dvector.cc index 2ab715f777..f47e262579 100644 --- a/deal.II/lac/source/dvector.cc +++ b/deal.II/lac/source/dvector.cc @@ -72,101 +72,172 @@ dVector::~dVector() if (val) delete[] val; } + + double dVector::operator * (const dVector& v) const { - int i; - double s; - for (i = 0, s = 0.; i < dim; i++) - { - s += val[i] * v.val[i]; - } - return s; + Assert (dim == v.dim, ExcDimensionsDontMatch(dim, v.dim)); + + double sum0 = 0, + sum1 = 0, + sum2 = 0, + sum3 = 0; + + // use modern processors better by + // allowing pipelined commands to be + // executed in parallel + for (int i=0; i<(dim/4); ++i) + { + sum0 += val[4*i] * v.val[4*i]; + sum1 += val[4*i+1] * v.val[4*i+1]; + sum2 += val[4*i+2] * v.val[4*i+2]; + sum3 += val[4*i+3] * v.val[4*i+3]; + }; + // add up remaining elements + for (int i=(dim/4)*4; i