Parallelization Error (for loop with a struct)

General OpenMP discussion

Parallelization Error (for loop with a struct)

Postby philski » Tue Sep 09, 2008 10:44 am

Good Afternoon,

I'm trying to parallelize a chunk of code where a struct operates on an array of elements

Structure fdv;

for (int i=0; i < elements.size(); i++)
{
fdv(elements[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?

Thanks,

Philip
philski
 
Posts: 1
Joined: Mon Apr 28, 2008 8:41 am

Re: Parallelization Error (for loop with a struct)

Postby ejd » Tue Sep 09, 2008 3:58 pm

You haven't given me much to go on. Is this C or C++ code? What compiler are you using? What does the structure fdv look like? Have you checked to see that the firstprivate copies of fdv are "initialized" correctly?
ejd
 
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am


Return to Using OpenMP

Who is online

Users browsing this forum: Google [Bot] and 2 guests