OpenMP* Run Time Library Routines

OpenMP* provides several run time library routines to assist you in managing 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 allow you to 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 table specifies the interface to these routines. The names for the routines are in user namespace. omp.h is provided in the include directory of your compiler installation. There are definitions for two different locks, omp_lock_t and omp_nest_lock_t, which are used by the functions in the table.

Function Description
void omp_set_num_threads(int num_threads) Dynamically set the number of threads to use for this region.
int omp_get_num_threads(void) Determine what the current number of threads is that is allowed to execute a region.
int omp_get_max_threads(void) Obtains the maximum number of threads ever allowed with this OpenMP* implementation.
int omp_get_thread_num(void) Determines the unique thread number of the thread currently executing this section of code.
int omp_get_num_procs(void) Determines the number of processors on the current machine.
int omp_in_parallel(void) Determines if the region of code the function is called in is running in parallel. Returns non-zero if inside a parallel region, zero otherwise.
void omp_set_dynamic(int dynamic_threads) Enable or disable dynamic adjustment of the number of threads used to execute a parallel region. If dynamic_threads is non-zero, dynamic threads are enabled. If dynamic_threads is zero, dynamic threads are disabled.
int omp_get_dynamic(void) Determine whether dynamic adjustment of the number of threads executing a region is supported. Returns non-zero if dynamic adjustment is supported, zero otherwise.
void omp_set_nested(int nested) Enable or disable nested parallelism. If parameter is non-zero, enable. Default is disabled.
int omp_get_nested(void) Determine whether nested parallelism is currently enabled or disabled. Function returns non-zero if nested parallelism is supported, zero otherwise.
void omp_init_lock(omp_lock_t *lock) Initialize a unique lock and set lock to point to it.
void omp_destroy_lock(omp_lock_t *lock) Disassociate lock from any locks.
void omp_set_lock(omp_lock_t *lock) Force 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.
void omp_unset_lock(omp_lock_t *lock) Release executing thread from ownership of lock associated with lock. lock must be initialized via omp_init_lock(), and behavior undefined if executing thread does not own the lock associated with lock.
int omp_test_lock(omp_lock_t *lock); Attempt to set lock associated with lock. If successful, return non-zero. lock must be initialized via omp_init_lock().
void omp_init_nest_lock(omp_nest_lock_t *lock) Initialize a unique nested lock and set lock to point to it.
void omp_destroy_nest_lock(omp_nest_lock_t *lock) Disassociate the nested lock lock from any locks.
void omp_set_nest_lock(omp_nest_lock_t *lock) Force 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  
void omp_unset_nest_lock(omp_nest_lock_t *lock) Release executing thread from ownership of lock associated with lock if count is zero. lock must be initialized via omp_init_nest_lock(). Behavior is undefined if executing thread does not own the lock associated with lock.
int omp_test_nest_lock(omp_nest_lock_t *lock) Attempt to set lock associated with lock. If successful, return nesting count, otherwise return zero. lock must be initialized via omp_init_lock().