C++
C#
VB
JScript
All

External Function parallel_for


Copyright (C) 2005 IENT-RWTH Aachen

template<class RanIt,class F> void parallel_for(RanIt begin,RanIt end,const F &f,int grain)
template<class G,class F> void parallel_for(const Vector<G> &X, const F &f,int grain)
template<class G,class F> void parallel_for(const Vector<G> &X, const F &f)
template<class G,class F> void parallel_for(const Matrix<G> &X, const F &f,int grain)
template<class G,class F> void parallel_for(const Matrix<G> &X, const F &f)

Computes parallel iteration of a function over a range of values

Parameters

begin

Integer or random access iterator addressing the position of the first element in the range to be operated on.

end

Integer or random access iterator addressing the position one past the final element in the range operated on.

grain

Number of iteration for a reasonable chunk to deal out to a thread. If no value given, the range is subdivided in num_threads() chunks.

X

Range to be operated on.

f

User-defined function object that is applied on subranges.

Remarks

The function object must model the following requirements:

Copy constructor F::F(const F &)
Destructor F::~F(const F &)
Apply on subranges template<class RanIt> F::operator()(RanIt,RanIt) const

Example

template<class V>
struct fill_function
{
  V val;
  fill_function(const V &v) : val(v) {}
  template<class It> void operator()(It begin, It end) const { fill(begin,end,val); }
};

template<class RanIt,class T>
void parallel_fill(RanIt begin, RanIt end, const T &val, int grain=10000)
{
  gmt::parallel_for(X.begin(),X.end(), fill_function<T>(val),grain);
}

See Also

parallel_copy, parallel_reduce