OpenMP Directives: Work-Sharing Constructs: SINGLE Directive

Purpose:

The SINGLE directive specifies that the enclosed code is to be executed by only one thread in the team.

May be useful when dealing with sections of code that are not thread safe (such as I/O)

Format:

Fortran:

!$OMP SINGLE [clause ...] 
             PRIVATE (list) 
             FIRSTPRIVATE (list) 

   block

!$OMP END SINGLE [ NOWAIT ]

C/C++:

#pragma omp single [clause ...]  newline 
                   private (list) 
                   firstprivate (list) 
                   nowait

     structured_block

Clauses:

Threads in the team that do not execute the SINGLE directive, wait at the end of the enclosed code block, unless a NOWAIT/nowait clause is specified.

Clauses are described in detail later, in the Data Scope Attribute Clauses section.

Restrictions:

It is illegal to branch into or out of a SINGLE block.