Routines for OpenMP

The OpenMP specification provides a number of routines that you can use to control and query the parallel execution environment, timing, and lock.

Parallel threads created by the runtime environment through the OpenMP interface are considered independent of the threads you create and control using calls to the Fortran Pthreads library module. References within the following descriptions to "serial portions of the program" refer to portions of the program that are executed by only one of the threads that have been created by the runtime environment. For example, you can create multiple threads by using f_pthread_create. However, if you then call omp_get_num_threads from outside of an OpenMP parallel block, or from within a serialized nested parallel region, the function will return 1, regardless of the number of threads that are currently executing.

OpenMP runtime library calls must not appear in PURE and ELEMENTAL procedures.

Table 1. OpenMP execution environment routines

omp_get_active_level
omp_get_ancestor_thread_num
omp_get_dynamic
omp_get_level
omp_get_max_active_levels
omp_get_max_threads
omp_get_nested
omp_get_num_procs
omp_get_num_threads

omp_get_thread_num
omp_get_schedule
omp_get_team_size
omp_get_thread_limit
omp_in_final
omp_in_parallel
omp_set_dynamic
omp_set_max_active_levels
omp_set_nested
omp_set_num_threads
omp_set_schedule

Included in the OpenMP runtime library are two routines that support a portable wall-clock timer.
Table 2. OpenMP timing routines

omp_get_wtick

omp_get_wtime

The OpenMP runtime library also supports a set of simple and nestable lock routines. You must only lock variables through these routines. Simple locks may not be locked if they are already in a locked state. Simple lock variables are associated with simple locks and may only be passed to simple lock routines. Nestable locks may be locked multiple times by the same thread. Nestable lock variables are associated with nestable locks and may only be passed to nestable lock routines. Note that locks are now associated with task regions, and no longer with threads as such, in accordance with changes in the OMP standard.

For all the routines listed below, the lock variable is an integer whose KIND type parameter is denoted either by the symbolic constant omp_lock_kind, or by omp_nest_lock_kind.

This variable is sized according to the compilation mode. It is set either to '4' for 32-bit applications or '8' for 64-bit.

Table 3. OpenMP simple lock routines

omp_destroy_lock
omp_init_lock
omp_set_lock

omp_test_lock
omp_unset_lock

Table 4. OpenMP nestable lock routines

omp_destroy_nest_lock
omp_init_nest_lock
omp_set_nest_lock

omp_test_nest_lock
omp_unset_nest_lock

Note: You can define and implement your own versions of the OpenMP routines. However, by default, the compiler will substitute the XL Fortran versions of the OpenMP routines regardless of the existence of other implementations, unless you specify the -qnoswapomp compiler option. For more information, see XL Fortran Compiler Reference.

See the following topics for more information about OpenMP execution environment routines, timing routines, and lock routines: