Skip main navigation

Tasking model

Tasking model

Tasking allows the parallelization of applications where work units are generated dynamically, as in recursive structures or while loops.

In OpenMP an explicit task is defined using the task directive.

#pragma omp task[clause[[,]clause]...]
structured-block

The task directive defines the code associated with the task and its data
environment. When a thread encounters a task directive, a new task is
generated. The task may be executed immediately or at a later time. If
task execution is delayed, then the task is placed in a conceptual
pool of sleeping tasks that is associated with the current parallel region. The threads in the current teams will take tasks out of the pool and
execute them until the pool is empty. A thread that executes a task
might be different than the one that originally encountered it.

The code associated with the task construct will be executed only
once. A task is named to be tied, if it 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.

We also want to mention that there are several task scheduling points where a task can be put from living into sleeping and back from sleeping to a living state:

  • In the generating task: after the task generates an explicit task, it can be put into a sleeping state.
  • In the generated task: after the last instruction of the task region.
  • If task is untied: everywhere inside the task.
  • In implicit and explicit barriers.
  • In taskwait.

Completion of a task can be guaranteed using task synchronization constructs such as taskwait directive. The taskwait construct specifies a wait on the completion of child tasks of the current task. The taskwait construct is a stand-alone directive.

#pragma omp taskwait [clause[ [,] clause] ... ]
This article is from the free online

Introduction to Parallel Programming

Created by
FutureLearn - Learning For Life

Reach your personal and professional goals

Unlock access to hundreds of expert online courses and degrees from top universities and educators to gain accredited qualifications and professional CV-building certificates.

Join over 18 million learners to launch, switch or build upon your career, all at your own pace, across a wide range of topic areas.

Start Learning now