NAG Library Function Document

1Purpose

nag_omp_set_num_threads (x06aac) sets the number of threads requested for subsequent OpenMP parallel regions.

2Specification

 #include #include
 void nag_omp_set_num_threads (Integer num, NagError *fail)

3Description

nag_omp_set_num_threads (x06aac), for multi-threaded implementations, sets the number of threads to be requested for subsequent parallel regions to num. The first element of the list held by the OpenMP Internal Control Variable (ICV) used in determining the number of threads is set. See the Users' Note for your implementation for details of the scope of this function.
The number of threads used in parallel regions will be equal to, or less than, the value of the ICV. The actual number of threads used is dependent on several factors, such as the presence of a num_threads clause on the parallel directive or the number of threads already in use by the program. Please refer to Section 4 for a full description of how the number of threads is chosen for a particular parallel region.
In serial implementations of the NAG C Library this function has no effect. See the x06 Chapter Introduction for a discussion of the behaviour of these functions when called in serial.

4References

OpenMP Specifications http://openmp.org/
Chapman B, Jost G and van der Pas R (2008) Using OpenMP Portable Shared Memory Parallel Programming The MIT Press

5Arguments

1:    $\mathbf{num}$IntegerInput
On entry: the number of threads requested for subsequent OpenMP parallel regions.
Constraint: ${\mathbf{num}}\ge 1$.
2:    $\mathbf{fail}$NagError *Input/Output
The NAG error argument (see Section 3.7 in How to Use the NAG Library and its Documentation).

6Error Indicators and Warnings

NE_ALLOC_FAIL
Dynamic memory allocation failed.
See Section 2.3.1.2 in How to Use the NAG Library and its Documentation for further information.
NE_INT
On entry, ${\mathbf{num}}=〈\mathit{\text{value}}〉$.
Constraint: ${\mathbf{num}}\ge 1$.
NE_INTERNAL_ERROR
An internal error has occurred in this function. Check the function call and any array sizes. If the call is correct then please contact NAG for assistance.
See Section 2.7.6 in How to Use the NAG Library and its Documentation for further information.
NE_NO_LICENCE
Your licence key may have expired or may not have been installed correctly.
See Section 2.7.5 in How to Use the NAG Library and its Documentation for further information.

Not applicable.

None.

10Example

In this example we presume a multi-threaded implementation of the NAG Library. We set the OpenMP Internal Control Variable used in determining the number of threads to $5$ with a call to nag_omp_set_num_threads (x06aac) and retrieve it again with nag_omp_get_max_threads (x06acc).
We then, using nag_omp_get_num_threads (x06abc), display the number of threads in use both outside, and inside, the OpenMP parallel region.
We expect to see nag_omp_get_num_threads (x06abc) returning $1$ outside of the parallel region, as the current team of threads there will consist of a single thread, and $5$ from within it.
If you use a serial implementation of the NAG Library, regardless of whether the code is compiled with OpenMP or not, calling nag_omp_set_num_threads (x06aac) has no effect and nag_omp_get_num_threads (x06abc) and nag_omp_get_max_threads (x06acc) will always return $1$. The appropriate results file will be included with the distribution material for your implementation.

10.1Program Text

Program Text (x06aace.c)

None.

10.3Program Results

Program Results (x06aace.r)

© The Numerical Algorithms Group Ltd, Oxford, UK. 2017