The tasking model implemented by the Intel® compiler enables OpenMP* to parallelize a large range of applications. The directives used for tasking are:
TASK and END TASK
TASKWAIT
The TASK and END TASK directives define an explicit task region as follows:
Example |
---|
!$OMP TASK ! explicit task region !$OMP END TASK |
The binding thread set of the task region is the current parallel team. A task region binds to the innermost enclosing PARALLEL region. When a thread encounters a task construct, a task is generated from the structured block enclosed in the construct. The encountering thread may immediately execute the task, or defer its execution. 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 directive takes an optional comma-separated list of clauses. The data environment of the task is created according to the data-sharing attribute clauses on the task construct and any defaults that apply. These clauses are:
IF: whether the task has to be executed immediately or can be deferred.
UNTIED: whether any thread in the team may resume a suspended task
PRIVATE, FIRSTPRIVATE, or SHARED: variable types
DEFAULT: variable data scope attribute
This example shows a way to generate N tasks with one thread and execute them with the threads in the parallel team:
Example |
---|
!$OMP PARALLEL SHARED(DATA) !$OMP SINGLE PRIVATE (I) DO I = 1, N !$OMP TASK FIRSTPRIVATE(I), SHARED(DATA) CALL WORK(DATA(I)) !$OMP END TASK END DO !$OMP END SINGLE !$OMP END PARALLEL |