Sun Studio 12 Update 1: OpenMP API User's Guide

4.2.2 OMP_THREAD_LIMIT

The OMP_THREAD_LIMIT environment variable sets the maximum number of OpenMP threads to use for the whole OpenMP program. The defaut number in Sun's implementation is 1024. If this environment variable is set to one, then all parallel regions will be executed by one thread.

The following example shows that a parallel region can get fewer threads if OMP_THREAD_LIMIT is set. The code is the same as above. The number of threads needed for all the parallel regions to be active at the same time is 8. If we set OMP_THREAD_LIMIT to 6, two of the four inner-most parallel regions may not be able to get all the helper threads they ask for. One possible result is shown below.


% setenv OMP_NESTED TRUE
% setenv OMP_THREAD_LIMIT 6
% a.out
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