The omp sections directive
distributes work among threads bound to a defined parallel region.
Syntax
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(reduction-identifier:list)
Specifies that for each data variable in list, a private copy is created. 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 reduction-identifier, and the result is
placed back in the original value of the shared reduction variable.
Scalar variables and array sections are supported in list. Items in
list are separated by commas. reduction-identifier is either an identifier, id-expression, or one of the
following operators that are implicitly
declared: +, -,
*, &, |,
^, &&, and ||.
If you use a reduction-identifier that is not implicitly declared, you
must use the omp declare
reduction directive to declare the
reduction-identifier beforehand.
The following table lists each reduction-identifier that is implicitly
declared at every scope for arithmetic types and its semantic initializer value. The actual
initializer value is that value as expressed in the data type of the reduction list item.
omp_priv=Least representable number in the reduction list item
type
omp_out=omp_in>omp_out?
omp_in:omp_out
min
omp_priv=Largest representable number in the reduction list item
type
omp_out=omp_in<omp_out?
omp_in:omp_out
omp_in and omp_out correspond to two identifiers that refer to storage of the
type of the list item. omp_out holds the final value of the combiner operation. Any
reduction-identifier that is defined with the omp declare reduction
directive is also valid. In that case, the initializer and
combiner of the reduction-identifier are specified by the
initializer-clause and the combiner in the omp
declare reduction directive.
Restrictions:
A list item that appears in a reduction clause of a worksharing
construct must be shared in the parallel regions to which any of the
worksharing regions arising from the worksharing construct bind.
A list item that appears in a reduction clause of the innermost
enclosing worksharing or parallel construct may not be accessed in an
explicit task.
Any number of reduction clauses can be specified on the directive, but
a list item can appear only once in the reduction clauses for that
directive.
For a reduction-identifier declared with the omp declare
reduction construct, the directive must appear before its use in a
reduction clause.
If a list item is an array section, it must specify contiguous storage and it cannot be a
zero-length array section.
If a list item is an array section, accesses to the elements of the array outside the specified
array section are not allowed.
The type of a list item that appears in a reduction clause must be
valid for the reduction-identifier. For a max or min reduction in C, the type of the list item must be an allowed
arithmetic data type: char, int, float, double, or _Bool, possibly modified with long, short,
signed, or unsigned.For a max or min reduction in C++, the type of the list item must be an
allowed arithmetic data type: char, wchar_t, int, float, double, or bool, possibly modified with
long, short, signed, or unsigned.
A list item that appears in a reduction clause must not be
const-qualified.
If a list item in a reduction clause on a worksharing construct has a
reference type then it must bind to the same object for all threads of the team.
The reduction-identifier for any list item must be unambiguous and
accessible.
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.