-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathaprod.f90
60 lines (43 loc) · 1.26 KB
/
aprod.f90
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
!c--- This file is from hypoDD by Felix Waldhauser ---------
!c-------------------------Modified by Haijiang Zhang-------
!c Multiply a matrix by a vector
!c Version for use with sparse matrix specified by
!c output of subroutine sparse for use with LSQR
subroutine aprod(mode, m, n, x, y, leniw, lenrw, iw, rw)
implicit none
!c Parameters:
integer mode ! ==1: Compute y = y + a*x
! y is altered without changing x
! ==2: Compute x = x + a(transpose)*y
! x is altered without changing y
integer m, n ! Row and column dimensions of a
real x(n), y(m) ! Input vectors
integer :: leniw
integer lenrw
integer iw(leniw) ! Integer work vector containing:
! iw[1] Number of non-zero elements in a
! iw[2:iw[1]+1] Row indices of non-zero elements
! iw[iw[1]+2:2*iw[1]+1] Column indices
real rw(lenrw) ! [1..iw[1]] Non-zero elements of a
!c Local variables:
integer i1
integer j1
integer k
integer kk
!c set the ranges the indices in vector iw
kk=iw(1)
i1=1
j1=kk+1
!c main iteration loop
do k = 1,kk
if (mode.eq.1) then
!c compute y = y + a*x
y(iw(i1+k)) = y(iw(i1+k)) + rw(k)*x(iw(j1+k))
else
!c compute x = x + a(transpose)*y
x(iw(j1+k)) = x(iw(j1+k)) + rw(k)*y(iw(i1+k))
endif
enddo
! 100 continue
return
end