# SetMode

Sets a new mode for VML functions according to mode parameter and stores the previous VML mode to oldmode.

## Syntax

Fortran:

oldmode = vmlsetmode( mode )

C:

oldmode = vmlSetMode( mode );

## Input Parameters

Name | Type | Description
--- | --- | ---
mode | FORTRAN: INTEGER, INTENT(IN) C: int | Specifies the VML mode to be set.

## Output Parameters

Name | Type | Description
--- | --- | ---
oldmode | FORTRAN: INTEGER C: int | Specifies the former VML mode.

## Description

The mode parameter is designed to control accuracy, FPU, error handling and threading options. Table “Values of the mode Parameter” lists values of the mode parameter. All other possible values of the mode parameter may be obtained from these values by using bitwise OR ( | ) operation to combine one value for accuracy, one for FPU, and one for error control options. The default value of the mode parameter is `VML_HA | VML_ERRMODE_DEFAULT | VML_NUM_THREADES_OMP_AUTO`. Thus, the current FPU control word (FPU precision and the rounding method) is used by default.

If any VML mathematical function requires different FPU precision, or rounding method, it changes these options automatically and then restores the former values. The mode parameter enables you to minimize switching the internal FPU mode inside each VML mathematical function that works with similar precision and accuracy settings. To accomplish this, set the mode parameter to VML_FLOAT_CONSISTENT for single precision real and complex functions, or to VML_DOUBLE_CONSISTENT for double precision real and complex functions. These values of the mode parameter are the optimal choice for the respective function groups, as they are required for most of the VML mathematical functions. After the execution is over, set the mode to VML_RESTORE if you need to restore the previous FPU mode.

Values of the mode Parameter
Value of mode | Description
--- | ---
Accuracy Control
VML_HA | High accuracy versions of VML functions will be used.
VML_LA | Low accuracy versions of VML functions will be used.
VML_EP | Enhanced Performance accuracy versions of VML functions will be used.
Additional FPU Mode Control
VML_FLOAT_CONSISTENT | The optimal FPU mode (control word) for single precision functions is set, and the previous FPU mode is saved.
VML_DOUBLE_CONSISTENT | The optimal FPU mode (control word) for double precision functions is set, and the previous FPU mode is saved.
VML_RESTORE | The previously saved FPU mode is restored.
Error Mode Control
VML_ERRMODE_IGNORE | No action is set for computation errors.
VML_ERRMODE_ERRNO | On error, the errno variable is set.
VML_ERRMODE_STDERR | On error, the error text information is written to stderr.
VML_ERRMODE_EXCEPT | On error, an exception is raised.
VML_ERRMODE_CALLBACK | On error, an additional error handler function is called.
VML_ERRMODE_DEFAULT | On error, the errno variable is set, an exception is raised, and an additional error handler function is called.
Treading Mode Control
VML_NUM_THREADS_OMP_AUTO | This is default behavior. Maximum number of threads is determined by environmental variable OMP_NUM_THREADS and can be overridden by OpenMP* function omp_set_num_threads(). For performance reasons VML threading logic can use fewer number of threads.
VML_NUM_THREADS_OMP_FIXED | Number of threads is determined by environmental variable OMP_NUM_THREADS and can be overridden by OpenMP* function omp_set_num_threads(). Use this mode to disable VML threading logic.

## Examples

Several examples of calling the function vmlSetMode() with different values of the mode parameter are given below:

Fortran:

  oldmode = vmlsetmode( VML_LA )

  call vmlsetmode( IOR(VML_LA, IOR(VML_FLOAT_CONSISTENT, VML_ERRMODE_IGNORE )))

  call vmlsetmode( VML_RESTORE)

  call vmlsetmode( VML_NUM_THREADS_OMP_FIXED)

C:

  vmlSetMode( VML_LA );

  vmlSetMode( VML_LA | VML_FLOAT_CONSISTENT | VML_ERRMODE_IGNORE );

  vmlSetMode( VML_RESTORE);

  vmlSetMode( VML_NUM_THREADS_OMP_FIXED);

Parent topic: VML Service Functions