Built-in functions for parallel processing

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.

Function Prototype Description
int __parthds(void); This function returns the value of the parthds runtime option. If the parthds option is not explicitly set by the user, the function returns the default value set by the runtime library.

If the -qsmp compiler option was not specified during program compilation, this function returns 1 regardless of runtime options selected.

int __usrthds(void); This function returns the value of the usrthds runtime option.

If the usrthds option is not explicitly set by the user, or the -qsmp compiler option was not specified during program compilation, this function returns 0 regardless of runtime options selected.

int omp_get_num_threads(void); This function 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); This function 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); This function returns the maximum value that can be returned by calls to omp_get_num_threads.
int omp_get_thread_num(void); This function 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); This function returns the maximum number of processors that could be assigned to the program.
int omp_in_parallel(void); This function 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); This function enables or disables dynamic adjustment of the number of threads available for execution of parallel regions.
int omp_get_dynamic(void); This function returns non-zero if dynamic thread adjustments enabled and returns 0 otherwise.
void omp_set_nested(int nested); This function enables or disables nested parallelism.
int omp_get_nested(void); This function 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.
Note:
In the current implementation, nested parallel regions are always serialized. As a result, omp_set_nested does not have any effect, and omp_get_nested always returns 0.

For complete information about OpenMP runtime library functions, refer to the OpenMP C/C++ Application Program Interface specification in www.openmp.org.

Related information