The OMP_NUM_THREADS environment variable specifies the number of threads to use for parallel regions.
>>-OMP_NUM_THREADS=--num_list----------------------------------><
If you do not set OMP_NUM_THREADS, the number of processors available is the default value to form a new team for the first encountered parallel construct. By default, any nested parallel constructs are run by one thread.
If num_list contains a single value, dynamic adjustment of the number of threads is enabled (OMP_DYNAMIC is set to true), and a parallel construct without a num_threads clause is encountered, the value is the maximum number of threads that can be used to form a new team for the encountered parallel construct.
If num_list contains a single value, dynamic adjustment of the number of threads is not enabled (OMP_DYNAMIC is set to false), and a parallel construct without a num_threads clause is encountered, the value is the exact number of threads that can be used to form a new team for the encountered parallel construct.
If num_list contains multiple values, dynamic adjustment of the number of threads is enabled (OMP_DYNAMIC is set to true), a parallel construct without a num_threads clause is encountered, the first value is the maximum number of threads that can be used to form a new team for the encountered parallel construct. After the encountered construct is entered, the first value is removed and the remaining values form a new num_list. The new num_list is in turn used in the same way for any closely nested parallel constructs inside the encountered parallel construct.
If the number of threads requested exceeds the system resources available, the program stops.
The omp_set_num_threads function sets the first value of num_list. The omp_get_max_threads function returns the first value of num_list.
export OMP_NUM_THREADS=3,4,5
export OMP_DYNAMIC=false
// omp_get_max_threads() returns 3
#pragma omp parallel
{
// Three threads running the parallel region
// omp_get_max_threads() returns 4
#pragma omp parallel if(0)
{
// One thread running the parallel region
// omp_get_max_threads() returns 5
#pragma omp parallel
{
// Five threads running the parallel region
// omp_get_max_threads() returns 5
}
}
}