private copy within a thread

General OpenMP discussion

private copy within a thread

Postby flashpixx » Wed Nov 16, 2011 6:40 am

Hello,

I'm using a reference in C++, that should use like a "private copy" within the thread:

Code: Select all
void method( fitnessclass& p_fitness )
{
#pragma omp parallel threadprivate(p_fitness) copyin(p_fitness)
{
}
}


I try to create the p_fitness private in each thread and the p_fitness variable has the value before the pragma
code will be run. I have tried it with private, theadprivate, firstprivate... but on each I get the error:
#pragma omp' clause before

Is the "private" call a seperate call, so I need two pragmas? I would like to create a copy of my p_fitness
for each thread, the thread-local p_fitness object should have the same values like the object before
the thread is running (I think copyin should be the correct option). After the threads are finished
the local objects can be removed, so no copy-back is needed

How can I do this?

edit: I have change the code to:
Code: Select all
            #pragma omp parallel for firstprivate(p_fitness) shared(l_optimumreached)
            for(std::size_t i=0; (i < vector.size()) && (!l_optimumreached); ++i) {


NOw the error is: 'p_fitness' has reference type for 'firstprivate'

p_fitness is a reference type of an abstract class (here named fitness&) so I need the reference to get the
correct object. Is there an solution to get a reference into the firstprivate?

Thanks

Phil
flashpixx
 
Posts: 6
Joined: Tue Nov 15, 2011 10:18 am

Return to Using OpenMP

Who is online

Users browsing this forum: No registered users and 10 guests