#pragma options [no]unroll, #pragma unroll
Controls loop unrolling, for improved performance.
When unroll is in effect, the optimizer determines and applies the best unrolling factor for each loop; in some cases, the loop control may be modified to avoid unnecessary branching. The compiler remains the final arbiter of whether the loop is actually unrolled. You can use the #pragma unroll directive to gain more control over unrolling.
Option syntax .-unroll--+-------------+-. | | .-auto-. | | | '-=--+-yes--+-' | | '-no---' | >>- -q--+-nounroll----------------+----------------------------><
Pragma syntax >>-#--pragma--+-nounroll-----------------+--------------------->< '-unroll--+--------------+-' '-(--number--)-'
-qunroll=auto
Specifying -qunroll without any suboptions is equivalent to -qunroll=yes.
-qnounroll is equivalent to -qunroll=no.
The pragma overrides the -q[no]unroll compiler option setting for a designated loop. However, even if #pragma unroll is specified for a given loop, the compiler remains the final arbiter of whether the loop is actually unrolled.
Only one pragma may be specified on a loop. The pragma must appear immediately before the loop or the #pragma block_loop directive to have effect.
The pragma affects only the loop that follows it. An inner nested loop requires a #pragma unroll directive to precede it if the desired loop unrolling strategy is different from that of the prevailing -q[no]unroll option.
The #pragma unroll and #pragma nounroll directives can only be used on for loops or #pragma block_loop directives. They cannot be applied to do while and while loops.
None.
#pragma unroll(3) for( i=0;i < n; i++) { a[i] = b[i] * c[i]; } #pragma unroll for( j=0;j < n; j++) { a[j] = b[j] * c[j]; }In this example, the first #pragma unroll(3) directive results in:
i=0; if (i>n-2) goto remainder; for (; i<n-2; i+=3) { a[i]=b[i] * c[i]; a[i+1]=b[i+1] * c[i+1]; a[i+2]=b[i+2] * c[i+2]; } if (i<n) { remainder: for (; i<n; i++) { a[i]=b[i] * c[i]; } }