Intel® C++ Compiler 16.0 User and Reference Guide
Specifies a structured block that will be executed only once by a single thread in the team.
#pragma omp single [clause,clause , ...] |
structured-block
clause |
Can be one or more of the following clauses:
|
Only one thread will be allowed to execute the structured block. The rest of the threads in the team wait at the implicit barrier at the end of the single construct, unless nowait is specified. If nowait is specified, then the rest of the threads in the team immediately execute the code after the structured block.
The following example demonstrates how to use this pragma to make sure that the printf function is executed only once. All the threads in the team that do not execute the function proceed immediately to the following calculations.
Example |
---|
#include <omp.h> #pragma omp parallel { #pragma omp single nowait { printf(“Starting calculation\n”); } // Do some calculation } |