OpenMP* Run-time Library Routines

OpenMP* provides several run-time library routines to help you manage your program in parallel mode. Many of these run-time library routines have corresponding environment variables that can be set as defaults. The run-time library routines let you dynamically change these factors to assist in controlling your program. In all cases, a call to a run-time library routine overrides any corresponding environment variable.

The following tables specify the interfaces to these routines. The names for the routines are in user name space. Header files are provided in the INCLUDE directory of your compiler installation:

There are definitions for two different locks, OMP_LOCK_KIND and OMP_NEST_LOCK_KIND, which are used by the functions in the table that follows.

This topic provides a summary of the OpenMP run-time library routines. For detailed descriptions, see the OpenMP Fortran version 2.0 specifications.

Execution Environment Routines

Function

Description

SUBROUTINE OMP_SET_NUM_THREADS(num_threads)
INTEGER num_threads

Sets the number of threads to use for subsequent parallel regions.

INTEGER FUNCTION OMP_GET_NUM_THREADS()

Returns the number of threads that are being used in the current parallel region.

INTEGER FUNCTION OMP_GET_MAX_THREADS()

Returns the maximum number of threads that are available for parallel execution.

INTEGER FUNCTION OMP_GET_THREAD_NUM()

Determines the unique thread number of the thread currently executing this section of code.

INTEGER FUNCTION OMP_GET_NUM_PROCS()

Determines the number of processors available to the program.

LOGICAL FUNCTION OMP_IN_PARALLEL()

Returns .TRUE. if called within the dynamic extent of a parallel region executing in parallel; otherwise returns .FALSE..

SUBROUTINE
OMP_SET_DYNAMIC(dynamic_threads)
LOGICAL dynamic_threads

Enables or disables dynamic adjustment of the number of threads used to execute a parallel region. If dynamic_threads is .TRUE., dynamic threads are enabled. If dynamic_threads is .FALSE., dynamic threads are disabled. Dynamic threads are disabled by default.

LOGICAL FUNCTION OMP_GET_DYNAMIC()

Returns .TRUE. if dynamic thread adjustment is enabled, otherwise returns .FALSE..

SUBROUTINE OMP_SET_NESTED(nested)
LOGICAL nested

Enables or disables nested parallelism. If nested is .TRUE., nested parallelism is enabled.  If nested is .FALSE., nested parallelism is disabled.  Nested parallelism is disabled by default.

LOGICAL FUNCTION OMP_GET_NESTED()

Returns .TRUE. if nested parallelism is enabled, otherwise returns .FALSE..

Lock Routines

Function

Description

SUBROUTINE OMP_INIT_LOCK(lock)
INTEGER (KIND=OMP_LOCK_KIND)::
lock

Initializes the lock associated with lock for use in subsequent calls.

SUBROUTINE OMP_DESTROY_LOCK(lock)
INTEGER(KIND=OMP_LOCK_KIND)::
lock

Causes the lock associated with lock to become undefined.

SUBROUTINE OMP_SET_LOCK(lock)
INTEGER(KIND=OMP_LOCK_KIND)::
lock

Forces the executing thread to wait until the lock associated with lock is available. The thread is granted ownership of the lock when it becomes available.

SUBROUTINE OMP_UNSET_LOCK(lock)
INTEGER(KIND=OMP_LOCK_KIND)::
lock

Releases the executing thread from ownership of the lock associated with lock. The behavior is undefined if the executing thread does not own the lock associated with lock.

LOGICAL OMP_TEST_LOCK(lock)
INTEGER(KIND=OMP_LOCK_KIND)::
lock

Attempts to set the lock associated with lock. If successful, returns .TRUE., otherwise returns .FALSE..

SUBROUTINE OMP_INIT_NEST_LOCK(lock)
INTEGER(KIND=OMP_NEST_LOCK_KIND)::
lock

Initializes the nested lock associated with lock for use in the subsequent calls.

SUBROUTINE OMP_DESTROY_NEST_LOCK(lock)
INTEGER(KIND=OMP_NEST_LOCK_KIND)::
lock

Causes the nested lock associated with lock to become undefined.

SUBROUTINE OMP_SET_NEST_LOCK(lock)
INTEGER(KIND=OMP_NEST_LOCK_KIND)::
lock

Forces the executing thread to wait until the nested lock associated with lock is available. The thread is granted ownership of the nested lock when it becomes available.

SUBROUTINE OMP_UNSET_NEST_LOCK(lock)
INTEGER(KIND=OMP_NEST_LOCK_KIND)::
lock

Releases the executing thread from ownership of the nested lock associated with lock if the nesting count is zero. Behavior is undefined if the executing thread does not own the nested lock associated with lock.

INTEGER OMP_TEST_NEST_LOCK(lock)
INTEGER(KIND=OMP_NEST_LOCK_KIND)::
lock

Attempts to set the nested lock associated with lock. If successful, returns the nesting count, otherwise returns zero.

Timing Routines

Function

Description

DOUBLE-PRECISION FUNCTION OMP_GET_WTIME()

Returns a double-precision value equal to the elapsed wallclock time (in seconds) relative to an arbitrary reference time. The reference time  does not change during program execution.

DOUBLE-PRECISION FUNCTION OMP_GET_WTICK()

Returns a double-precision value equal to the number of seconds between successive clock ticks.