I'm trying to parallelize a chunk of code where a struct operates on an array of elements
for (int i=0; i < elements.size(); i++)
This code works fine unparallelized. When parallelized by adding the following pragma to the for loop, the results are incorrect.
#pragma omp parallel for firstprivate(fdv)
Now my understanding is that firstprivate is to make exact copies of the data structure, fdv, and send it to each worker thread, correct?
If I move the declaration of fdv inside the loop (and remove the "firstprivate(fdv)"), the code parallelized functions correctly, but due to the overhead in allocating fdv, I'd like to just do it up front before entering the loop. Any clues?