omp_set_num_threads

#include <omp.h>

void omp_set_num_threads(int num_threads);

The omp_set_num_threads function sets the number of threads to use for subsequent parallel regions. The value of the parameter num_threads must be positive. Its effect depends upon whether dynamic adjustment of the number of threads is enabled. If dynamic adjustment is disabled, the value is used as the number of threads for all subsequent parallel regions prior to the next call to this function; otherwise, the value is the maximum number of threads that will be used. 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 this function is undefined.

For more information on this subject, see the omp_set_dynamic and omp_get_dynamic functions. This call has precedence over the OMP_NUM_THREADS environment variable.

omp_get_num_threads

#include <omp.h>

int omp_get_num_threads(void);

The omp_get_num_threads function returns the number of threads currently in the team executing the parallel region from which it is called. The omp_set_num_threads function and the OMP_NUM_THREADS environment variable control the number of threads in a team. If the number of threads has not been explicitly set by the user, the default is implementation dependent. This function binds to the closest enclosing parallel directive. If called from a serial portion of a program, or from a nested parallel region that is serialized, this function returns 1.

omp_get_max_threads

#include <omp.h>

int omp_get_max_threads(void);

The omp_get_max_threads function returns an integer that is guaranteed to be at least as large as the number of threads that would be used to form a team if a parallel region without a num_threads clause were to be encountered at that point in the code.

omp_get_thread_num

#include <omp.h>

int omp_get_thread_num(void);

The omp_get_thread_num 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. If called from a serial region, omp_get_thread_num returns 0. If called from within a nested parallel region that is serialized, this function returns 0.

omp_get_num_procs

#include <omp.h>

int omp_get_num_procs(void);

The omp_get_num_procs function returns the number of processors that are available to the program at the time the function is called.

omp_in_parallel

#include <omp.h>

int omp_in_parallel(void);

Parallel Programming Using OpenMP 171