KTH framework for Nek5000 toolboxes; testing version  0.0.1
dlatrd.f
Go to the documentation of this file.
1  SUBROUTINE dlatrd( UPLO, N, NB, A, LDA, E, TAU, W, LDW )
2 *
3 * -- LAPACK auxiliary routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * October 31, 1992
7 *
8 * .. Scalar Arguments ..
9  CHARACTER UPLO
10  INTEGER LDA, LDW, N, NB
11 * ..
12 * .. Array Arguments ..
13  DOUBLE PRECISION A( LDA, * ), E( * ), TAU( * ), W( LDW, * )
14 * ..
15 *
16 * Purpose
17 * =======
18 *
19 * DLATRD reduces NB rows and columns of a real symmetric matrix A to
20 * symmetric tridiagonal form by an orthogonal similarity
21 * transformation Q' * A * Q, and returns the matrices V and W which are
22 * needed to apply the transformation to the unreduced part of A.
23 *
24 * If UPLO = 'U', DLATRD reduces the last NB rows and columns of a
25 * matrix, of which the upper triangle is supplied;
26 * if UPLO = 'L', DLATRD reduces the first NB rows and columns of a
27 * matrix, of which the lower triangle is supplied.
28 *
29 * This is an auxiliary routine called by DSYTRD.
30 *
31 * Arguments
32 * =========
33 *
34 * UPLO (input) CHARACTER
35 * Specifies whether the upper or lower triangular part of the
36 * symmetric matrix A is stored:
37 * = 'U': Upper triangular
38 * = 'L': Lower triangular
39 *
40 * N (input) INTEGER
41 * The order of the matrix A.
42 *
43 * NB (input) INTEGER
44 * The number of rows and columns to be reduced.
45 *
46 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
47 * On entry, the symmetric matrix A. If UPLO = 'U', the leading
48 * n-by-n upper triangular part of A contains the upper
49 * triangular part of the matrix A, and the strictly lower
50 * triangular part of A is not referenced. If UPLO = 'L', the
51 * leading n-by-n lower triangular part of A contains the lower
52 * triangular part of the matrix A, and the strictly upper
53 * triangular part of A is not referenced.
54 * On exit:
55 * if UPLO = 'U', the last NB columns have been reduced to
56 * tridiagonal form, with the diagonal elements overwriting
57 * the diagonal elements of A; the elements above the diagonal
58 * with the array TAU, represent the orthogonal matrix Q as a
59 * product of elementary reflectors;
60 * if UPLO = 'L', the first NB columns have been reduced to
61 * tridiagonal form, with the diagonal elements overwriting
62 * the diagonal elements of A; the elements below the diagonal
63 * with the array TAU, represent the orthogonal matrix Q as a
64 * product of elementary reflectors.
65 * See Further Details.
66 *
67 * LDA (input) INTEGER
68 * The leading dimension of the array A. LDA >= (1,N).
69 *
70 * E (output) DOUBLE PRECISION array, dimension (N-1)
71 * If UPLO = 'U', E(n-nb:n-1) contains the superdiagonal
72 * elements of the last NB columns of the reduced matrix;
73 * if UPLO = 'L', E(1:nb) contains the subdiagonal elements of
74 * the first NB columns of the reduced matrix.
75 *
76 * TAU (output) DOUBLE PRECISION array, dimension (N-1)
77 * The scalar factors of the elementary reflectors, stored in
78 * TAU(n-nb:n-1) if UPLO = 'U', and in TAU(1:nb) if UPLO = 'L'.
79 * See Further Details.
80 *
81 * W (output) DOUBLE PRECISION array, dimension (LDW,NB)
82 * The n-by-nb matrix W required to update the unreduced part
83 * of A.
84 *
85 * LDW (input) INTEGER
86 * The leading dimension of the array W. LDW >= max(1,N).
87 *
88 * Further Details
89 * ===============
90 *
91 * If UPLO = 'U', the matrix Q is represented as a product of elementary
92 * reflectors
93 *
94 * Q = H(n) H(n-1) . . . H(n-nb+1).
95 *
96 * Each H(i) has the form
97 *
98 * H(i) = I - tau * v * v'
99 *
100 * where tau is a real scalar, and v is a real vector with
101 * v(i:n) = 0 and v(i-1) = 1; v(1:i-1) is stored on exit in A(1:i-1,i),
102 * and tau in TAU(i-1).
103 *
104 * If UPLO = 'L', the matrix Q is represented as a product of elementary
105 * reflectors
106 *
107 * Q = H(1) H(2) . . . H(nb).
108 *
109 * Each H(i) has the form
110 *
111 * H(i) = I - tau * v * v'
112 *
113 * where tau is a real scalar, and v is a real vector with
114 * v(1:i) = 0 and v(i+1) = 1; v(i+1:n) is stored on exit in A(i+1:n,i),
115 * and tau in TAU(i).
116 *
117 * The elements of the vectors v together form the n-by-nb matrix V
118 * which is needed, with W, to apply the transformation to the unreduced
119 * part of the matrix, using a symmetric rank-2k update of the form:
120 * A := A - V*W' - W*V'.
121 *
122 * The contents of A on exit are illustrated by the following examples
123 * with n = 5 and nb = 2:
124 *
125 * if UPLO = 'U': if UPLO = 'L':
126 *
127 * ( a a a v4 v5 ) ( d )
128 * ( a a v4 v5 ) ( 1 d )
129 * ( a 1 v5 ) ( v1 1 a )
130 * ( d 1 ) ( v1 v2 a a )
131 * ( d ) ( v1 v2 a a a )
132 *
133 * where d denotes a diagonal element of the reduced matrix, a denotes
134 * an element of the original matrix that is unchanged, and vi denotes
135 * an element of the vector defining H(i).
136 *
137 * =====================================================================
138 *
139 * .. Parameters ..
140  DOUBLE PRECISION ZERO, ONE, HALF
141  parameter( zero = 0.0d+0, one = 1.0d+0, half = 0.5d+0 )
142 * ..
143 * .. Local Scalars ..
144  INTEGER I, IW
145  DOUBLE PRECISION ALPHA
146 * ..
147 * .. External Subroutines ..
148  EXTERNAL daxpy, dgemv, dlarfg, dscal, dsymv
149 * ..
150 * .. External Functions ..
151  LOGICAL LSAME
152  DOUBLE PRECISION DDOT
153  EXTERNAL lsame, ddot
154 * ..
155 * .. Intrinsic Functions ..
156  INTRINSIC min
157 * ..
158 * .. Executable Statements ..
159 *
160 * Quick return if possible
161 *
162  IF( n.LE.0 )
163  $ RETURN
164 *
165  IF( lsame( uplo, 'U' ) ) THEN
166 *
167 * Reduce last NB columns of upper triangle
168 *
169  DO 10 i = n, n - nb + 1, -1
170  iw = i - n + nb
171  IF( i.LT.n ) THEN
172 *
173 * Update A(1:i,i)
174 *
175  CALL dgemv( 'No transpose', i, n-i, -one, a( 1, i+1 ),
176  $ lda, w( i, iw+1 ), ldw, one, a( 1, i ), 1 )
177  CALL dgemv( 'No transpose', i, n-i, -one, w( 1, iw+1 ),
178  $ ldw, a( i, i+1 ), lda, one, a( 1, i ), 1 )
179  END IF
180  IF( i.GT.1 ) THEN
181 *
182 * Generate elementary reflector H(i) to annihilate
183 * A(1:i-2,i)
184 *
185  CALL dlarfg( i-1, a( i-1, i ), a( 1, i ), 1, tau( i-1 ) )
186  e( i-1 ) = a( i-1, i )
187  a( i-1, i ) = one
188 *
189 * Compute W(1:i-1,i)
190 *
191  CALL dsymv( 'Upper', i-1, one, a, lda, a( 1, i ), 1,
192  $ zero, w( 1, iw ), 1 )
193  IF( i.LT.n ) THEN
194  CALL dgemv( 'Transpose', i-1, n-i, one, w( 1, iw+1 ),
195  $ ldw, a( 1, i ), 1, zero, w( i+1, iw ), 1 )
196  CALL dgemv( 'No transpose', i-1, n-i, -one,
197  $ a( 1, i+1 ), lda, w( i+1, iw ), 1, one,
198  $ w( 1, iw ), 1 )
199  CALL dgemv( 'Transpose', i-1, n-i, one, a( 1, i+1 ),
200  $ lda, a( 1, i ), 1, zero, w( i+1, iw ), 1 )
201  CALL dgemv( 'No transpose', i-1, n-i, -one,
202  $ w( 1, iw+1 ), ldw, w( i+1, iw ), 1, one,
203  $ w( 1, iw ), 1 )
204  END IF
205  CALL dscal( i-1, tau( i-1 ), w( 1, iw ), 1 )
206  alpha = -half*tau( i-1 )*ddot( i-1, w( 1, iw ), 1,
207  $ a( 1, i ), 1 )
208  CALL daxpy( i-1, alpha, a( 1, i ), 1, w( 1, iw ), 1 )
209  END IF
210 *
211  10 CONTINUE
212  ELSE
213 *
214 * Reduce first NB columns of lower triangle
215 *
216  DO 20 i = 1, nb
217 *
218 * Update A(i:n,i)
219 *
220  CALL dgemv( 'No transpose', n-i+1, i-1, -one, a( i, 1 ),
221  $ lda, w( i, 1 ), ldw, one, a( i, i ), 1 )
222  CALL dgemv( 'No transpose', n-i+1, i-1, -one, w( i, 1 ),
223  $ ldw, a( i, 1 ), lda, one, a( i, i ), 1 )
224  IF( i.LT.n ) THEN
225 *
226 * Generate elementary reflector H(i) to annihilate
227 * A(i+2:n,i)
228 *
229  CALL dlarfg( n-i, a( i+1, i ), a( min( i+2, n ), i ), 1,
230  $ tau( i ) )
231  e( i ) = a( i+1, i )
232  a( i+1, i ) = one
233 *
234 * Compute W(i+1:n,i)
235 *
236  CALL dsymv( 'Lower', n-i, one, a( i+1, i+1 ), lda,
237  $ a( i+1, i ), 1, zero, w( i+1, i ), 1 )
238  CALL dgemv( 'Transpose', n-i, i-1, one, w( i+1, 1 ), ldw,
239  $ a( i+1, i ), 1, zero, w( 1, i ), 1 )
240  CALL dgemv( 'No transpose', n-i, i-1, -one, a( i+1, 1 ),
241  $ lda, w( 1, i ), 1, one, w( i+1, i ), 1 )
242  CALL dgemv( 'Transpose', n-i, i-1, one, a( i+1, 1 ), lda,
243  $ a( i+1, i ), 1, zero, w( 1, i ), 1 )
244  CALL dgemv( 'No transpose', n-i, i-1, -one, w( i+1, 1 ),
245  $ ldw, w( 1, i ), 1, one, w( i+1, i ), 1 )
246  CALL dscal( n-i, tau( i ), w( i+1, i ), 1 )
247  alpha = -half*tau( i )*ddot( n-i, w( i+1, i ), 1,
248  $ a( i+1, i ), 1 )
249  CALL daxpy( n-i, alpha, a( i+1, i ), 1, w( i+1, i ), 1 )
250  END IF
251 *
252  20 CONTINUE
253  END IF
254 *
255  RETURN
256 *
257 * End of DLATRD
258 *
259  END
subroutine daxpy(n, da, dx, incx, dy, incy)
Definition: daxpy.f:2
subroutine dgemv(TRANS, M, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
Definition: dgemv.f:3
subroutine dlarfg(N, ALPHA, X, INCX, TAU)
Definition: dlarfg.f:2
subroutine dlatrd(UPLO, N, NB, A, LDA, E, TAU, W, LDW)
Definition: dlatrd.f:2
subroutine dscal(n, da, dx, incx)
Definition: dscal.f:2
subroutine dsymv(UPLO, N, ALPHA, A, LDA, X, INCX, BETA, Y, INCY)
Definition: dsymv.f:3