[Openmp-dev] Private clause behavior outside and inside a function

Churbanov, Andrey Andrey.Churbanov at intel.com
Tue Sep 30 01:39:27 PDT 2014

Hi Simone,

According to the OpenMP specification it is unspecified whether "c" in the function references local or global object.  This may depend on compiler, its optimizations, etc.  For example, if the function test() is inlined you can easily see reference to local object, if the function is outlined then most probably the global object will be referenced in it.

Also your code fragment has couple of issues (those could be caused by incompleteness of the fragment and may not exist in the complete code): race condition on shared variable "j" and usage of uninitialized variable "eps".


> -----Original Message-----
> From: openmp-dev-bounces at cs.uiuc.edu [mailto:openmp-dev-
> bounces at cs.uiuc.edu] On Behalf Of Simone Atzeni
> Sent: Monday, September 29, 2014 9:07 PM
> To: openmp-dev at dcs-maillist2.engr.illinois.edu
> Subject: [Openmp-dev] Private clause behavior outside and inside a function
> Hi all,
> I have a OpenMP code like the following:
> --------------------------------------------------------------------------------
> "c" is global
> #pragma omp parallel for default(shared) private(c,eps)
>   for (i=0; i<N; i++) {
>     for (j=0; j<N; j++) {
>       cr = -2.0+2.5*(double)(i)/(double)(N)+eps;
>       c.i = 1.125*(double)(j)/(double)(NPOINTS)+eps;
>       test();
>     }
>   }
> and "test" is a function that read the values in "c".
> --------------------------------------------------------------------------------
> The "c" inside the for loop and inside the function are the same?
> Or that one in the for loop is local (because of the private clause) and that one
> within the function is global?
> Thanks.
> Best,
> Simone
> _______________________________________________
> Openmp-dev mailing list
> Openmp-dev at dcs-maillist2.engr.illinois.edu
> http://lists.cs.uiuc.edu/mailman/listinfo/openmp-dev

Closed Joint Stock Company Intel A/O
Registered legal address: Krylatsky Hills Business Park, 
17 Krylatskaya Str., Bldg 4, Moscow 121614, 
Russian Federation

This e-mail and any attachments may contain confidential material for
the sole use of the intended recipient(s). Any review or distribution
by others is strictly prohibited. If you are not the intended
recipient, please contact the sender and delete all copies.

More information about the Openmp-dev mailing list