Intel® Fortran Compiler
Build applications that can scale for the future with optimized code designed for Intel® Xeon® and compatible processors.
29382 Discussions

OMP_GET_MAX_THREADS vs OMP_GET_NUM_PROCS

jond
Novice
3,870 Views
What is the difference between OMP_GET_MAX_THREADS (OT) and OMP_GET_NUM_PROCS (OP) functions? By default, does OT return the same number as OP? Is OT, by default, hardware dependent?

Thanks,
Jon
4 Replies
jimdempseyatthecove
Honored Contributor III
3,869 Views

Jon,

Depending on your program design or system administrator's preference, an application my have (want) more or less threads than the number of processors available. If, as an example, your OpenMP threads perform I/O as well as computations, you might find it preferable to use more threads than processors. On the other hand, if your OpenMP threads are compute intensive, and the system is used for other purposes, you might find it preferable to specify a max number of threads less than the number of available processors.

Jim Dempsey

Steven_L_Intel1
Employee
3,869 Views
The default is that the number of threads is the number of processors. This can be affected in many ways (environment variables, calls to OMP, etc.)
jond
Novice
3,869 Views
Thanks Jim,

One other question: If I run my program on a machine with 4 processors, I would expect that OMP_GET_NUM_PROCS (OP) returns the value 4. Let's assume OMP_GET_MAX_THREADS (OT) also returns 4. If I run my program on an 8-processor machine, I think OP would return 8, but what about OT? Would it still return 4 (a preset number by Intel) or would it return 8 as well? I know that you can set the number of threads less or higher than the number of processors, but I am crious about the default number OT would return.

Jon
0 Kudos
jimdempseyatthecove
Honored Contributor III
3,869 Views

On application startup the initialization code calls the O/S to obtain the number of processors used by the O/S.e.g. a single processor O/S may not necessarily have a function to query for the number of processors, or if it has, it may return 1. A multi processor O/S will typically report the number of concurrent hardware theads as number of processors. However, depending on the O/S you can get information as to

Number of packages (chips)
Number of processors per package
Number of cores per processor
Number of hardware threads per core (e.g. HyperThreading)

Most systems require all packages to be the same (but some systems do not have this requirement).

A system with two E5420 Xeon's has 2 packages, 2 processors per package, 2 cores per processor, 0 hardware threads per core. omp_get_num_procs should return 8.

Most operating systems support environment variables. If you set OMP_NUM_THREADS=n then n will be the default number of threads. If OMP_NUM_THREADS is not specified then the initialization code uses OMP_GET_NUM_PROCS.

Note, some of the older generation processors with HyperThreading would not provide significant performance boost for FPU intensive applications. On those systems you might want to set OMP_NUM_THREADS = total number of cores (not total number of hardware theads).

Jim Dempsey

Reply