2. Compiling and Running OpenMP Programs
3. Implementation-Defined Behaviors
6. Automatic Scoping of Variables
6.1 The Autoscoping Data Scope Clause
6.2 Scoping Rules for a Parallel Construct
6.2.1 Scoping Rules For Scalar Variables
6.2.2 Scoping Rules for Arrays
6.4 General Comments About Autoscoping
6.6 Checking the Results of Autoscoping
Under automatic scoping, the compiler applies the following rules to determine the scope of a variable in a task construct.
These rules do not apply to variables scoped implicitly by the OpenMP specification, such as loop index variables of PARALLEL DO/for loops.
When autoscoping a scalar variable that is referenced in a task construct and that does not have predetermined or implicitly determined scope, the compiler checks the use of the variable against the following rules TS1-TS5 in the given order.
TS1: If the use of the variable is read-only in the task construct, and read-only in the parallel construct in which the task construct is enclosed, then the variable is autoscoped as FIRSTPRIVATE.
TS2: If the use of the variable is free of data race, and the variable will be accessible while the task is executing, then the variable is autoscoped as SHARED.
TS3: If the use of the variable is free of data race, and is read-only in the task construct, and the variable may not be accessible while the task is executing, then the variable is autoscoped as FIRSTPRIVATE.
TS4: If the use of the variable is not free of data race, and in each thread executing the task region, the variable is always written before being read by the same thread, then the variable is autoscoped as PRIVATE.
TS5: If the use of variable is not free of data race, and is not read-only in task region, and some read in the task region might get the value defined outside the task, then the variable is autoscoped as FIRSTPRIVATE.
Autoscoping for tasks does not handle arrays.