Sun Studio 12: OpenMP API User's Guide

2.3 OpenMP Environment Variables

The OpenMP specification define four environment variables that control the execution of OpenMP programs. These are summarized in the following table.

Table 2–1 OpenMP Environment Variables

Environment Variable  

Function  

OMP_SCHEDULE

Sets schedule type for DO, PARALLEL DO, for, parallel for, directives/pragmas with schedule type RUNTIME specified. If not defined, a default value of STATIC is used. value is “type[,chunk]”

Example: setenv OMP_SCHEDULE 'GUIDED,4'

OMP_NUM_THREADS or PARALLEL

Sets the number of threads to use during execution of a parallel region. You can override this value by a NUM_THREADS clause, or a call to OMP_SET_NUM_THREADS(). If not set, a default of 1 is used. value is a positive integer. For compatibility with legacy programs, setting the PARALLEL environment variable has the same effect as setting OMP_NUM_THREADS. However, if they are both set to different values, the runtime library will issue an error message.

Example: setenv OMP_NUM_THREADS 16

OMP_DYNAMIC

Enables or disables dynamic adjustment of the number of threads available for execution of parallel regions. If not set, a default value of TRUE is used. value is either TRUE or FALSE.

Example: setenv OMP_DYNAMIC FALSE

OMP_NESTED

Enables or disables nested parallelism.

value is either TRUE or FALSE. The default is FALSE.

Example: setenv OMP_NESTED FALSE

Additional multiprocessing environment variables affect execution of OpenMP programs and are not part of the OpenMP specifications. These are summarized in the following table.

Table 2–2 Multiprocessing Environment Variables

Environment Variable  

Function  

SUNW_MP_WARN

Controls warning messages issued by the OpenMP runtime library. If set to TRUE the runtime library issues warning messages to stderr; FALSE disables warning messages. The default is FALSE.

The OpenMP runtime library has the ability to check for many common OpenMP violations, such as incorrect nesting and deadlocks. Runtime checking does add overhead to the execution of the program. See Chapter 3, Implementation-Defined Behaviors.

The runtime library issues warning messages to stderr if SUNW_MP_WARN is set to TRUE. The runtime library will also issue warning messages if the program registers a call-back function to accept warning messages. A program can register a user call-back function by calling the following function:


   int sunw_mp_register_warn (void (*func)(void *));

The address of the call-back function is passed as argument to sunw_mp_register_warn(). This function returns 0 upon successfully registering the call-back function, 1 upon failure.

If the program has registered a call-back function, libmtsk will call the registered function passing a pointer to the localized string containing the error message. The memory pointed to is no longer valid upon return from the call-back function.

Example: 

setenv SUNW_MP_WARN TRUE

SUNW_MP_THR_IDLE

Controls the status of idle threads in an OpenMP program that are waiting at a barrier or waiting for new parallel regions to work on. You can set the value to be one of the following: SPIN, SLEEP, SLEEP( times), SLEEP(timems), SLEEP( timemc), where time is an integer that specifies an amount of time, and s, ms, and mc specify the time unit (seconds, milli-seconds, and micro-seconds, respectively).

SPIN specifies that an idle thread should spin while waiting at barrier or waiting for new parallel regions to work on. SLEEP without a time argument specifies that an idle thread should sleep immediately. SLEEP with a time argument specifies the amount of time a thread should spin-wait before going to sleep.

The default idle thread status is to sleep after possibly spin-waiting for some amount of time. SLEEP, SLEEP(0), SLEEP(0s), SLEEP(0ms), and SLEEP(0mc) are all equivalent.

Examples:  


setenv SUNW_MP_THR_IDLE SPIN 
setenv SUNW_MP_THR_IDLE SLEEP 
setenv SUNW_MP_THR_IDLE SLEEP(2s) 
setenv SUNW_MP_THR_IDLE SLEEP(20ms) 
setenv SUNW_MP_THR_IDLE SLEEP(150mc)

SUNW_MP_PROCBIND

This environment variable works on Solaris systems only. The SUNW_MP_PROCBIND environment variable can be used to bind threads of an OpenMP program to virtual processors on the running system. Performance can be enhanced with processor binding, but performance degradation will occur if multiple threads are bound to the same virtual processor. See 2.4 Processor Binding on Solaris for details.

SUNW_MP_MAX_POOL_THREADS

Specifies the maximum size of the thread pool. The thread pool contains only non-user threads that the OpenMP runtime library creates. It does not contain the master thread or any threads created explicitly by the user’s program. If this environment variable is set to zero, the thread pool will be empty and all parallel regions will be executed by one thread. The default, if not specified, is 1023. See 4.2 Control of Nested Parallelism for details.

SUNW_MP_MAX_NESTED_LEVELS

Specifies the maximum depth of active nested parallel regions. Any parallel region that has an active nested depth greater than the value of this environment variable will be executed by only one thread. A parallel region is considered not active if it is an OpenMP parallel region that has a false IF clause. The default, if not specified, is 4. See 4.2 Control of Nested Parallelism for details.

STACKSIZE

Sets the stack size for each thread. The value is in kilobytes. The default thread stack sizes are 4 Mb on 32-bit SPARC V8 and x86 platforms, and 8 Mb on 64-bit SPARC V9 and x86 platforms.

Example: 

setenv STACKSIZE 8192 sets the thread stack size to 8 Mb

The STACKSIZE environment variable also accepts numerical values with a suffix of either B, K, M, or G for bytes, kilobytes, megabytes, or gigabytes respectively. The default is kilobytes.

SUNW_MP_GUIDED_WEIGHT

Sets the weighting factor used to determine the size of chunks assigned to threads in loops with GUIDED scheduling. The value should be a positive floating-point number, and will apply to all loops with GUIDED scheduling in the program. If not set, the default value assumed is 2.0.