OpenMP* Run-time Library Routines

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

The following table specifies the interfaces to these routines. The names for the routines are in user name space. The omp.h and omp_lib.h 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:

Execution Environment Routines

Function Description
omp_set_num_threads(nthreads) Sets the number of threads to use for subsequent parallel regions.
omp_get_num_threads() Returns the number of threads that are being used in the current parallel region.
omp_get_max_threads() Returns the maximum number of threads that are available for parallel execution.
omp_get_thread_num() Returns the unique thread number of the thread currently executing this section of code.
omp_get_num_procs() Returns the number of processors available to the program.
omp_in_parallel() Returns TRUE if called within the dynamic extent of a parallel region executing in parallel; otherwise returns FALSE.
omp_set_dynamic(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. Dynamics threads are disabled by default.
omp_get_dynamic() Returns TRUE if dynamic thread adjustment is enabled, otherwise returns FALSE.
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.
omp_get_nested() Returns TRUE if nested parallelism is enabled, otherwise returns FALSE.

Lock Routines

Function Description
omp_init_lock(lock) Initializes the lock associated with lock for use in subsequent calls.
omp_destroy_lock(lock) Causes the lock associated with lock to become undefined.
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.
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.
omp_test_lock(lock Attempts to set the lock associated with lock. If successful, returns TRUE, otherwise returns FALSE.
omp_init_nest_lock(lock) Initializes the nested lock associated with lock for use in the subsequent calls.
omp_destroy_nest_lock(lock) Causes the nested lock associated with lock to become undefined.
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.
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.
omp_test_nest_lock(lock) Attempts to set the nested lock associated with lock. If successful, returns the nesting count, otherwise returns zero.

Timing Routines

Function Description
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.
omp_get_wtick() Returns a double-precision value equal to the number of seconds between successive clock ticks.