EVSL  1.1.0 EigenValues Slicing Library
csr_module.f90
Go to the documentation of this file.
1 module csrmatrix
2
3  ! This module contains a simple CSR matrix storage type and an associated
4  ! matvec routine to accompany it.
5
6  ! This is used to demonstrate usage of the matrix free version of EVSL from
7  ! Fortran
8
9  type csrmat
10  integer :: nrows ! Number of rows in the matrix
11  integer :: ncols ! Number of cols in the matrix
12  integer :: nnz ! Number of nonzero entries in the matrix
13
14  integer, dimension(:), pointer :: ia ! The row map
15  integer, dimension(:), pointer :: ja ! The column indices
16  double precision, dimension(:), pointer :: a ! The values in the matrix
17  end type csrmat
18
19 contains
20  ! This will perform a matrix vector multiplication Ax = y
21  subroutine csrmatvec(x, y, mat)
22  ! Determine the inputs
23  type(csrmat) :: mat
24  double precision, dimension(mat%nrows), intent(in) :: x
25  double precision, dimension(mat%nrows), intent(out) :: y
26
27  ! Information to parse the matrix
28  integer :: row, col, i, j, s, e
29
30  ! For safety, parse the y vector and set entries to 0
31  do i = 1, mat % nrows
32  y(i) = 0
33  enddo
34
35  ! For each row perform the matvec
36  do i = 1, mat % nrows
37  s = mat%ia(i)
38  e = mat%ia(i+1)
39  do j = s, e-1
40  col = mat%ja(j)
41  y(i) = y(i) + mat%a(j) * x(col)
42  enddo
43  enddo
44  end subroutine csrmatvec
45 end module csrmatrix
subroutine csrmatvec(x, y, mat)
Definition: csr_module.f90:21