-
Notifications
You must be signed in to change notification settings - Fork 2
/
dgemv.f
261 lines (261 loc) · 7.31 KB
/
dgemv.f
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
SUBROUTINE DGEMV ( TRANS, M, N, ALPHA, A, LDA, X, INCX,
$ BETA, Y, INCY )
* .. SCALAR ARGUMENTS ..
DOUBLE PRECISION ALPHA, BETA
INTEGER INCX, INCY, LDA, M, N
CHARACTER*1 TRANS
* .. ARRAY ARGUMENTS ..
DOUBLE PRECISION A( LDA, * ), X( * ), Y( * )
* ..
*
* PURPOSE
* =======
*
* DGEMV PERFORMS ONE OF THE MATRIX-VECTOR OPERATIONS
*
* Y := ALPHA*A*X + BETA*Y, OR Y := ALPHA*A'*X + BETA*Y,
*
* WHERE ALPHA AND BETA ARE SCALARS, X AND Y ARE VECTORS AND A IS AN
* M BY N MATRIX.
*
* PARAMETERS
* ==========
*
* TRANS - CHARACTER*1.
* ON ENTRY, TRANS SPECIFIES THE OPERATION TO BE PERFORMED AS
* FOLLOWS:
*
* TRANS = 'N' OR 'N' Y := ALPHA*A*X + BETA*Y.
*
* TRANS = 'T' OR 'T' Y := ALPHA*A'*X + BETA*Y.
*
* TRANS = 'C' OR 'C' Y := ALPHA*A'*X + BETA*Y.
*
* UNCHANGED ON EXIT.
*
* M - INTEGER.
* ON ENTRY, M SPECIFIES THE NUMBER OF ROWS OF THE MATRIX A.
* M MUST BE AT LEAST ZERO.
* UNCHANGED ON EXIT.
*
* N - INTEGER.
* ON ENTRY, N SPECIFIES THE NUMBER OF COLUMNS OF THE MATRIX A.
* N MUST BE AT LEAST ZERO.
* UNCHANGED ON EXIT.
*
* ALPHA - DOUBLE PRECISION.
* ON ENTRY, ALPHA SPECIFIES THE SCALAR ALPHA.
* UNCHANGED ON EXIT.
*
* A - DOUBLE PRECISION ARRAY OF DIMENSION ( LDA, N ).
* BEFORE ENTRY, THE LEADING M BY N PART OF THE ARRAY A MUST
* CONTAIN THE MATRIX OF COEFFICIENTS.
* UNCHANGED ON EXIT.
*
* LDA - INTEGER.
* ON ENTRY, LDA SPECIFIES THE FIRST DIMENSION OF A AS DECLARED
* IN THE CALLING (SUB) PROGRAM. LDA MUST BE AT LEAST
* MAX( 1, M ).
* UNCHANGED ON EXIT.
*
* X - DOUBLE PRECISION ARRAY OF DIMENSION AT LEAST
* ( 1 + ( N - 1 )*ABS( INCX ) ) WHEN TRANS = 'N' OR 'N'
* AND AT LEAST
* ( 1 + ( M - 1 )*ABS( INCX ) ) OTHERWISE.
* BEFORE ENTRY, THE INCREMENTED ARRAY X MUST CONTAIN THE
* VECTOR X.
* UNCHANGED ON EXIT.
*
* INCX - INTEGER.
* ON ENTRY, INCX SPECIFIES THE INCREMENT FOR THE ELEMENTS OF
* X. INCX MUST NOT BE ZERO.
* UNCHANGED ON EXIT.
*
* BETA - DOUBLE PRECISION.
* ON ENTRY, BETA SPECIFIES THE SCALAR BETA. WHEN BETA IS
* SUPPLIED AS ZERO THEN Y NEED NOT BE SET ON INPUT.
* UNCHANGED ON EXIT.
*
* Y - DOUBLE PRECISION ARRAY OF DIMENSION AT LEAST
* ( 1 + ( M - 1 )*ABS( INCY ) ) WHEN TRANS = 'N' OR 'N'
* AND AT LEAST
* ( 1 + ( N - 1 )*ABS( INCY ) ) OTHERWISE.
* BEFORE ENTRY WITH BETA NON-ZERO, THE INCREMENTED ARRAY Y
* MUST CONTAIN THE VECTOR Y. ON EXIT, Y IS OVERWRITTEN BY THE
* UPDATED VECTOR Y.
*
* INCY - INTEGER.
* ON ENTRY, INCY SPECIFIES THE INCREMENT FOR THE ELEMENTS OF
* Y. INCY MUST NOT BE ZERO.
* UNCHANGED ON EXIT.
*
*
* LEVEL 2 BLAS ROUTINE.
*
* -- WRITTEN ON 22-OCTOBER-1986.
* JACK DONGARRA, ARGONNE NATIONAL LAB.
* JEREMY DU CROZ, NAG CENTRAL OFFICE.
* SVEN HAMMARLING, NAG CENTRAL OFFICE.
* RICHARD HANSON, SANDIA NATIONAL LABS.
*
*
* .. PARAMETERS ..
DOUBLE PRECISION ONE , ZERO
PARAMETER ( ONE = 1.0D+0, ZERO = 0.0D+0 )
* .. LOCAL SCALARS ..
DOUBLE PRECISION TEMP
INTEGER I, INFO, IX, IY, J, JX, JY, KX, KY, LENX, LENY
* .. EXTERNAL FUNCTIONS ..
LOGICAL LSAME
EXTERNAL LSAME
* .. EXTERNAL SUBROUTINES ..
EXTERNAL XERBLA
* .. INTRINSIC FUNCTIONS ..
INTRINSIC MAX
* ..
* .. EXECUTABLE STATEMENTS ..
*
* TEST THE INPUT PARAMETERS.
*
INFO = 0
IF ( .NOT.LSAME( TRANS, 'N' ).AND.
$ .NOT.LSAME( TRANS, 'T' ).AND.
$ .NOT.LSAME( TRANS, 'C' ) )THEN
INFO = 1
ELSE IF( M.LT.0 )THEN
INFO = 2
ELSE IF( N.LT.0 )THEN
INFO = 3
ELSE IF( LDA.LT.MAX( 1, M ) )THEN
INFO = 6
ELSE IF( INCX.EQ.0 )THEN
INFO = 8
ELSE IF( INCY.EQ.0 )THEN
INFO = 11
END IF
IF( INFO.NE.0 )THEN
CALL XERBLA( 'DGEMV ', INFO )
RETURN
END IF
*
* QUICK RETURN IF POSSIBLE.
*
IF( ( M.EQ.0 ).OR.( N.EQ.0 ).OR.
$ ( ( ALPHA.EQ.ZERO ).AND.( BETA.EQ.ONE ) ) )
$ RETURN
*
* SET LENX AND LENY, THE LENGTHS OF THE VECTORS X AND Y, AND SET
* UP THE START POINTS IN X AND Y.
*
IF( LSAME( TRANS, 'N' ) )THEN
LENX = N
LENY = M
ELSE
LENX = M
LENY = N
END IF
IF( INCX.GT.0 )THEN
KX = 1
ELSE
KX = 1 - ( LENX - 1 )*INCX
END IF
IF( INCY.GT.0 )THEN
KY = 1
ELSE
KY = 1 - ( LENY - 1 )*INCY
END IF
*
* START THE OPERATIONS. IN THIS VERSION THE ELEMENTS OF A ARE
* ACCESSED SEQUENTIALLY WITH ONE PASS THROUGH A.
*
* FIRST FORM Y := BETA*Y.
*
IF( BETA.NE.ONE )THEN
IF( INCY.EQ.1 )THEN
IF( BETA.EQ.ZERO )THEN
DO 10, I = 1, LENY
Y( I ) = ZERO
10 CONTINUE
ELSE
DO 20, I = 1, LENY
Y( I ) = BETA*Y( I )
20 CONTINUE
END IF
ELSE
IY = KY
IF( BETA.EQ.ZERO )THEN
DO 30, I = 1, LENY
Y( IY ) = ZERO
IY = IY + INCY
30 CONTINUE
ELSE
DO 40, I = 1, LENY
Y( IY ) = BETA*Y( IY )
IY = IY + INCY
40 CONTINUE
END IF
END IF
END IF
IF( ALPHA.EQ.ZERO )
$ RETURN
IF( LSAME( TRANS, 'N' ) )THEN
*
* FORM Y := ALPHA*A*X + Y.
*
JX = KX
IF( INCY.EQ.1 )THEN
DO 60, J = 1, N
IF( X( JX ).NE.ZERO )THEN
TEMP = ALPHA*X( JX )
DO 50, I = 1, M
Y( I ) = Y( I ) + TEMP*A( I, J )
50 CONTINUE
END IF
JX = JX + INCX
60 CONTINUE
ELSE
DO 80, J = 1, N
IF( X( JX ).NE.ZERO )THEN
TEMP = ALPHA*X( JX )
IY = KY
DO 70, I = 1, M
Y( IY ) = Y( IY ) + TEMP*A( I, J )
IY = IY + INCY
70 CONTINUE
END IF
JX = JX + INCX
80 CONTINUE
END IF
ELSE
*
* FORM Y := ALPHA*A'*X + Y.
*
JY = KY
IF( INCX.EQ.1 )THEN
DO 100, J = 1, N
TEMP = ZERO
DO 90, I = 1, M
TEMP = TEMP + A( I, J )*X( I )
90 CONTINUE
Y( JY ) = Y( JY ) + ALPHA*TEMP
JY = JY + INCY
100 CONTINUE
ELSE
DO 120, J = 1, N
TEMP = ZERO
IX = KX
DO 110, I = 1, M
TEMP = TEMP + A( I, J )*X( IX )
IX = IX + INCX
110 CONTINUE
Y( JY ) = Y( JY ) + ALPHA*TEMP
JY = JY + INCY
120 CONTINUE
END IF
END IF
*
RETURN
*
* END OF DGEMV .
*
END