NAG Library Function Document

nag_omp_get_thread_num (x06adc)

 Contents

    1  Purpose
    7  Accuracy

1
Purpose

nag_omp_get_thread_num (x06adc) returns the OpenMP thread number of the calling thread.

2
Specification

#include <nag.h>
#include <nagx06.h>
Integer  nag_omp_get_thread_num ()

3
Description

nag_omp_get_thread_num (x06adc), for multi-threaded implementations, returns the calling OpenMP thread's unique thread number within the current team. The master thread will always return 0. The remaining threads will return a value between 1 and the value returned by nag_omp_get_num_threads (x06abc) less 1.
If this function is called from a sequential part of a multi-threaded program then it will return the value 0.
In serial implementations of the NAG C Library this function will always return 0. See the x06 Chapter Introduction for a discussion of the behaviour of these functions when called in serial.

4
References

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

5
Arguments

None.

6
Error Indicators and Warnings

None.

7
Accuracy

Not applicable.

8
Parallelism and Performance

nag_omp_get_thread_num (x06adc) is not threaded in any implementation.

9
Further Comments

None.

10
Example

In this example we presume a multi-threaded implementation of the NAG C Library. We call nag_omp_get_thread_num (x06adc) both outside and inside an OpenMP active parallel region. Outside we expect a single thread to display the value 0. Inside the region we use the value to have only the master thread display the result.
We also call nag_omp_in_parallel (x06afc) inside and outside of the region. Outside we expect it to return 0, as we are not in an active parallel region, and inside we expect to see the value 1, indicating that the parallel region is an active one.
If you use a serial implementation of the NAG library, regardless of whether the code is compiled with OpenMP or not, nag_omp_get_num_threads (x06abc) will always return 1 and nag_omp_get_thread_num (x06adc) and nag_omp_in_parallel (x06afc) will always return 0. The appropriate results file will be included with the distribution material for your implementation.

10.1
Program Text

Program Text (x06adce.c)

10.2
Program Data

None.

10.3
Program Results

Program Results (x06adce.r)

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