OpenMP Internal Control Variables and Environment Variables
The OpenMP specification provides internal control variables you can set prior to the execution of an OpenMP application to affect the operation of parallel regions and loops. You cannot modify the internal control variables at the application level but you can modify the variables using the environment variables or the appropriate OpenMP functions.
Internal Control Variables
The OpenMP specification defines the following internal control variables whose values affect the operation of parallel regions.
- nthreads-var—Stores the number of threads requested for future parallel regions.
- dyn-var—Controls whether dynamic adjustment of the number of threads used for future parallel regions is enabled.
Note LabWindows/CVI does not support dynamic adjustment of the number of threads. - nest-var—Controls whether nested parallelism is enabled for future parallel regions.
Note LabWindows/CVI does not support nested parallelism.
The OpenMP specification defines the following internal control variables whose values affect the operation of loops.
- run-sched-var—Stores scheduling information used for loop regions using the run-time schedule clause.
- def-sched-var—Stores implementation-defined default scheduling information for loop regions.
Environment Variables
The OpenMP specification provides the following environmental variables you can use to modify internal control variables.
- OMP_SCHEDULE—Sets the run-sched-var internal control variable for the run-time schedule type and chunk size.
- OMP_NUM_THREADS—Sets the nthreads-var internal control variable for the number of threads to use for parallel regions.
- OMP_DYNAMIC—Sets the dyn-var internal control variable for the dynamic adjustment
of threads to use for parallel regions.
Note LabWindows/CVI does not support dynamic adjustment of the number of threads. - OMP_NESTED—Sets the nest-var internal control variable to enable or disable nested
parallelism.
Note LabWindows/CVI does not support nested parallelism. - OMP_CVI_PROC_MSGS_MASTER—Specifies whether the master thread processes user interface operations within a parallel region. The default is FALSE.
Caution Whenever possible, using the default behavior is recommended. You should perform user interface operations only from the master thread or the thread that owns the user interface object. Use the master directive inside a parallel region to limit the user interface operations to the master thread.
In the event that you are unable to modify the source code or the above mechanism does not work, you can work around this issue by forcing the master thread to process the Windows message pump by setting the OMP_CVI_PROC_MSGS_MASTER environment variable to 1. Note that using this environment option should be done with caution; setting the variable can lead to unexpected reentrancy issues and because the environment variable affects the entire application, it can break code in ways that might not be immediately apparently. Refer to the Troubleshooting OpenMP Issues topic for more information about assigning user interface objects or operations to the master and worker threads.
Accessing Internal Control Variables
The following table displays how you can set or get the value of the internal control variables as well as the initial value of the variables.
Internal Control Variable | To Modify | To Retrieve | Initial Value | ||
---|---|---|---|---|---|
nthreads-var | OMP_NUM_THREADS omp_set_num_threads num_threads
| omp_get_max_threads | Number of processors on machine | ||
dyn-var | OMP_DYNAMIC omp_set_dynamic | omp_get_dynamic | FALSE | ||
nest-var | OMP_NESTED omp_set_nested | omp_get_nested | FALSE | ||
run-sched-var | OMP_SCHEDULE | none | static | ||
def-sched-var | none | none | static |
Override Relationships between Environment Variables, OpenMP Functions, and OpenMP Clauses
When you run an application, the internal control variables are set with their initial values before any OpenMP function or clause executes. You can override and modify the initial values, shown in the previous table, by setting the appropriate environment variable. You can override and modify the internal control value set by an environment variable by modifying the value with an OpenMP function call, such as omp_set_num_threads. Finally, you can use an OpenMP clause, such as num_threads to override the initial control variable value set by an OpenMP function call; however, an OpenMP clause does not permanently modify the internal control variable value. The following table displays the override precedence for internal control variable values.
OpenMP Clause | OpenMP Function | Environment Variable | Internal Control Variable Initial Value | ||
---|---|---|---|---|---|
num_threads![]() | omp_set_num_threads![]() | OMP_NUM_THREADS![]() | nthreads-var | ||
N/A![]() | omp_set_dynamic![]() | OMP_DYNAMIC![]() | dyn-var
| ||
N/A![]() | omp_set_nested![]() | OMP_NESTED![]() | nest-var
| ||
N/A![]() | N/A![]() | OMP_SCHEDULE![]() | run-sched-var | ||
schedule![]() | N/A![]() | N/A![]() | def-sched-var |
The image indicates override relationship; for example, the environment variable value overrides the internal control variable initial value and so on.