Intel® C++ Compiler XE 13.1 User and Reference Guides
Defines a task region.
#pragma omp task [clause[[,]clause]...] |
block
clause |
clause can be any of the following:
|
||||||||||||||||
block |
Is a structured block of statements or constructs. You cannot branch into or out of the block. |
When a thread encounters a task construct, a task is generated from the code for the associated structured block. 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.
A thread that encounters a task scheduling point within the task region may temporarily suspend the task region. By default, a task is then tied and its suspended task region can only be resumed by the thread that started its execution. However, if the untied clause is specified in a task construct, any thread in the team can resume the task region after a suspension. The untied clause is ignored in following cases:
A task construct may be nested inside an outer task, but the task region of the inner task is not a part of the task region of the outer 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 its point of completion. An implementation may add task scheduling points anywhere in untied task regions.
Note that when storage is shared by an explicit task region, you must add proper synchronization to ensure that the storage does not reach the end of its lifetime before the explicit task region completes its execution.
A program must not depend on any ordering of the evaluations of the clauses of the task pragma and it must not depend on any side effects of the evaluations of the clauses. A program that branches into or out of a task region is non-conforming.
Unsynchronized use of C++ I/O statements by multiple tasks on the same unit has unspecified behavior.
struct node {
struct node *left;
struct node *right;
};
extern void process(struct node *);
int depth, limit;
void traverse( struct node *p ) {
// When depth>limit, stop generating new tasks, and allow the
// compiler to avoid creating a new data environment.
if (p->left)
#pragma omp task final(depth>limit) mergeable
// p is firstprivate by default
traverse(p->left);
if (p->right)
#pragma omp task final(depth>limit) mergeable
// p is firstprivate by default
traverse(p->right);
process(p);
}