I'm trying to use openmp to multithread a loop through std::set. When I write the following code -
#pragma omp parallel for
for (std::set<A>::const_iterator i = s.begin(); i != s.end(); ++i) {
const A a = *i;
operate(a);
}
I get this error:
error: invalid type for iteration variable 'i'
error: invalid controlling predicate
error: invalid increment expression.
Is there an another, correct way to iterate through std containers using openmp?
I know I can use int i and iterate from 0 to s.size() and an iterator or operator[] in the loop body, but this looks much less clean.
std::for_eachwhich should do the trick for you. Maybe you can also look at the source there? See also algo2.iti.kit.edu/singler/mcstl.