The task directive takes the following data attribute clauses that define the data environment of the task:
default (private | firstprivate | shared | none)
private (list)
firstprivate (list)
shared (list)
All references within a task to a variable listed in the shared clause refer to the variable with that same name known immediately prior to the task directive.
For each private and firstprivate variable, new storage is created and all references to the original variable in the lexical extent of the task construct are replaced by references to the new storage. A firstprivate variable is initialized with the value of the original variable at the moment the task is encountered.
The data-sharing attributes of variables that are not listed in data attribute clauses of a task construct, and are not predetermined according to the OpenMP rules, are implicitly determined as follows:
(a) In a task construct, if no default clause is present, a variable that is determined to be shared in all enclosing constructs, up to and including the innermost enclosing parallel construct, is shared.
(b) In a task construct, if no default clause is present, a variable whose data-sharing attribute is not determined by rule (a) is firstprivate.
It follows that:
(a) If a task construct is lexically enclosed in a parallel construct, then variables that are shared in all scopes enclosing the task construct remain shared in the generated task. Otherwise, variables are implicitly determined firstprivate.
(b) If a task construct is orphaned, then variables are implicitly determined firstprivate.