Admin Production ni-theme
Current Publication

OpenMP Internal Control Variables and Environment Variables

LabWindows/CVI

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 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 Note  LabWindows/CVI does not support nested parallelism.

The OpenMP specification defines the following internal control variables whose values affect the operation of loops.

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 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 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 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 VariableTo ModifyTo RetrieveInitial Value
nthreads-varOMP_NUM_THREADS
omp_set_num_threads
num_threads
Note Note  num_threads overrides the variable only for the parallel region in which you call it.
omp_get_max_threadsNumber of processors on machine
dyn-varOMP_DYNAMIC
omp_set_dynamic
omp_get_dynamicFALSE
nest-varOMP_NESTED
omp_set_nested
omp_get_nestedFALSE
run-sched-varOMP_SCHEDULEnonestatic
def-sched-varnonenonestatic

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 ClauseOpenMP FunctionEnvironment VariableInternal Control Variable Initial Value
num_threadsomp_set_num_threadsOMP_NUM_THREADSnthreads-var
N/Aomp_set_dynamicOMP_DYNAMICdyn-var
Note Note  LabWindows/CVI does not support dynamic adjustment of the number of threads.
N/Aomp_set_nestedOMP_NESTEDnest-var
Note Note  LabWindows/CVI does not support nested parallelism.
N/AN/AOMP_SCHEDULErun-sched-var
scheduleN/AN/Adef-sched-var

The image indicates override relationship; for example, the environment variable value overrides the internal control variable initial value and so on.