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:
The omp.h and omp_lib.h header files.
To include the appropriate header files you must add statements similar to the following to your code:
Example |
---|
#include <omp.h> #include <omp_lib.h> |
This topic provides a summary of the OpenMP run-time library routines. For detailed descriptions, see the OpenMP C/C++ version 2.5 specifications (http://www.openmp.org/specs).
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 |
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. |
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. |