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.
This topic provides a summary of the OpenMP run-time library routines. See OpenMP* Support Overview for additional resources; refer to the OpenMP API Version 3.0 specification for detailed information about using these routines.
The following tables specify the interfaces to these routines. (The names for the routines are in user name space.)
Use these routines to monitor and influence threads and the parallel environment.
Function |
Description |
---|---|
SUBROUTINE OMP_SET_NUM_THREADS(num_threads) |
Sets the number of threads to use for subsequent parallel regions created by the calling thread. |
INTEGER FUNCTION OMP_GET_NUM_THREADS() |
Returns the number of threads that are being used in the current parallel region. This function does not return the value inherited by the calling thread from the OMP_SET_NUM_THREADS() function. |
INTEGER FUNCTION OMP_GET_MAX_THREADS() |
Returns the number of threads available to subsequent parallel regions created by the calling thread. This function returns the value inherited by the calling thread from the OMP_SET_NUM_THREADS() function. |
INTEGER FUNCTION OMP_GET_THREAD_NUM() |
Returns the thread number of the calling thread, within the context of the current parallel region.. |
INTEGER FUNCTION OMP_GET_NUM_PROCS() |
Returns 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 |
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) |
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.. |
SUBROUTINE |
Determines the schedule of a worksharing loop that is applied when 'runtime' is used as schedule kind. |
SUBROUTINE |
Returns the schedule of a worksharing loop that is applied when the 'runtime' schedule is used. |
INTEGER FUNCTION |
Returns the maximum number of simultaneously executing threads in an OpenMP* program. |
SUBROUTINE |
Limits the number of nested active parallel regions. The call is ignored if negative max_active_levels specified. |
INTEGER FUNCTION |
Returns the maximum number of nested active parallel regions. |
INTEGER FUNCTION |
Returns the number of nested, active parallel regions enclosing the task that contains the call. |
INTEGER FUNCTION |
Returns the number of nested parallel regions (whether active or inactive) enclosing the task that contains the call, not including the implicit parallel region. |
INTEGER FUNCTION |
Returns the thread number of the ancestor at a given nest level of the current thread. |
INTEGER FUNCTION |
Returns the size of the thread team to which the ancestor belongs. |
Use these routines to affect OpenMP locks.
Function |
Description |
---|---|
SUBROUTINE OMP_INIT_LOCK(lock) |
Initializes the lock associated with lock for use in subsequent calls. |
SUBROUTINE OMP_DESTROY_LOCK(lock) |
Causes the lock specified by lock to become undefined or uninitialized. The lock must be initialized and not locked. |
SUBROUTINE OMP_SET_LOCK(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. The lock must be initialized. |
SUBROUTINE OMP_UNSET_LOCK(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) |
Attempts to set the lock associated with lock. If successful, returns .TRUE., otherwise returns .FALSE.. The lock must be initialized. |
SUBROUTINE OMP_INIT_NEST_LOCK(lock) |
Initializes the nested lock associated with lock for use in the subsequent calls. |
SUBROUTINE OMP_DESTROY_NEST_LOCK(lock) |
Causes the nested lock associated with lock to become undefined or uninitialized. The lock must be initialized and not locked. |
SUBROUTINE OMP_SET_NEST_LOCK(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. The lock must be initialized. |
SUBROUTINE OMP_UNSET_NEST_LOCK(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) |
Attempts to set the nested lock specified by lock. If successful, returns the nesting count, otherwise returns zero. |
Function |
Description |
---|---|
DOUBLE PRECISION FUNCTION OMP_GET_WTIME() |
Returns a double precision value equal to the elapsed wall clock 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. |