The omp_in_parallel function returns non-zero if it is called within the dynamic extent of a parallel region executing in parallel; otherwise, it returns 0. This function returns non-zero from within a region executing in parallel, including nested regions that are serialized.

omp_set_dynamic

#include <omp.h>

void omp_set_dynamic(int dynamic_threads);

The omp_set_dynamic function enables or disables dynamic adjustment of the number of threads available for execution of parallel regions. This function has effect only when called from serial portions of the program. If it is called from a portion of the program where the omp_in_parallel function returns non-zero, the behavior of the function is undefined. If dynamic_threads evaluates to non-zero, the number of threads that are used for executing subsequent parallel regions may be adjusted automatically by the runtime environment to best utilize system resources. As a consequence, the number of threads specified by the user is the maximum thread count. The number of threads always remains fixed over the duration of each parallel region and is reported by the omp_get_num_threads function. If dynamic_threads evaluates to 0, dynamic adjustment is disabled. A call to omp_set_dynamic has precedence over the OMP_DYNAMIC environment variable.

The default for the dynamic adjustment of threads is 0.

omp_get_dynamic

#include <omp.h>

int omp_get_dynamic(void);

The omp_get_dynamic function returns non-zero if dynamic thread adjustment is enabled and returns 0 otherwise.

omp_set_nested

#include <omp.h>

void omp_set_nested(int nested);

The omp_set_nested function enables or disables nested parallelism. If nested evaluates to 0, which is the default, nested parallelism is disabled, and nested parallel regions are serialized and executed by the current thread. If nested evaluates to non-zero, nested parallelism is enabled, and parallel regions that are nested may deploy additional threads to form the team. This call has precedence over the OMP_NESTED environment variable.

omp_get_nested

#include <omp.h>

int omp_get_nested(void);

The omp_get_nested function returns non-zero if nested parallelism is enabled and 0 if it is disabled.

Lock Functions

The functions described in this section manipulate locks used for synchronization.

For the following functions, the lock variable must have type omp_lock_t. For nestable lock functions, the lock variable must have type omp_nest_lock_t.

172 Exception Handling