Quantcast
Channel: Intel Developer Zone Articles
Viewing all articles
Browse latest Browse all 3384

Diagnostic 15038: remark: loop was not vectorized: conditional assignment to a scalar (Fortran)

$
0
0

Causes:

1. A loop contains a conditional statement
2. The conditional statement is controlling the assignment of a scalar value.
3. The logic of the assignment is such that the value of the scalar at the end of execution of the loop depends on the loop executing iterations strictly in-order  AND
4. the scalar value is referenced AFTER the loop exits.

Below is an example:

Examples:

subroutine f15038( 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
b(i) = x
end subroutine f15038

ifort -c -vec-report2  f15038.f90
f15038.f90(10): (col. 6) remark: loop was not vectorized: conditional assignment to a scalar
f15038.f90(8): (col. 1) warning #13379: loop was not vectorized with "simd"

Resolution Status:

1. 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 f15038( 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
!..commented out b(i) = x
end subroutine f15038

> ifort -c -vec-report2 f15038.f90
f15038.f90(8): (col. 1) remark: SIMD LOOP WAS VECTORIZED

Back to the list of vectorization diagnostics for Intel Fortran

 


Viewing all articles
Browse latest Browse all 3384

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>