From: Martin Kronbichler Date: Tue, 8 Sep 2009 12:45:17 +0000 (+0000) Subject: Use a smarter implementation of a parallel = operator. Work around a problem with... X-Git-Tag: v8.0.0~7160 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=e37962f0247144797c97e91d969ba64cc741dcf9;p=dealii.git Use a smarter implementation of a parallel = operator. Work around a problem with the g++ on MacOSX. git-svn-id: https://svn.dealii.org/trunk@19413 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/lac/include/lac/vector.h b/deal.II/lac/include/lac/vector.h index ad1ad3e760..38ed5b720c 100644 --- a/deal.II/lac/include/lac/vector.h +++ b/deal.II/lac/include/lac/vector.h @@ -1015,6 +1015,49 @@ void Vector::reinit (const unsigned int n, const bool fast) +namespace internal +{ + namespace Vector + { + template + void set_subrange (const T s, + const unsigned int begin, + const unsigned int end, + dealii::Vector &dst) + { + if (s == T()) + memset ((dst.begin()+begin),0,(end-begin)*sizeof(T)); + else + std::fill (&*(dst.begin()+begin), &*(dst.begin()+end), s); + } + + template + void copy_subrange (const dealii::Vector&src, + const unsigned int begin, + const unsigned int end, + dealii::Vector &dst) + { + memcpy(&*(dst.begin()+begin), &*(src.begin()+begin), + (end-begin)*sizeof(T)); + } + + template + void copy_subrange_ext (const dealii::Vector&src, + const unsigned int begin, + const unsigned int end, + dealii::Vector &dst) + { + const T* q = src.begin()+begin; + const T* const end_q = src.begin()+end; + U* p = dst.begin()+begin; + for (; q!=end_q; ++q, ++p) + *p = *q; + } + } +} + + + template inline Vector & Vector::operator = (const Number s) @@ -1025,10 +1068,70 @@ Vector & Vector::operator = (const Number s) if (s != Number()) Assert (vec_size!=0, ExcEmptyObject()); if (vec_size!=0) - parallel::apply_to_subranges (begin(), end(), - std_cxx1x::bind(&std::fill, - _1, _2, s), + parallel::apply_to_subranges (0U, size(), + std_cxx1x::bind(&internal::Vector::template + set_subrange, + s, _1, _2, std_cxx1x::ref(*this)), + internal::Vector::minimum_parallel_grain_size); + + return *this; +} + + + +template <> +inline +Vector > & Vector >::operator = (const std::complex s) +{ + Assert (numbers::is_finite(s), + ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)")); + + if (s != std::complex()) + Assert (vec_size!=0, ExcEmptyObject()); + if (vec_size!=0) + std::fill (begin(), end(), s); + + return *this; +} + + + +template +inline +Vector & +Vector::operator = (const Vector& v) +{ + if (v.vec_size != vec_size) + reinit (v.vec_size, true); + if (vec_size!=0) + parallel::apply_to_subranges (0U, size(), + std_cxx1x::bind(&internal::Vector::template + copy_subrange, + std_cxx1x::cref(v), _1, _2, + std_cxx1x::ref(*this)), + internal::Vector::minimum_parallel_grain_size); + + return *this; +} + + + +template +template +inline +Vector & +Vector::operator = (const Vector& v) +{ + if (v.size() != vec_size) + reinit (v.size(), true); + if (vec_size!=0) + parallel::apply_to_subranges (0U, size(), + std_cxx1x::bind(&internal::Vector::template + copy_subrange_ext, + std_cxx1x::cref(v), _1, _2, + std_cxx1x::ref(*this)), internal::Vector::minimum_parallel_grain_size); + return *this; } diff --git a/deal.II/lac/include/lac/vector.templates.h b/deal.II/lac/include/lac/vector.templates.h index 6aafe6bc39..c1d9f089ee 100644 --- a/deal.II/lac/include/lac/vector.templates.h +++ b/deal.II/lac/include/lac/vector.templates.h @@ -666,39 +666,6 @@ void Vector::ratio (const Vector &a, -template -Vector & -Vector::operator = (const Vector& v) -{ - if (v.vec_size != vec_size) - reinit (v.vec_size, true); - if (vec_size!=0) - parallel::transform (v.val, - v.val+v.vec_size, - val, - (boost::lambda::_1), - internal::Vector::minimum_parallel_grain_size); - - return *this; -} - - - -template -template -Vector & -Vector::operator = (const Vector& v) -{ - if (v.size() != vec_size) - reinit (v.size(), true); - if (vec_size!=0) - std::copy (v.begin(), v.end(), begin()); - - return *this; -} - - - template Vector & Vector::operator = (const BlockVector& v) diff --git a/deal.II/lac/source/vector.cc b/deal.II/lac/source/vector.cc index 39607ff73a..0ce029e10f 100644 --- a/deal.II/lac/source/vector.cc +++ b/deal.II/lac/source/vector.cc @@ -52,10 +52,6 @@ TEMPL_COPY_CONSTRUCTOR(std::complex,std::complex); #define TEMPL_OP_EQ(S1,S2) \ - template \ - Vector& \ - Vector::DEAL_II_MEMBER_OP_TEMPLATE_INST \ - operator=(const Vector&); \ template void Vector::scale (const Vector&); \ template void Vector::equ (const S1, const Vector&)