Oracle® Solaris Studio 12.4: OpenMP API User's Guide

Exit Print View

Updated: December 2014
 
 

4.1.1 OpenMP Task Execution

In OpenMP, an explicit task is specified using the task construct, which 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 is 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. The thread that executes a task might be different from the thread that originally encountered the task and placed it in the pool.

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

Threads are allowed to suspend the 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.

Task scheduling points are implied at a number of locations, including the following:

  • The point immediately following the generation of an explicit task

  • After the point of completion of a task region

  • In a taskyield region

  • In a taskwait region

  • At the end of a taskgroup region

  • In an implicit and explicit barrier region

In addition to explicit tasks specified using the task construct, the OpenMP specification presents 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. In the latter case, 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.

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.