Use these built-in functions to obtain information about the parallel environment. Function definitions for the omp_ functions can be found in the omp.h header file.
Prototype | Description |
---|---|
int omp_get_num_threads(void); | Returns the number of threads currently in the team executing the parallel region from which it is called. |
void omp_set_num_threads(int num_threads); | Overrides the setting of the OMP_NUM_THREADS environment
variable, and specifies the number of threads to use in parallel regions following
this directive. The value num_threads must be a positive
integer.
If the num_threads clause is present, then for the parallel region it is applied to, it supersedes the number of threads requested by the omp_set_num_threads library function or the OMP_NUM_THREADS environment variable. Subsequent parallel regions are not affected by it. |
int omp_get_max_threads(void); | Returns the maximum value that can be returned by calls to omp_get_num_threads. |
int omp_get_thread_num(void); | Returns the thread number, within its team, of the thread executing the function. The thread number lies between 0 and omp_get_num_threads()-1, inclusive. The master thread of the team is thread 0. |
int omp_get_num_procs(void); | Returns the maximum number of processors that could be assigned to the program. |
int omp_in_parallel(void); | Returns non-zero if it is called within the dynamic extent of a parallel region executing in parallel; otherwise, it returns 0. |
void omp_set_dynamic(int dynamic_threads); | Enables or disables dynamic adjustment of the number of threads available for execution of parallel regions. |
int omp_get_dynamic(void); | Returns non-zero if dynamic thread adjustments enabled and returns 0 otherwise. |
void omp_set_nested(int nested); | Enables or disables nested parallelism. |
int omp_get_nested(void); | Returns non-zero if nested parallelism is enabled and 0 if it is disabled. |
void omp_init_lock(omp_lock_t *lock);
void omp_init_nest_lock(omp_nest_lock_t *lock); |
These functions provide the only means of initializing a lock. Each function initializes the lock associated with the parameter lock for use in subsequent calls. |
void omp_destroy_lock(omp_lock_t *lock);
void omp_destroy_nest_lock(omp_nest_lock_t *lock); |
These functions ensure that the specified lock variable lock is uninitialized. |
void omp_set_lock(omp_lock_t *lock);
void omp_set_nest_lock(omp_nest_lock_t *lock); |
Each of these functions blocks the thread executing the function until the specified lock is available and then sets the lock. A simple lock is available if it is unlocked. A nestable lock is available if it is unlocked or if it is already owned by the thread executing the function. |
void omp_unset_lock(omp_lock_t *lock);
void omp_unset_nest_lock(omp_nest_lock_t *lock); |
These functions provide the means of releasing ownership of a lock. |
int omp_test_lock(omp_lock_t *lock);
int omp_test_nest_lock(omp_nest_lock_t *lock); |
These functions attempt to set a lock but do not block execution of the thread. |
double omp_get_wtime(void); | Returns the time elapsed from a fixed starting time. The value of the fixed starting time is determined at the start of the current program, and remains constant throughout program execution. |
double omp_get_wtick(void); | Returns the number of seconds between clock ticks. |
For complete information about OpenMP runtime library functions, refer to the OpenMP C/C++ Application Program Interface specification in www.openmp.org.
Related information