how to use "private" ?

General OpenMP discussion

Re: how to use "private" ?

Postby ejd » Thu Apr 17, 2008 7:04 am

peter wrote:i will try to post little "pseudo"-code:

myclass * myvar = function(); // this function returns a pointer to a myclass-Object
int i;
int n = 1000;
int z = 2;

#pragma omp parallel for private(i) shared(myvar, n) firstprivate(z) default(shared)
for (i = 1; i <n; i++)
api_function(myvar); // its an api-function from the CAD-API ACIS which reads the myclass-variable

Info: if you now little about the CAD-API ACIS: i use a pointer to a BODY- and a FACE-object

it's sure that the api_function only reads the myclass-variable!!!

I assume there must be something more to this than what you are showing, because calling api_function to do the same thing "n" times doesn't really make any sense to me. In any case, if the api_function is only reading myvar, then this should work IF the api_function is "threadsafe". That is, it may be keeping global information that if accessed by multiple threads will cause a data race. You need to look at the documentation for the CAD-API and see what it says about this issue.
Posts: 1025
Joined: Wed Jan 16, 2008 7:21 am

Re: how to use "private" ?

Postby roosevelt » Thu Apr 17, 2008 7:56 am

thanks very much. I already understand this problem. :D

Re: how to use "private" ?

Postby Guest » Thu Apr 17, 2008 10:07 am


thanks for your example! it helps me alot to understand the private and firstprivate-clause with pointers.

the problem that my program didnt work was a problem that a variable causes a read error
therefore i wondered because i thought that parallel reads are no problem.
now i found out that its not a problem cuased by openmp.
its one problem from the function that i call because the function belongs to an api which is not threadsafe.

thanks for ur help. This board is really a super place to talkabout openmp and to improve my openmp skills.

Re: how to use "private" ?

Postby peter » Thu May 22, 2008 2:04 am


as i see now: i forgot to write my username in my post before.
therefore i want to tell you that the post before was from me.

Re: how to use "private" ?

Postby boost_fan » Sun Aug 03, 2008 10:15 am

I have questions on OpenMP and C++ asked by many people on this thread but I notice the scarcity of any meaningful replies. This could be because not many people use this platform. Perhaps then I should continue using boost threads where there is much help.


Return to Using OpenMP

Who is online

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