#include <base/config.h>
#include <base/exceptions.h>
+#include <base/parallel.h>
#include <base/subscriptor.h>
+#include <boost/lambda/lambda.hpp>
#include <cstdio>
*/
Vector<Number> & operator /= (const Number factor);
+ /**
+ * Scale each element of this
+ * vector by the corresponding
+ * element in the argument. This
+ * function is mostly meant to
+ * simulate multiplication (and
+ * immediate re-assignment) by a
+ * diagonal scaling matrix.
+ */
+ void scale (const Vector<Number> &scaling_factors);
+
/**
* Scale each element of this
* vector by the corresponding
*/
template <typename Number2>
void scale (const Vector<Number2> &scaling_factors);
-
+
+ /**
+ * Assignment <tt>*this = a*u</tt>.
+ */
+ void equ (const Number a, const Vector<Number>& u);
+
/**
* Assignment <tt>*this = a*u</tt>.
*/
if (s != Number())
Assert (vec_size!=0, ExcEmptyObject());
if (vec_size!=0)
- std::fill (begin(), end(), s);
+ parallel::apply_to_subranges (begin(), end(),
+ std_cxx1x::bind(&std::fill<Number*,Number>,
+ _1, _2, s),
+ internal::Vector::minimum_parallel_grain_size);
return *this;
}
Assert (vec_size!=0, ExcEmptyObject());
- iterator ptr = begin();
- const const_iterator eptr = end();
- while (ptr!=eptr)
- *ptr++ *= factor;
+ parallel::transform (val,
+ val+vec_size,
+ val,
+ (factor*boost::lambda::_1),
+ internal::Vector::minimum_parallel_grain_size);
}
Assert (vec_size!=0, ExcEmptyObject());
Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
- iterator i_ptr = begin(),
- i_end = end();
- const_iterator v_ptr = v.begin();
- while (i_ptr!=i_end)
- *i_ptr++ += a * *v_ptr++;
+ parallel::transform (val,
+ val+vec_size,
+ v.val,
+ val,
+ (boost::lambda::_1 + a*boost::lambda::_2),
+ internal::Vector::minimum_parallel_grain_size);
}
Assert (vec_size!=0, ExcEmptyObject());
Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
- iterator i_ptr = begin(),
- i_end = end();
- const_iterator v_ptr = v.begin();
- for (; i_ptr!=i_end; ++i_ptr)
- *i_ptr = x * *i_ptr + a * *v_ptr++;
+
+ parallel::transform (val,
+ val+vec_size,
+ v.val,
+ val,
+ (x*boost::lambda::_1 + a*boost::lambda::_2),
+ internal::Vector::minimum_parallel_grain_size);
}
#include <base/template_constraints.h>
#include <base/numbers.h>
-#include <base/parallel.h>
#include <lac/vector.h>
#include <lac/block_vector.h>
# include <lac/trilinos_vector.h>
#endif
-#include <boost/lambda/lambda.hpp>
-
#include <cmath>
#include <cstring>
#include <algorithm>
const Vector<Number>& w, const Number c,
const Vector<Number>& y)
{
- Assert (numbers::is_finite(x),
- ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(a),
- ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(b),
- ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
- Assert (numbers::is_finite(c),
- ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
+ sadd (x, a, v, b, w);
+ add (c, y);
+}
+
+
+template <typename Number>
+void Vector<Number>::scale (const Vector<Number> &s)
+{
Assert (vec_size!=0, ExcEmptyObject());
- Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
- Assert (vec_size == w.vec_size, ExcDimensionMismatch(vec_size, w.vec_size));
- Assert (vec_size == y.vec_size, ExcDimensionMismatch(vec_size, y.vec_size));
+ Assert (vec_size == s.vec_size, ExcDimensionMismatch(vec_size, s.vec_size));
- for (unsigned int i=0; i<vec_size; ++i)
- val[i] = x*val[i] + a*v.val[i] + b*w.val[i] +c*y.val[i];
+ parallel::transform (val,
+ val+vec_size,
+ s.val,
+ val,
+ (boost::lambda::_1*boost::lambda::_2),
+ internal::Vector::minimum_parallel_grain_size);
}
{
Assert (vec_size!=0, ExcEmptyObject());
Assert (vec_size == s.vec_size, ExcDimensionMismatch(vec_size, s.vec_size));
-
+
for (unsigned int i=0; i<vec_size; ++i)
val[i] *= s.val[i];
}
+
+template <typename Number>
+void Vector<Number>::equ (const Number a,
+ const Vector<Number>& u)
+{
+ Assert (numbers::is_finite(a),
+ ExcMessage("The given value is not finite but either infinite or Not A Number (NaN)"));
+
+ Assert (vec_size!=0, ExcEmptyObject());
+ Assert (vec_size == u.vec_size, ExcDimensionMismatch(vec_size, u.vec_size));
+
+ parallel::transform (u.val,
+ u.val+u.vec_size,
+ val,
+ (a*boost::lambda::_1),
+ internal::Vector::minimum_parallel_grain_size);
+}
+
+
+
template <typename Number>
template <typename Number2>
void Vector<Number>::equ (const Number a,
}
+
template <typename Number>
void Vector<Number>::equ (const Number a, const Vector<Number>& u,
const Number b, const Vector<Number>& v)
Assert (vec_size == u.vec_size, ExcDimensionMismatch(vec_size, u.vec_size));
Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
- for (unsigned int i=0; i<vec_size; ++i)
- val[i] = a * u.val[i] + b * v.val[i];
-}
+ parallel::transform (u.val,
+ u.val+u.vec_size,
+ v.val,
+ val,
+ (a*boost::lambda::_1 + b*boost::lambda::_2),
+ internal::Vector::minimum_parallel_grain_size);
+ }
template <typename Number>
Assert (vec_size == v.vec_size, ExcDimensionMismatch(vec_size, v.vec_size));
Assert (vec_size == w.vec_size, ExcDimensionMismatch(vec_size, w.vec_size));
- for (unsigned int i=0; i<vec_size; ++i)
- val[i] = a * u.val[i] + b * v.val[i] + c * w.val[i];
+ parallel::transform (u.val,
+ u.val+u.vec_size,
+ v.val,
+ w.val,
+ val,
+ (a*boost::lambda::_1 + b*boost::lambda::_2 + c*boost::lambda::_3),
+ internal::Vector::minimum_parallel_grain_size);
}
// we overwrite them anyway
reinit (a.size(), true);
- for (unsigned int i=0; i<vec_size; ++i)
- val[i] = a.val[i] / b.val[i];
+ parallel::transform (a.val,
+ a.val+a.vec_size,
+ b.val,
+ val,
+ (boost::lambda::_1 / boost::lambda::_2),
+ internal::Vector::minimum_parallel_grain_size);
}
if (v.vec_size != vec_size)
reinit (v.vec_size, true);
if (vec_size!=0)
- std::copy (v.begin(), v.end(), begin());
+ parallel::transform (v.val,
+ v.val+v.vec_size,
+ val,
+ (boost::lambda::_1),
+ internal::Vector::minimum_parallel_grain_size);
return *this;
}