JavaScript is required to for searching.
Skip Navigation Links
Exit Print View
Oracle Solaris Studio 12.2: OpenMP API User's Guide
search filter icon
search icon

Document Information

Preface

1.  Introducing the OpenMP API

2.  Compiling and Running OpenMP Programs

3.  Implementation-Defined Behaviors

4.  Nested Parallelism

5.  Tasking

5.1 The Tasking Model

5.2 Data Environment

5.3 TASKWAIT Directive

5.4 Tasking Example

5.5 Programming Considerations

5.5.1 THREADPRIVATE and Thread-Specific Information

5.5.2 Locks

5.5.3 References to Stack Data

6.  Automatic Scoping of Variables

7.  Scope Checking

8.  Performance Considerations

A.  Placement of Clauses on Directives

B.  Converting to OpenMP

Index

5.1 The Tasking Model

OpenMP specification version 3.0 introduced a new feature called tasking. Tasking facilitates the parallelization of applications where units of work are generated dynamically, as in recursive structures or while loops.

In OpenMP, an explicit task is specified using the task directive. The task directive defines the code associated with the task and its data environment. The task construct can be placed anywhere in the program; whenever a thread encounters a task construct, a new task is generated.

When a thread encounters a task construct, it may choose to execute the task immediately or defer its execution until a later time. If task execution is deferred, then the task in placed in a conceptual pool of tasks that is associated with the current parallel region. The threads in the current team will take tasks out of the pool and execute them until the pool is empty. A thread that executes a task may be different from the thread that originally encountered it.

The code associated with a task construct will be executed only once. A task is tied if the code is executed by the same thread from beginning to end. A task is untied if the code can be executed by more than one thread, so that different threads execute different parts of the code. By default, tasks are tied, and a task can be specified to be untied by using the untied clause with the task directive.

Threads are allowed to suspend execution of a task region at a task scheduling point in order to execute a different task. If the suspended task is tied, then the same thread later resumes execution of the suspended task. If the suspended task is untied, then any thread in the current team may resume the task execution.

The OpenMP specification defines the following task scheduling points for tied tasks:

As implemented in the Solaris Studio compilers, the above scheduling points are also the task scheduling points for untied tasks.

In addition to explicit tasks specified using the task directive, the OpenMP specification version 3.0 introduces the notion of implicit tasks. An implicit task is a task generated by the implicit parallel region, or generated when a parallel construct is encountered during execution. The code for each implicit task is the code inside the parallel construct. Each implicit task is assigned to a different thread in the team and is tied; that is, an implicit task is always executed from beginning to end by the thread to which it is initially assigned.

All implicit tasks generated when a parallel construct is encountered are guaranteed to be complete when the master thread exits the implicit barrier at the end of the parallel region. On the other hand, all explicit tasks generated within a parallel region are guaranteed to be complete on exit from the next implicit or explicit barrier within the parallel region.

When an if clause is present on a task construct and the value of the scalar-expression evaluates to false, the thread that encounters the task must immediately execute the task. The if clause can be used to avoid the overhead of generating many finely grained tasks and placing them in the conceptual pool.