Environment Library Routines
The routines that can be used to modify the execution environment are listed below.
- omp_set_num_threads(num_threads)
- The
omp_set_num_threads
routine is used to set the nthreads OpenMP internal variable. It should be called outside a parallel region. If it is called within a parallel region, its effect is implementation-defined. The argument must be a positive integer. Setting the internal variable to a particular value does not guarantee that the next parallel region will have that number of threads, because a parallel construct may have its own num_threads clause. - omp_get_num_threads
- The
omp_get_num_threads
routine is not the corresponding getter foromp_set_num_threads
. It can be called anywhere in the program and returns the number of threads in the innermost parallel region to which it belongs. If it is called outside a parallel region, it returns 1. - int omp_get_max_threads()
- The
omp_get_max_threads
routine is the corresponding getter foromp_set_num_threads
. It returns the present value of the nthreads OpenMP internal variable. It should be called outside a parallel region. If it is called within a parallel region, its result is implementation-defined. - int omp_get_thread_number()
- The
omp_get_thread_number
routine returns the OpenMP thread number of the thread from which it is called. OpenMP numbers its threads from 0 to one less than the number that would be returned byomp_get_num_threads
if it were called at this point in the program. These numbers should not be confused with the numbers assigned to threads by the operating system. - int omp_get_num_procs()
- The
omp_get_num_procs
routine returns the number of processors (cores) available to the program. - logical omp_in_parallel()
- The
omp_in_parallel
routine returns the logical "or" of the if-clauses of all the enclosing parallel regions. Any parallel region that doesn't have an if-clause contributes .TRUE. to this evaluation. The routine returns .FALSE. if called outside any parallel region. When called in a C program it returns the integer equivalents (1, 0) of true and false. - omp_set_dynamic(dynamic)
- The
omp_set_dynamic
routine sets the dynamic OpenMP internal variable if its argument evaluates to true and if the OpenMP implementation supports dynamic scheduling of threads. It should be called outside a parallel region. If it is called within a parallel region, its effect is implementation-defined. - logical omp_get_dynamic()
- The
omp_get_dynamic
routine gets the dynamic OpenMP internal variable. It should be called outside a parallel region. If it is called within a parallel region, its effect is implementation-defined. If the implementation doesn't support dynamic scheduling of the number of threads, it will always return false. - omp_set_nested(nested)
- The
omp_set_nested
routine sets the nested OpenMP internal variable if its argument evaluates to true and if the OpenMP implementation supports nesting of parallel regions. It should be called outside a parallel region. If it is called within a parallel region, its effect is implementation-defined. - logical omp_get nested()
- The
omp_get_nested
routine gets the nested OpenMP internal variable. It should be called outside a parallel region. If it is called within a parallel region, its effect is implementation-defined. If the implementation doesn't support nesting of parallel regions, it will always return false.