Under automatic scoping, the compiler applies the following rules to determine the scope of a variable in a parallel construct.
These rules do not apply to variables scoped implicitly by the OpenMP specification, such as loop index variables of worksharing DO or FOR loops.
When autoscoping a scalar variable that is referenced in a parallel construct and that does not have predetermined or implicitly determined scope, the compiler checks the use of the variable against the following rules PS1-PS3 in the given order.
PS1: If the use of the variable in the parallel region is free of data race conditions for the threads in the team executing the region, then the variable is scoped SHARED.
PS2: If in each thread executing the parallel region, the variable is always written before being read by the same thread, then the variable is scoped PRIVATE. The variable is scoped as LASTPRIVATE if it can be scoped PRIVATE and is read before it is written after the parallel region, and the construct is either a PARALLEL DO or a PARALLEL SECTIONS.
PS3: If the variable is used in a reduction operation that can be recognized by the compiler, then the variable is scoped REDUCTION with that particular operation type.
PA1: If the use of the array in the parallel region is free of data race conditions for the threads in the team executing the region, then the array is scoped as SHARED.