Search code examples
openmp

OpenMP omp_get_max_threads() return value


Does omp_get_max_threads() return the value of $OMP_NUM_THREADS when OMP_NUM_THREADS environment variable is defined?

It look like so on my system (Linux/gcc). Even if OMP_NUM_THREADS is set to a ridiculously high value...

Calling it in the beginning of main, i.e., not inside any (nested) parallel region (if it makes a difference).


Solution

  • You are right that omp_get_max_threads() returns the value of OMP_NUM_THREADS. And you can set this as high as you want: a thread is a software construct and has nothing to do with the number of cores you have. For that, use omp_get_num_procs(). Normally it wouldn't make much sense to have more threads than cores, but it could: if the work in the threads is very different, or threads can pause because of locks and such, you could get a higher processor utilization by having more threads than cores.