Oracle® Solaris Studio 12.4: OpenMP API User's Guide

Exit Print View

Updated: December 2014
 
 

3.2.2 OMP_THREAD_LIMIT

The setting of the OMP_THREAD_LIMIT environment variable controls the maximum number of OpenMP threads to use for the whole program. This number includes the initial (or main) thread, as well as the OpenMP helper threads that the OpenMP runtime library creates. By default, the maximum number of OpenMP threads to use for the whole program is 1024 (one initial or main thread and 1023 OpenMP helper threads).

Note that the thread pool consists of only OpenMP helper threads that the OpenMP runtime library creates. The pool does not include the initial (or main) thread or any thread created explicitly by the user's program.

If OMP_THREAD_LIMIT is set to 1, then the helper thread pool will be empty and all parallel regions will be executed by one thread (the initial or main thread).

The following example output shows that a parallel region might get fewer helper threads if the pool does not contain a sufficient number of helper threads. The code is the same as that in Example 3–1, except that the environment variable OMP_THREAD_LIMIT is set to 6. The number of threads needed for all the parallel regions to be active at the same time is 8. Therefore, the pool needs to contain at least 7 helper threads. If OMP_THREAD_LIMIT is set to 6, then the pool contains at most 5 helper threads. Therefore, two of the four innermost parallel regions might not be able to get all the helper threads requested. The following example shows one possible result.

% setenv OMP_NESTED TRUE
% OMP_THREAD_LIMIT 6
% a.out | sort
Level 1: number of threads in the team = 2
Level 2: number of threads in the team = 2
Level 2: number of threads in the team = 2
Level 3: number of threads in the team = 2
Level 3: number of threads in the team = 2
Level 3: number of threads in the team = 1
Level 3: number of threads in the team = 1