I'm trying to iterate over a map in c++ using openMP, but I got three error messages saying
that the initialization, termination and increment of my loop has improper form and I'm quite new in using openmp, so is there any way to get around this problem while getting the same results as the serial ones? the following is the code I used
map< int,string >::iterator datIt;
#pragma omp parallel for
for(datIt=dat.begin();datIt!=dat.end();datIt++) //construct the distance matrix
{
...............
}
It could be done also by using a simple index based for loop clubbed with std::advance
to reach to a particular map element. OpenMP 2.0 supports index based for loops very well.
#pragma omp parallel for
for(int i = 0; i < dat.size(); i++) {
auto datIt = dat.begin();
advance(datIt, i);
//construct the distance matrix using iterator datIt
}
In each thread the iterator datIt
will point to a map item and can be used to perform operations on it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With