# SINGLE

OpenMP* Fortran Compiler Directive: Specifies that a block of code is to be executed by only one thread in the team at a time.

## Syntax

!$OMP SINGLE [clause[[,] clause] ... ]

loosely-structured-block

!$OMP END SINGLE [modifier]

-or-

!$OMP SINGLE [clause[[,] clause] ... ]

strictly-structured-block

!$OMP END SINGLE [modifier]

clause | Is one of the following: ALLOCATE ([allocator :] list) FIRSTPRIVATE (list) PRIVATE (list)
loosely-structured-block | Is a structured block (section) of statements or constructs. You cannot branch into or out of the block.
strictly-structured-block | Is a Fortran BLOCK construct. You cannot branch into or out of the BLOCK construct.
modifier | Is one of the following: COPYPRIVATE (list) NOWAIT

The binding thread set for a SINGLE construct is the current team. A SINGLE region binds to the innermost enclosing parallel region.

Threads in the team that are not executing this directive wait at the END SINGLE directive unless NOWAIT is specified.

SINGLE directives must be encountered by all threads in a team or by none at all. It must also be encountered in the same order by all threads in a team.

## Example

In the following example, the first thread that encounters the SINGLE directive executes subroutines OUTPUT and INPUT:

      !$OMP PARALLEL DEFAULT(SHARED)
            CALL WORK(X)
      !$OMP BARRIER
      !$OMP SINGLE
            CALL OUTPUT(X)
            CALL INPUT(Y)
      !$OMP END SINGLE
            CALL WORK(Y)
      !$OMP END PARALLEL

You should not make assumptions as to which thread executes the SINGLE section. All other threads skip the SINGLE section and stop at the barrier at the END SINGLE construct. If other threads can proceed without waiting for the thread executing the SINGLE section, you can specify NOWAIT in the END SINGLE directive.

Parent topic: S

## See Also

OpenMP Fortran Compiler Directives
Syntax Rules for Compiler Directives
Parallel Processing Model for information about Binding Sets