HOME
| OPENMP API Specification: "Version 5.2 -- GIT rev 95b2e3a44"

16.1  cancel Construct

Name: cancel

Association: none

Category: executable

Properties: default

Clauses

if, do, for, parallel, sections, taskgroup

Additional information

The cancel-directive-name clause set consists of the directive-name of each directive that has the cancellable property (i.e., directive-name for the worksharing-loop construct, parallel, sections and taskgroup). This clause set has the required, unique and exclusive properties.

Binding

The binding thread set of the cancel region is the current team. The binding region of the cancel region is the innermost enclosing region of the type that corresponds to cancel-directive-name.

Semantics

The cancel construct activates cancellation of the innermost enclosing region of the type specified by cancel-directive-name, which must be the directive-name of a cancellable construct. Cancellation of the binding region is activated only if the cancel-var ICV is true, in which case the cancel construct causes the encountering task to continue execution at the end of the binding region if cancel-directive-name is not taskgroup. If the cancel-var ICV is true and cancel-directive-name is taskgroup, the encountering task continues execution at the end of the current task region. If the cancel-var ICV is false, the cancel construct is ignored.

Threads check for active cancellation only at cancellation points that are implied at the following locations:

When a thread reaches one of the above cancellation points and if the cancel-var ICV is true, then:

When cancellation of tasks is activated through a cancel construct with taskgroup for cancel-directive-name, the tasks that belong to the taskgroup set of the innermost enclosing taskgroup region will be canceled. The task that encountered that construct continues execution at the end of its task region, which implies completion of that task. Any task that belongs to the innermost enclosing taskgroup and has already begun execution must run to completion or until a cancellation point is reached. Upon reaching a cancellation point and if cancellation is active, the task continues execution at the end of its task region, which implies the completion of the task. Any task that belongs to the innermost enclosing taskgroup and that has not begun execution may be discarded, which implies its completion.

When cancellation of tasks is activated through a cancel construct with cancel-directive-name other than taskgroup, each thread of the binding thread set resumes execution at the end of the canceled region if a cancellation point is encountered. If the canceled region is a parallel region, any tasks that have been created by a task or a taskloop construct and their descendent tasks are canceled according to the above taskgroup cancellation semantics. If the canceled region is not a parallel region, no task cancellation occurs.

The usual C++ rules for object destruction are followed when cancellation is performed.
All private objects or subobjects with ALLOCATABLE attribute that are allocated inside the canceled construct are deallocated.

If the canceled construct contains a reduction-scoping or lastprivate clause, the final values of the list items that appeared in those clauses are undefined.

When an if clause is present on a cancel construct and the if expression evaluates to false, the cancel construct does not activate cancellation. The cancellation point associated with the cancel construct is always encountered regardless of the value of the if expression.

The programmer is responsible for releasing locks and other synchronization data structures that might cause a deadlock when a cancel construct is encountered and blocked threads cannot be canceled. The programmer is also responsible for ensuring proper synchronizations to avoid deadlocks that might arise from cancellation of OpenMP regions that contain OpenMP synchronization constructs.

Execution Model Events

If a task encounters a cancel construct that will activate cancellation then a cancel event occurs.

A discarded-task event occurs for any discarded tasks.

Tool Callbacks

A thread dispatches a registered ompt_callback_cancel callback for each occurrence of a cancel event in the context of the encountering task. This callback has type signature ompt_callback_cancel_t; (flags & ompt_cancel_activated) always evaluates to true in the dispatched callback; (flags & ompt_cancel_parallel) evaluates to true in the dispatched callback if cancel-directive-name is parallel; (flags & ompt_cancel_sections) evaluates to true in the dispatched callback if cancel-directive-name is sections; (flags & ompt_cancel_loop) evaluates to true in the dispatched callback if cancel-directive-name is for or do; and (flags & ompt_cancel_taskgroup) evaluates to true in the dispatched callback if cancel-directive-name is taskgroup.

A thread dispatches a registered ompt_callback_cancel callback with the ompt_data_t associated with the discarded task as its task_data argument and ompt_cancel_discarded_task as its flags argument for each occurrence of a discarded-task event. The callback occurs in the context of the task that discards the task and has type signature ompt_callback_cancel_t.

Restrictions

Restrictions to the cancel construct are as follows:

Cross References