tags:

views:

34

answers:

1

Hi,

I have a scenario like the following:

//class somemethod contains the member variables(declaration) val1 and val2, 
//and is defined in somemethod.h.

#include <somemethod.h>

void abovefunction(x)
{
//code that could be made parallel if val1 and val2 is declared private()
}
//abovefunction() is in somemethod.cpp, where the methods of class somemethod
//are described

The function is later called by some object like obj.abovefunction(x). Since val1 and val2 are declared/initialized in somemethod.h, so I cannot use them as private (val1, val2), and something like private (this->val1, this->val2) is also not possible. Can anyone please let me know the best way to parallelize using OpenMP in cases like this where the variable is a part of class and declared not in the immediate scope of the code block where OpenMP pragmas are applied ?

I have asked the same question on the OpenMP forum - http://openmp.org/forum/viewtopic.php?f=3&amp;t=886#p3516

Thanks,
Sayan

A: 

If I'm not mistaken, when you declare a variable private(var) all it does is create new space for that variable, and it doesn't actually copy the value that it entered the private(var) statement.

This being said, if you could suffice to use the private(var) statement, could you not locally initialize the variable in the somemethod::abovefunction(x) call?

Brett
I moved abovefunction to somemethod.h, so that I could access the variables. Thanks.
Sayan
And thanks to a member of the OpenMP.org forum for reminding me that static members could be declared as threadprivate.
Sayan