2
Example: Average-Neighbors
OpenMP code (example a1):
• #pragma omp parallel for
for( i=1; i < n; ++i )
  b[i] = (a[i] + a[i-1]) / 2.0;
Concur code:
• active for each( int i in range(1,n) ) {
  b[i] = (a[i] + a[i-1]) / 2.0;
}
•Works also with STL and BCL collections, not just arrays.
•Or use a parallel version of the std::transform algorithm.
• ptransform( a.begin()+1, a.end(), a.begin(), b.begin(), (_1+_2) / 2.0 );

first input range

second
input
range

output
range

how to compute
the output
note: taking explicit advantage of knowing how iterators traverse collections, and which ones are read vs. written

template< class In, class Out, class Op >
OutputIterator pitransform( In first, In last, Out result, Op op) {
  for( ; first < last; ++first, ++out ) active {
    *out = op(first);
  }
}