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?