#pragma unroll

Description

The #pragma unroll directive is used to unroll the innermost or outermost for loops in your program, which can help improve program performance.

Syntax

Read syntax diagramSkip visual syntax diagram>>-#--pragma--+-nounroll------------+--------------------------><
              '-unroll--(--+---+--)-'
                           '-n-'

where n is the loop unrolling factor. In C programs, the value of n is a positive integral constant expression. In C++ programs, the value of n is a positive scalar integer or compile-time constant initialization expression. An unroll factor of 1 disables unrolling. If n is not specified and if -qhot, -qsmp, or -O4 or higher is specified, the optimizer determines an appropriate unrolling factor for each nested loop.

Notes

The #pragma unroll and #pragma nounroll directives can only be used on for loops or a block_loop directive. It cannot be applied to do-while and while loops.

The #pragma unroll and #pragma nounroll directives must appear immediately before the loop or the block_loop directive to be affected.

Only one of these directives can be specified for a given loop. The loop structure must meet the following conditions:

Specifying #pragma nounroll for a loop instructs the compiler to not unroll that loop. Specifying #pragma unroll(1) has the same effect.

To see if the unroll option improves performance of a particular application, you should first compile the program with usual options, then run it with a representative workload. You should then recompile with command line -qunroll option and/or the unroll pragmas enabled, then rerun the program under the same conditions to see if performance improves.

Examples

Related information