where event-handle is an integer variable of omp_event_handle_kindkind.
BindingThe binding thread set of the task region is the current team. A task region binds to the
innermost enclosing parallel region.
Description
The task construct is a task generating construct. When a thread encounters a task construct, an explicit
task is generated from the code for the associated structured-block. The data environment of the task is
created according to the data-sharing attribute clauses on the task construct, per-data environment ICVs,
and any defaults that apply. The data environment of the task is destroyed when the execution code of the
associated structured-block is completed.
The encountering thread may immediately execute the task, or defer its execution. In the latter case, any
thread in the team may be assigned the task. Completion of the task can be guaranteed using task
synchronization constructs. If a task construct is encountered during execution of an outer task, the
generated task region corresponding to this construct is not a part of the outer task region unless the
generated task is an included task.
If a detach clause is present on a task construct a new event allow-completion-event is created. The
allow-completion-event is connected to the completion of the associated task region. The original
event-handle will be updated to represent the allow-completion-event event before the task data environment
is created. The event-handle will be considered as if it was specified on a firstprivate clause. The use
of a variable in a detach clause expression of a task construct causes an implicit reference to the
variable in all enclosing constructs.
If no detach clause is present on a task construct the generated task is completed when the execution
of its associated structured-block is completed. If a detach clause is present on a task construct the
task is completed when the execution of its associated structured-block is completed and the
allow-completion-event is fulfilled.
When an if clause is present on a task construct, and the if clause expression evaluates to false, an
undeferred task is generated, and the encountering thread must suspend the current task region, for which
execution cannot be resumed until execution of the structured block that is associated with the generated
task is completed. The use of a variable in an if clause expression of a task construct causes an implicit
reference to the variable in all enclosing constructs.
When a final clause is present on a task construct and the final clause expression evaluates to true,
the generated task will be a final task. All task constructs encountered during execution of a final task will
generate final and included tasks. The use of a variable in a final clause expression of a task construct
causes an implicit reference to the variable in all enclosing constructs. Encountering a task
construct with the detach clause during the execution of a final task results in unspecified
behavior.
The if clause expression and the final clause expression are evaluated in the context outside of the
task construct, and no ordering of those evaluations is specified..
A thread that encounters a task scheduling point within the task region may temporarily suspend the
task region. By default, a task is tied and its suspended task region can only be resumed by the thread
that started its execution. If the untied clause is present on a task construct, any thread in the team can
resume the task region after a suspension. The untied clause is ignored if a final clause is present on
the same task construct and the final clause expression evaluates to true, or if a task is an included
task.
The task construct includes a task scheduling point in the task region of its generating task, immediately
following the generation of the explicit task. Each explicit task region includes a task scheduling point at
the end of its associated structured-block.
When the mergeable clause is present on a task construct, the generated task is a mergeable
task.
The priority clause is a hint for the priority of the generated task. The priority-value is a non-negative
integer expression that provides a hint for task execution order. Among all tasks ready to be executed, higher
priority tasks (those with a higher numerical value in the priority clause expression) are recommended
to execute before lower priority ones. The default priority-value when no priority clause is specified is
zero (the lowest priority). If a value is specified in the priority clause that is higher than the
max-task-priority-var ICV then the implementation will use the value of that ICV. A program that
relies on task execution order being determined by this priority-value may have unspecified
behavior.
The affinity clause is a hint to indicate data affinity of the generated task. The task is recommended to
execute closely to the location of the list items. A program that relies on the task execution location being
determined by this list may have unspecified behavior.
The list items that appear in the affinity clause may reference iterators defined by an iterators-definition
appearing in the same clause. The list items that appear in the affinity clause may include array
sections.
The list items that appear in the affinity clause may use shape-operators.
If a list item appears in an affinity clause then data affinity refers to the original list item.
Note – When storage is shared by an explicit task region, the programmer must ensure, by adding proper
synchronization, that the storage does not reach the end of its lifetime before the explicit task region completes
its execution.
Execution Model Events
The task-create event occurs when a thread encounters a construct that causes a new task to be created. The
event occurs after the task is initialized but before it begins execution or is deferred.
Tool Callbacks
A thread dispatches a registered ompt_callback_task_create callback for each occurrence of a
task-create event in the context of the encountering task. This callback has the type signature
ompt_callback_task_create_t and the flags argument indicates the task types shown in
Table 2.7.
RestrictionsRestrictions to the task construct are as follows:
A
program
that
branches
into
or
out
of
a
task
region
is
non-conforming.
A
program
must
not
depend
on
any
ordering
of
the
evaluations
of
the
clauses
of
the
task
directive,
or
on
any
side
effects
of
the
evaluations
of
the
clauses.
At
most
one
if
clause
can
appear
on
the
directive.
At
most
one
final
clause
can
appear
on
the
directive.
At
most
one
priority
clause
can
appear
on
the
directive.
At
most
one
detach
clause
can
appear
on
the
directive.
If
a
detach
clause
appears
on
the
directive,
then
a
mergeable
clause
cannot
appear
on
the
same
directive.
∙ A throw executed inside a task region must cause execution to resume within the same task region,
and the same thread that threw the exception must catch it.
Cross References
Task
scheduling
constraints,
see
Section 2.10.6
on
page 415.