Product Version: Intel® Fortran Compiler 15.0 and above
Cause:
When a loop contains a conditional statement which controls the assignment of a scalar value AND the scalar value is referenced AFTER the loop exits. The vectorization report generated using Intel® Fortran Compiler's optimization and vectorization report options includes non-vectorized loop instance:
Windows* OS: /O2 /Qopt-report:2 /Qopt-report-phase:vec
Linux OS or OS X: -O2 -qopt-report2 -qopt-report-phase=vec
Example:
An example below will generate the following remark in optimization report:
subroutine f13379( a, b, n ) implicit none integer :: a(n), b(n), n integer :: i, x=10 !dir$ simd do i=1,n if( a(i) > 0 ) then x = i !...here is the conditional assignment end if b(i) = x end do !... reference the scalar outside of the loop write(*,*) "last value of x: ", x end subroutine f13379
ifort -c /O2 /Qopt-report:2 /Qopt-report-phase:vec /Qopt-report-file:stdout f13379.f90
Begin optimization report for: F13379
Report from: Vector optimizations [vec]
LOOP BEGIN at f13379.f90(8,1)
....
remark #13379: loop was not vectorized with "simd"
LOOP END
Resolution:
The reference of the scalar after the loop requires that the value coming out of the loop is "correct", meaning that the loop iterations were executed strictly in-order and sequentially. IF the scalar is NOT referenced outside of the loop, the compiler can can vectorize this loop since the order of that the iterations are evaluated does not matter - without reference outside the loop the final value of the scalar does not matter since it is no longer referenced.
Example
subroutine f13379( a, b, n ) implicit none integer :: a(n), b(n), n integer :: i, x=10 !dir$ simd do i=1,n if( a(i) > 0 ) then x = i !...here is the conditional assignment end if b(i) = x end do !... no reference to scalar X outside of the loop !... removed the WRITE statment for X end subroutine f13379
Begin optimization report for: F13379
Report from: Vector optimizations [vec]
LOOP BEGIN at f13379.f90(8,1)
f13379.f90(8,1):remark #15301: SIMD LOOP WAS VECTORIZED
LOOP END
See also:
Requirements for Vectorizable Loops
Vectorization and Optimization Reports