Purpose
The omp sections directive
distributes work among threads bound to a defined parallel region.
Syntax
.-,------.
V |
>>-#--pragma--omp sections----clause-+-------------------------><
Parameters
clause is any
of the following clauses:
- 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 in the original value of the shared reduction variable.
For example, when the max operator is
specified, the original reduction variable value combines with the
final values of the private copies by using the following expression:original_reduction_variable = original_reduction_variable < private_copy ?
private_copy : original_reduction_variable;
For variables specified in the reduction clause,
they must satisfy the following conditions:- Must be of a type appropriate to the operator. If
the max or min operator is specified,
the variables must be one of the following types with or without long, short, signed,
or unsigned:
- _Bool
- char
- int
- float
- double
- 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.
Usage
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.