RWalib C Array Library User Guide > Linear Algebra > alibSpMVM
  

alibSpMVM
Returns the product of a CSR-sparse matrix and a dense vector. The PV-WAVE API for this routine is the SPMVM Function.
Prototype
void alibSpMVMd( wvlong n, wvlong p, wvlong *r, wvlong *c, double *m, double *v, double *w )
Parameters
n — (Input) The number of rows in the sparse matrix.
p — (Input) The number of nonzero entries in the sparse matrix.
*r — (Input) The (n+1)-element array of indices to the start of each row. If the nonzero entries of the sparse matrix are stored in array m, the nonzero entries in the jth row are elements m[r[j]] through m[r[j+1]–1]. Note that the first and last entries in array r are always 0 and p, respectively.
*c — (Input) The p-element array of column numbers. If the nonzero entries of the sparse matrix are stored in array m, c[j] is the column number of m[j].
*m — (Input) The p-element array of nonzero entries in the sparse matrix.
*v — (Input) The dense vector to be multiplied by the sparse matrix.
*w — (Input/Output) The n-element destination array. On return, array w contains the product of the sparse matrix times the dense vector.
Example
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "alib.h"
void main() {
   /* consider for example the (4,5) sparse matrix */
   /*    0  8  0  1  0
   /*    7  0  2  0  6
   /*    0  3  0  0  0
   /*    0  0  5  0  4
   /* the array of nonzero entries is */
   double m[8] = { 8, 1, 7, 2, 6, 3, 5, 4 };
   /* the row pointers are */
   wvlong r[5] = { 0, 2, 5, 6, 8 };
   /* the column numbers are */
   wvlong c[8] = { 1, 3, 0, 2, 4, 1, 2, 4 };
   /* the dense vector to be multiplied is for example */
   double v[5] = { 5, 4, 3, 2, 1 };
   /* compute and print the result */
   double w[4];
   alibinit( NULL, NULL, NULL, NULL );
   alibSpMVMd( 4, 8, r, c, m, v, w );
   alibPrintArrayd( 1, 1, 4, 1, w, NULL );
}
 
Output:
 
   3.4000000e+01
   4.7000000e+01
   1.2000000e+01
   1.9000000e+01

Version 2017.0
Copyright © 2017, Rogue Wave Software, Inc. All Rights Reserved.