Diagnostic 15316: simd loop was not vectorized: scalar assignment in simd loop is prohibited, consider private, lastprivate or reduction clauses

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, intent(in)               :: n
  integer, intent(in),  dimension(n) :: a
  integer, intent(out),dimension(n) :: b
   
  integer                           :: i, x=10  
   
!$omp simd  
  do i=1,n  
    if( a(i) > 0 ) then 
     x = i                    !...here is the scalar 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-report2 -qopenmp-simd -qopt-report-file=stderr -qopt-report-phase=vec f13379.f90

When using Intel Fortran Compiler version 16.0 the following remark is generated:

LOOP BEGIN at f13379.f90(8,3)

   remark #15336: simd loop was not vectorized: conditional assignment to a scalar   [ f13379.f90(10,8) ]

   remark #13379: loop was not vectorized with "simd"

LOOP END

When using Intel Fortran Compiler version 17.0 the following remark is generated:

LOOP BEGIN at  f15336.f90(12,3)
   remark #15316: simd loop was not vectorized: scalar assignment in simd loop is prohibited, consider private, lastprivate or reduction clauses  f15336.f90(10,6)
   remark #15552: loop was not vectorized with "simd"
LOOP END

Resolution:

Using !$omp simd lastprivate(x)  instead of !$omp simd will have x initialized for each subroutine in executable code.

Example

subroutine f13379( a, b, n )  
  implicit none 
  integer, intent(in)               :: n
  integer, intent(in),  dimension(n) :: a
  integer, intent(out),dimension(n) :: b
   
  integer                           :: i, x=10  
   
!$omp simd lastprivate(x)  
  do i=1,n  
    if( a(i) > 0 ) then 
     x = i                    !...here is the scalar 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-report2 -qopenmp-simd -qopt-report-file=stderr -qopt-report-phase=vec f13379.f90


Begin optimization report for: F13379

    Report from: Vector optimizations [vec]

LOOP BEGIN at f13379.f90(10,3)
   remark #15301: OpenMP SIMD LOOP WAS VECTORIZED
LOOP END

See also:

Requirements for Vectorizable Loops

Vectorization Essentials

Vectorization and Optimization Reports

Back to the list of vectorization diagnostics for Intel® Fortran

 

For more complete information about compiler optimizations, see our Optimization Notice.