views:

79

answers:

1

To loop over elements of a container, I would typically use an iterator, like so:

container<type> myContainer;
// fill up the container
container<type>::iterator it;
for(it=myContainer.begin(); it!=myContainer.end(); ++it) {
   //do stuff to the elements of the container
}

Now, if I want to parallelize the loop using OpenMP, I might try something like:

container<type> myContainer;
// fill up the container
container<type>::iterator it, it_begin=myContainer.begin(), it_end=myContainer.end();
#pragma omp parallel for default(none) private(it) shared(it_begin, it_end)
for(it=it_begin; it!=it_end; ++it) {
   //do stuff to the elements of the container
}

However, when I run said code, the changes are not made to the container. If, however, I use a typical indexing on the container, the parallel code works fine. What I am wondering is if it is possible to use iterators in the context of OpenMP, or if I need to convert the iterated loop to an indexed loop?

+1  A: 

Parallelization for STL iterators is allowed only in OpenMP 3.0. Which version of OpenMP does your compiler supports?

Kirill V. Lyadvinsky
Thanks Kirill. It looks my compiler uses OpenMP 2.5, so that would explain it.
MarkD