HP MLIB User's Guide Vol. 1 7th Ed.
140 HP MLIB User’s Guide
SSUM/DSUM/ISUM/CSUM/ZSUM Vector sum
INTEGER*8 n, incx
COMPLEX*8 s, CSUM, x(lenx)
s = CSUM(n, x, incx)
INTEGER*8 n, incx
COMPLEX*16 s, ZSUM, x(lenx)
s = ZSUM(n, x, incx)
Input n Number of elements of vector x to be used in the sum. If
n ≤ 0, the subprograms do not reference x.
x Array of length lenx = (n−1)×|incx|+1 containing the
n-vector x.
incx Increment for the array x. x is stored forward in array x
with increment |incx|; that is, x
i
is stored in
x((i−1)×|incx|+1).
Use incx = 1 if the vector x is stored contiguously in
array x; that is, if x
i
is stored in x(i). Refer to “BLAS
Indexing Conventions” in the introduction to this
chapter.
Output s If n ≤ 0, then s = 0. Otherwise, s is the sum of the
elements of x.
Fortran
Equivalent
REAL*4 FUNCTION SSUM (N, X,INCX)
REAL*4 X(*)
SSUM = 0.0
IF ( N .LE. 0 ) RETURN
IX = 1
INCXA = ABS ( INCX )
DO 10 I = 1, N
SSUM = SSUM + X(IX)
IX = IX + INCXA
10 CONTINUE
RETURN
END
Example Compute the sum of the elements of a REAL*8 vector x, where x is a vector 10
elements long stored in a one-dimensional array X of dimension 20.
INTEGER*4 N,INCX
REAL*8 S,X(20)
N = 10
INCX = 1
S = DSUM (N,X,INCX)