Go to main content
Oracle® Developer Studio 12.6: OpenMP API User's Guide

Exit Print View

Updated: June 2017
 
 

6.3 Scoping Rules for a parallel Construct

When doing automatic scoping, the compiler applies the rules described in this section 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 for/do loops.

6.3.1 Scoping Rules for Scalar Variables in a parallel Construct

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 construct is free of data race conditions for the threads in the team executing the construct, then the variable is scoped as shared.

  • PS2: If in each thread executing the parallel construct the variable is always written before being read by the same thread, then the variable is scoped as private. The variable is scoped as lastprivate if it can be scoped private and it is read before it is written after the parallel construct, and the construct is either a parallel for/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 as reduction with that particular operation type.

6.3.2 Scoping Rule for Arrays in a parallel Construct

  • PA1: If the use of the array in the parallel construct is free of data race conditions for the threads in the team executing the construct, then the array is scoped as shared.