DSCAL scales a vector by a constant. uses unrolled loops for increment equal to 1.
Type | Intent | Optional | Attributes | Name | ||
---|---|---|---|---|---|---|
integer(kind=ip) | :: | n | ||||
real(kind=wp) | :: | da | ||||
real(kind=wp) | :: | dx(*) | ||||
integer(kind=ip) | :: | incx |
subroutine dscal(n, da, dx, incx) !! DSCAL scales a vector by a constant. !! uses unrolled loops for increment equal to 1. real(wp) :: da integer(ip) :: incx, n real(wp) :: dx(*) integer i, m, mp1, nincx if (n <= 0_ip .or. incx <= 0_ip) return if (incx == 1_ip) then ! code for increment equal to 1 ! clean-up loop m = mod(n, 5_ip) if (m /= 0_ip) then do i = 1_ip, m dx(i) = da*dx(i) end do if (n < 5_ip) return end if mp1 = m + 1_ip do i = mp1, n, 5_ip dx(i) = da*dx(i) dx(i + 1_ip) = da*dx(i + 1_ip) dx(i + 2_ip) = da*dx(i + 2_ip) dx(i + 3_ip) = da*dx(i + 3_ip) dx(i + 4_ip) = da*dx(i + 4_ip) end do else ! code for increment not equal to 1 nincx = n*incx do i = 1_ip, nincx, incx dx(i) = da*dx(i) end do end if end subroutine dscal