real function sdot (n, sx, incx, sy, incy) C***BEGIN PROLOGUE SDOT C***PURPOSE Compute the inner product of two vectors. C***CATEGORY D1A4 C***TYPE SINGLE PRECISION (SDOT-S, DDOT-D, CDOTU-C) C***KEYWORDS BLAS, INNER PRODUCT, LINEAR ALGEBRA, VECTOR C***AUTHOR Lawson, C. L., (JPL) C Hanson, R. J., (SNLA) C Kincaid, D. R., (U. of Texas) C Krogh, F. T., (JPL) C***DESCRIPTION C C B L A S Subprogram C Description of Parameters C C --Input-- c n number of elements in input vector(s) c sx single precision vector with n elements c incx storage spacing between elements of sx c sy single precision vector with n elements c incy storage spacing between elements of sy C C --Output-- c sdot single precision dot product (zero if n .le. 0) C C Returns the dot product of single precision SX and SY. C SDOT = sum for I = 0 to N-1 of SX(LX+I*INCX) * SY(LY+I*INCY), C where LX = 1 if INCX .GE. 0, else LX = 1+(1-N)*INCX, and LY is C defined in a similar way using INCY. C C***REFERENCES C. L. Lawson, R. J. Hanson, D. R. Kincaid and F. T. C Krogh, Basic linear algebra subprograms for Fortran C usage, Algorithm No. 539, Transactions on Mathematical C Software 5, 3 (September 1979), pp. 308-323. C***ROUTINES CALLED (NONE) C***REVISION HISTORY (YYMMDD) C 791001 DATE WRITTEN C 890831 Modified array declarations. (WRB) C 890831 REVISION DATE from Version 3.2 C 891214 Prologue converted to Version 4.0 format. (BAB) C 920310 Corrected definition of LX in DESCRIPTION. (WRB) C 920501 Reformatted the REFERENCES section. (WRB) C 010807 Added specific declaration for all variables (FAF) C***END PROLOGUE SDOT real sx(*), sy(*) integer incy, incx, n, ix, iy, i, m, mp1, ns c***first executable statement sdot sdot = 0.0e0 if (n .le. 0) return if (incx .eq. incy) if (incx-1) 5,20,60 c c code for unequal or nonpositive increments. c 5 ix = 1 iy = 1 if (incx .lt. 0) ix = (-n+1)*incx + 1 if (incy .lt. 0) iy = (-n+1)*incy + 1 do 10 i = 1,n sdot = sdot + sx(ix)*sy(iy) ix = ix + incx iy = iy + incy 10 continue return c c code for both increments equal to 1. c c clean-up loop so remaining vector length is a multiple of 5. c 20 m = mod(n,5) if (m .eq. 0) go to 40 do 30 i = 1,m sdot = sdot + sx(i)*sy(i) 30 continue if (n .lt. 5) return 40 mp1 = m + 1 do 50 i = mp1,n,5 sdot = sdot + sx(i)*sy(i) + sx(i+1)*sy(i+1) + sx(i+2)*sy(i+2) + 1 sx(i+3)*sy(i+3) + sx(i+4)*sy(i+4) 50 continue return c c code for equal, positive, non-unit increments. c 60 ns = n*incx do 70 i = 1,ns,incx sdot = sdot + sx(i)*sy(i) 70 continue return end