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 |
|
| |
| incx | Increment for the array x. x is stored forward in array x |
|
| with increment incx; that is, xi is stored in |
|
| x((i−1)⋅incx+1). |
|
| Use incx = 1 if the vector x is stored contiguously in |
|
| array x; that is, if xi 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 | REAL*4 FUNCTION SSUM (N, X,INCX) | |
Equivalent | 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
INTEGER*4 | N,INCX | |
REAL*8 | S,X(20) | |
N = | 10 |
|
INCX = 1 |
| |
S = | DSUM (N,X,INCX) |
140HP MLIB User’s Guide