Sometimes, the work that is to be divided up among threads isn't iterative. In that case, the OpenMP sections directive makes it possible to execute blocks of code in separate threads using the OpenMP framework. The sections directive begins with the OpenMP sentinel and can be followed on the same line (or continuation of that line) by a number of modifiers in clauses. A sections directive must occur in a parallel region, or if the parallel region is the same size as the sections region, they can be combined in a parallel sections directive. Each block to be executed by a thread is introduced with the OpenMP section (singular) directive, which takes no clauses. In C/C++ the block is enclosed in {}; in Fortran, it is delimited by an END SECTION directive. There is an implicit barrier at the end of a sections construct unless the nowait clause is present.

Example

!$OMP PARALLEL [clause[,clause]]
⋮
!$OMP SECTIONS [clause [,clause]]
!$OMP SECTION
⋮
!$OMP END SECTION
⋮
!$OMP SECTION
⋮
!$OMP END SECTION
!$OMP END SECTIONS [nowait]
⋮
!$OMP END PARALLEL

The available clauses for the sections directive are:

Fortran has one exception: the nowait clause must appear with the END SECTIONS directive. If the sections construct appears in nested parallel regions, it will bind to the threads of the innermost enclosing region.

The OpenMP section constructs take no clauses.

 
©   Cornell University  |  Center for Advanced Computing  |  Copyright Statement  |  Inclusivity Statement