#pragma omp section, #pragma omp sections

Description

The omp sections directive distributes work among threads bound to a defined parallel region.

Syntax

Read syntax diagramSkip visual syntax diagram                            .-,------.
                            V        |
>>-#--pragma--omp sections----clause-+-------------------------><

where clause is any of the following:

private (list) Declares the scope of the data variables in list to be private to each thread. Data variables in list are separated by commas.
firstprivate (list) Declares the scope of the data variables in list to be private to each thread. Each new private object is initialized as if there was an implied declaration within the statement block. Data variables in list are separated by commas.
lastprivate (list) Declares the scope of the data variables in list to be private to each thread. The final value of each variable in list, if assigned, will be the value assigned to that variable in the last section. Variables not assigned a value will have an indeterminate value. Data variables in list are separated by commas.
reduction (operator: list) Performs a reduction on all scalar variables in list using the specified operator. Reduction variables in list are separated by commas.

A private copy of each variable in list is created for each thread. At the end of the statement block, the final values of all private copies of the reduction variable are combined in a manner appropriate to the operator, and the result is placed back into the original value of the shared reduction variable.

Variables specified in the reduction clause:

  • must be of a type appropriate to the operator.
  • must be shared in the enclosing context.
  • must not be const-qualified.
  • must not have pointer type.
nowait Use this clause to avoid the implied barrier at the end of the sections directive. This is useful if you have multiple independent work-sharing sections within a given parallel region. Only one nowait clause can appear on a given sections directive.

Notes

The omp section directive is optional for the first program code segment inside the omp sections directive. Following segments must be preceded by an omp section directive. All omp section directives must appear within the lexical construct of the program source code segment associated with the omp sections directive.

When program execution reaches a omp sections directive, program segments defined by the following omp section directive are distributed for parallel execution among available threads. A barrier is implicitly defined at the end of the larger program region associated with the omp sections directive unless the nowait clause is specified.