Using OpenMP and STL vectors
Hi
I have a program, where I some numbers during a for-loop, as in
Code:
for(int i=0; i<1000000000; i++)
{
if(i%10 == 0) num_vec.push_back(i);
}
I wanted to exploit multithreading, and I thought about using OpenMP. Appending data to the vector is a critical part, I guess, so is it correct for me to parallelize my program as follows?
Code:
#pragma omp parallel for
for(int i=0; i<1000000000; i++)
{
#pragma omp critical
if(i%10 == 0) num_vec.push_back(i);
}
Thanks for help in advance.
Best,
Niles.