#pragma omp task
Purpose
The task pragma can be used to explicitly define a task.
Use the task pragma when you want to identify a block of code to be executed in parallel with the code outside the task region. The task pragma can be useful for parallelizing irregular algorithms such as pointer chasing or recursive algorithms. The task directive takes effect only if you specify the -qsmp compiler option.
Parameters
- default (shared | none)
- Defines the default data scope of variable in each task. Only
one default clause can be specified on an omp
task directive.
Specifying default(shared) is equivalent to stating each variable in a shared(list) clause.
Specifying default(none) requires that each data variable visible to the construct must be explicitly listed in a data scope clause, with the exception of variables with the following attributes:- Threadprivate
- Automatic and declared in a scope inside the construct
- Objects with dynamic storage duration
- Static data members
- The loop iteration variables in the associated for-loops for a work-sharing for or parallel for construct
- Static and declared in a scope inside the construct
- depend(dependence-type:list)
- Establishes scheduling dependences between sibling tasks that
share list items. The dependence-type can be in, out,
or inout. Data variables in list are separated by commas.
- If dependence-type is in or inout, for each list item that has the same storage location as a list item in a depend clause of a sibling task with the out or inout dependence type, a scheduling dependence for the generated task on the sibling task is created.
- If dependence-type is out or inout, for each list item that has the same storage location as a list item in a depend clause of a sibling task with the in, out, or inout dependence type, a scheduling dependence for the generated task on the sibling task is created.
- final (exp)
- If you specify a final clause and exp evaluates
to a nonzero value, the generated task is a final task.
All task constructs encountered inside a final task create final
and included
tasks.
You can specify only one final clause on the task pragma.
- firstprivate (list)
- Declares the scope of the data variables in list to be private to each thread. Each new private object is initialized with the value of the original variable as if there was an implied declaration within the statement block. Data variables in list are separated by commas.
- if (exp)
- When the if clause is specified, an undeferred task is generated if the scalar expression exp evaluates to a nonzero value. Only one if clause can be specified.
- mergeable
- If you specify a mergeable clause and the generated task is an undeferred task or included task, a merged task might be generated.
- private (list)
- Declares the scope of the data variables in list to be private to each thread. Data variables in list are separated by commas.
- shared (list)
- Declares the scope of the comma-separated data variables in list to be shared across all threads.
- untied
- When a task region is suspended, untied tasks can be resumed by
any thread in a team. The untied clause on a
task construct is ignored if either of the following conditions is
a nonzero value:
- A final clause is specified on the same task construct and the final clause expression evaluates to a nonzero value.
- The task is an included task.
Usage
- A final clause is specified on a task construct and the final clause expression evaluates to nonzero value.
- The generated task is a child task of a final task.
An undeferred task is a task whose execution is not deferred with respect to its generating task region. In other words, the generating task region is suspended until the undeferred task has finished running. An undeferred task is generated when an if clause is specified on a task construct and the if clause expression evaluates to zero.
An included task is a task whose execution is sequentially included in the generating task region. In other words, an included task is undeferred and executed immediately by the encountering thread. An included task is generated when the generated task is a child task of a final task.
- A mergeable clause is specified on a task construct.
- The generated task is an undeferred task or an included task.
The if clause expression and the final clause expression are evaluated outside of the task construct, and the evaluation order is not specified.