#pragma omp parallel
Purpose
The omp parallel directive explicitly instructs the compiler to parallelize the chosen block of code.
Syntax
Parameters
- if(exp)
- When the
if
argument is specified, the program code executes in parallel only if the scalar expression represented by exp evaluates to a nonzero value at run time. Only oneif
clause can be specified. - private(list)
- Declares the scope of the data variables in list to be private to each thread. Data variables in list are separated by commas.
- firstprivate(list)
- Declares the scope of the data variables in list to be private to each thread. Each new private object is initialized with the value of the original variable as if there was an implied declaration within the statement block. Data variables in list are separated by commas.
- num_threads(int_exp)
- The value of int_exp is an integer expression that specifies the number of threads to use for the parallel region. If dynamic adjustment of the number of threads is also enabled, then int_exp specifies the maximum number of threads to be used.
- shared(list)
- Declares the scope of the comma-separated data variables in list to be shared across all threads.
- default(shared | none)
- Defines the default data scope of variables in each thread. Only
one default clause can be specified on an omp parallel directive.
Specifying default(shared) is equivalent to stating each variable in a shared(list) clause.
Specifying default(none) requires that each data variable visible to the parallelized statement block must be explcitly listed in a data scope clause, with the exception of those variables that are:
- const-qualified,
- specified in an enclosed data scope attribute clause, or,
- used as a loop control variable referenced only by a corresponding omp for or omp parallel for directive.
- copyin(list)
- For each data variable specified in list, the value of the data variable in the main thread is copied to the thread-private copies at the beginning of the
parallel region. Data variables in list are separated by commas.
Each data variable specified in the copyin clause must be a threadprivate variable.
- reduction(reduction-identifier:list)
- Performs a reduction on each data variable in list using the specified reduction-identifier. A private copy of each variable in list is created for each thread. At the end of the statement block, the final values of all private copies of the reduction variable are combined in a manner appropriate to the operator, and the result is placed back in the original value of the shared reduction variable.Scalar variables and array sections are supported in list. Items in list are separated by commas. reduction-identifier is either an identifier, id-expression, or one of the following operators that are implicitly declared: +, -, *, &, |, ^, &&, and ||. If you use a reduction-identifier that is not implicitly declared, you must use the omp declare reduction directive to declare the reduction-identifier beforehand.
- proc_bind(master | close | spread)
- Specifies a policy for assigning threads to places within the
current place partition. At most one
proc_bind
clause can be specified on the parallel directive. If the OMP_PROC_BIND environment variable is not set to FALSE, theproc_bind
clause overrides the first element in the OMP_PROC_BIND environment variable. If the OMP_PROC_BIND environment variable is set to FALSE, theproc_bind
clause has no effect.
Usage
When a parallel region is encountered, a logical team of threads is formed. Each thread in the team executes all statements within a parallel region except for work-sharing constructs. Work within work-sharing constructs is distributed among the threads in a team.
Loop iterations must be independent before the loop can be parallelized. An implied barrier exists at the end of a parallelized statement block.
By default, nested parallel regions are serialized.