The single construct can also appear in a parallel region. The single directive indicates that the block of code that follows must be executed by only one thread in the parallel team. There is no guarantee about which thread will be used. Like the loop and section directives, the single 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.

Example

!$OMP PARALLEL [clause [,clause]]
⋮
!$OMP SINGLE [clause [,clause]]
⋮
!$OMP END SINGLE [NOWAIT]
⋮
!$OMP END PARALLEL

The available clauses are:

The copyprivate clause lists variables that are to be broadcast to all of the threads as private variables when execution of the single region completes. This happens at the implicit barrier at the end of the region, so if the copyprivate clause is used, the nowait clause cannot be. In Fortran, the copyprivate clause, like the nowait clause, appears on the END SINGLE construct.

There is an implicit barrier at the end of a single construct unless its directive (single in C/C++ or END SINGLE in Fortran) includes the nowait clause.

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