SPMVM Function
Multiplies a sparse matrix and a dense vector.
enabled.
Usage
w = SPMVM( n, m, r, c, v )
Input Parameters
n—Number of rows in the matrix.
m—Double-precision vector of nonzero elements in the matrix, stored in row-major order. Each row of the matrix must have at least one non-zero entry.
r—Long-integer (n+1)-element vector of row pointers. The nonzero elements in the ith row of the matrix consist of m(r(i)) through m(r(i+1)–1).
c—Long-integer vector of column numbers. Each matrix element m(j) is in column c(j).
v—Double-precision dense vector to be multiplied by the matrix.
Returned Value
w—Double-precision dense vector which is the result of the multiplication.
Keywords
None.
Discussion
Sparse-matrix dense-vector multiplications represent nearly all the computational cost associated with iterative solvers for large sparse linear systems. Since these systems are generally quite large, double-precision is usually required for reasonable accuracy, so for this reason and to eliminate repeated data-type conversions in iterative processes, SPMVM requires double-precision for floating-point input and LONGs for integer input. SPMVM is multithreaded and uses a computationally efficient compressed-sparse-row (CSR) storage format.
Example
; Create a small dense matrix to model a sparse matrix.
a = [[0,7,0,0],[8,0,3,0],[0,2,0,5],[1,0,0,0],[0,6,0,4]]
PM, a
; PV-WAVE prints:
; 0 8 0 1 0
; 7 0 2 0 6
; 0 3 0 0 0
; 0 0 5 0 4
; number of rows
n = 4
; nonzeros in row-major order
m = DOUBLE([8, 1, 7, 2, 6, 3, 5, 4])
; row pointers
r = LONG([0, 2, 5, 6, 8])
; column numbers
c = LONG([1, 3, 0, 2, 4, 1, 2, 4])
; Create a dense vector to complete the data for the example.
v = DOUBLE([5, 4, 3, 2, 1])
; Now compute and print the result.
w = SPMVM(n, m, r, c, v)
PM, w
; PV-WAVE prints:
; 34.000000
; 47.000000
; 12.000000
; 19.000000
See Also