HOME
| OPENMP API Specification: Version 5.0 November 2018

2.6.1  Determining the Number of Threads for a parallel Region

When execution encounters a parallel directive, the value of the if clause or num_threads clause (if any) on the directive, the current parallel context, and the values of the nthreads-var, dyn-var, thread-limit-var, and max-active-levels-var ICVs are used to determine the number of threads to use in the region.

Using a variable in an if or num_threads clause expression of a parallel construct causes an implicit reference to the variable in all enclosing constructs. The if clause expression and the num_threads clause expression are evaluated in the context outside of the parallel construct, and no ordering of those evaluations is specified. In what order or how many times any side effects of the evaluation of the num_threads or if clause expressions occur is also unspecified.

When a thread encounters a parallel construct, the number of threads is determined according to Algorithm 2.1.

____________________________________________________________________________
      Algorithm 2.1_________________________________

let ThreadsBusy be the number of OpenMP threads currently executing in this contention group;

let ActiveParRegions be the number of enclosing active parallel regions;

if an if clause exists

then let IfClauseValue be the value of the if clause expression;

else let IfClauseValue = true;

if a num_threads clause exists

then let ThreadsRequested be the value of the num_threads clause expression;

else let ThreadsRequested = value of the first element of nthreads-var;

let ThreadsAvailable = (thread-limit-var - ThreadsBusy + 1);

if (IfClauseValue = false)

then number of threads = 1;

else if (ActiveParRegions = max-active-levels-var)

then number of threads = 1;

else if (dyn-var = true) and (ThreadsRequested ThreadsAvailable)

then 1 number of threads ThreadsRequested;

else if (dyn-var = true) and (ThreadsRequested > ThreadsAvailable)

then 1 number of threads ThreadsAvailable;

else if (dyn-var = false) and (ThreadsRequested ThreadsAvailable)

then number of threads = ThreadsRequested;

else if (dyn-var = false) and (ThreadsRequested > ThreadsAvailable)

then behavior is implementation defined;

____________________________________________________________________________

SVG-Viewer needed.

Note – Since the initial value of the dyn-var ICV is implementation defined, programs that depend on a specific number of threads for correct execution should explicitly disable dynamic adjustment of the number of threads.

SVG-Viewer needed.

Cross References