sscal Subroutine

public subroutine sscal(n, sa, sx, incx)

Routine to scale a vector by a constant author: Jack Dongarra, Linpack author: P J Knight, CCFE, Culham Science Centre n : input integer : order of the matrix sx sa : input real array : constant multiplier sx(n*incx) : input/output real array : On entry, matrix to be scaled; On exit, the scaled matrix incx : input integer : interval in storage between sx array elements This routine scales a vector by a constant, using unrolled loops for increments equal to 1. !

Arguments

Type IntentOptional AttributesName
integer, intent(in) :: n
real(kind=dp), intent(in) :: sa
real(kind=dp), intent(inout), dimension(n*incx):: sx
integer, intent(in) :: incx

Contents

Source Code


Source Code

  subroutine sscal(n,sa,sx,incx)

    !! Routine to scale a vector by a constant
    !! author: Jack Dongarra, Linpack
    !! author: P J Knight, CCFE, Culham Science Centre
    !! n        : input integer : order of the matrix sx
    !! sa       : input real array : constant multiplier
    !! sx(n*incx) : input/output real array : On entry, matrix to be scaled;
    !! On exit, the scaled matrix
    !! incx     : input integer : interval in storage between sx array elements
    !! This routine scales a vector by a constant, using
    !! unrolled loops for increments equal to 1.
    !!     !
    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    implicit none

    !  Arguments

    integer, intent(in) :: n, incx
    real(dp), intent(in) :: sa
    real(dp), dimension(n*incx), intent(inout) :: sx

    !  Local variables

    integer :: i,ix,m,mp1

    ! !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

    if (n <= 0) return

    if (incx /= 1) then

       ix = 1
       if (incx < 0) ix = (-n+1)*incx + 1
       do i = 1,n
          sx(ix) = sa*sx(ix)
          ix = ix + incx
       end do

    else

       m = mod(n,5)
       if ( m /= 0 ) then
          do i = 1,m
             sx(i) = sa*sx(i)
          end do
          if (n < 5) return
       end if

       mp1 = m + 1
       do i = mp1,n,5
          sx(i)     = sa*sx(i)
          sx(i + 1) = sa*sx(i + 1)
          sx(i + 2) = sa*sx(i + 2)
          sx(i + 3) = sa*sx(i + 3)
          sx(i + 4) = sa*sx(i + 4)
       end do

    end if

  end subroutine sscal