# Diagnostic 15043: loop was not vectorized: nonstandard loop is not a vectorization candidate (Fortran)

Causes:

1. More than one exit point in the loop. A loop must have a single entry and a single exit point. Multiple exit points in a loop can cause this message.
2. An iteration count that is data dependent. The iteration count must be known at entry to the loop.
3. Loop contains a subroutine or function call that prevents vectorization.
4. Other complex control structures, for example, use of multiple GOTO statements.

Below are examples for the first three scenarios.

Examples:

```subroutine d_15043(a,b,c,n)
implicit none
real, intent(in ), dimension(n) :: a, b
real, intent(out), dimension(n) :: c
integer, intent(in)             :: n
integer                         :: i

do i=1,n
if(a(i).lt.0.) exit
c(i) = sqrt(a(i)) * b(i)
enddo
end subroutine d_15043
```

> ifort -c -vec-report2 d_15043.f90

d_15043.f90(8): (col. 3) remark: loop was not vectorized: nonstandard loop is not a vectorization candidate

```subroutine d_15043_2(a,b,c,n)
implicit none
real, intent(in ), dimension(n) :: a, b
real, intent(out), dimension(n) :: c
integer, intent(in)             :: n
integer                         :: i

i = 0
do while (a(i)>0.)
c(i) = sqrt(a(i)) * b(i)
i = i + 1
enddo

end subroutine d_15043_2
```

> ifort -c -vec-report2 d_15043_2.f90
d_15043_2.f90(9): (col. 3) remark: loop was not vectorized: nonstandard loop is not a vectorization candidate

```subroutine d_15043_3(a,b,c,n)
implicit none
real, intent(in ), dimension(n) :: a, b
real, intent(out), dimension(n) :: c
integer, intent(in)             :: n
integer                         :: i

do i=1,n
call my_sub(a(i),b(i),c(i))
enddo

end subroutine d_15043_3
```

> ifort -c -vec-report2 d_15043_3.f90

d_15043_3.f90(10): (col. 3) remark: loop was not vectorized: nonstandard loop is not a vectorization candidate

Resolution Status:

1. For the first example, modify the loop to have a single entry and a single exit point and ensure that the iteration count is constant and known on entry to the loop. For example, the loop is vectorizable if “exit” is replaced by “cycle”, though the behavior is different.

2. For the second example, try to replace the DO WHILE construct by a counted DO loop. For example:

```  do i=1,n
if(a(i).ge.0.) c(i) = sqrt(a(i)) * b(i)
enddo
```

​If necessary, the iteration count could be precomputed.

3. For the third example, either inline the subroutine, for example using interprocedural optimization, or convert it into a SIMD-enabled subroutine, for example by using the DECLARE SIMD feature of OpenMP 4.0.

### Back to the list of vectorization diagnostics for Intel Fortran

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