KTH framework for Nek5000 toolboxes; testing version  0.0.1
dsytrd.f
Go to the documentation of this file.
1  SUBROUTINE dsytrd( UPLO, N, A, LDA, D, E, TAU, WORK, LWORK, INFO )
2 *
3 * -- LAPACK routine (version 3.0) --
4 * Univ. of Tennessee, Univ. of California Berkeley, NAG Ltd.,
5 * Courant Institute, Argonne National Lab, and Rice University
6 * June 30, 1999
7 *
8 * .. Scalar Arguments ..
9  CHARACTER UPLO
10  INTEGER INFO, LDA, LWORK, N
11 * ..
12 * .. Array Arguments ..
13  DOUBLE PRECISION A( LDA, * ), D( * ), E( * ), TAU( * ),
14  $ WORK( * )
15 * ..
16 *
17 * Purpose
18 * =======
19 *
20 * DSYTRD reduces a real symmetric matrix A to real symmetric
21 * tridiagonal form T by an orthogonal similarity transformation:
22 * Q**T * A * Q = T.
23 *
24 * Arguments
25 * =========
26 *
27 * UPLO (input) CHARACTER*1
28 * = 'U': Upper triangle of A is stored;
29 * = 'L': Lower triangle of A is stored.
30 *
31 * N (input) INTEGER
32 * The order of the matrix A. N >= 0.
33 *
34 * A (input/output) DOUBLE PRECISION array, dimension (LDA,N)
35 * On entry, the symmetric matrix A. If UPLO = 'U', the leading
36 * N-by-N upper triangular part of A contains the upper
37 * triangular part of the matrix A, and the strictly lower
38 * triangular part of A is not referenced. If UPLO = 'L', the
39 * leading N-by-N lower triangular part of A contains the lower
40 * triangular part of the matrix A, and the strictly upper
41 * triangular part of A is not referenced.
42 * On exit, if UPLO = 'U', the diagonal and first superdiagonal
43 * of A are overwritten by the corresponding elements of the
44 * tridiagonal matrix T, and the elements above the first
45 * superdiagonal, with the array TAU, represent the orthogonal
46 * matrix Q as a product of elementary reflectors; if UPLO
47 * = 'L', the diagonal and first subdiagonal of A are over-
48 * written by the corresponding elements of the tridiagonal
49 * matrix T, and the elements below the first subdiagonal, with
50 * the array TAU, represent the orthogonal matrix Q as a product
51 * of elementary reflectors. See Further Details.
52 *
53 * LDA (input) INTEGER
54 * The leading dimension of the array A. LDA >= max(1,N).
55 *
56 * D (output) DOUBLE PRECISION array, dimension (N)
57 * The diagonal elements of the tridiagonal matrix T:
58 * D(i) = A(i,i).
59 *
60 * E (output) DOUBLE PRECISION array, dimension (N-1)
61 * The off-diagonal elements of the tridiagonal matrix T:
62 * E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
63 *
64 * TAU (output) DOUBLE PRECISION array, dimension (N-1)
65 * The scalar factors of the elementary reflectors (see Further
66 * Details).
67 *
68 * WORK (workspace/output) DOUBLE PRECISION array, dimension (LWORK)
69 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
70 *
71 * LWORK (input) INTEGER
72 * The dimension of the array WORK. LWORK >= 1.
73 * For optimum performance LWORK >= N*NB, where NB is the
74 * optimal blocksize.
75 *
76 * If LWORK = -1, then a workspace query is assumed; the routine
77 * only calculates the optimal size of the WORK array, returns
78 * this value as the first entry of the WORK array, and no error
79 * message related to LWORK is issued by XERBLA.
80 *
81 * INFO (output) INTEGER
82 * = 0: successful exit
83 * < 0: if INFO = -i, the i-th argument had an illegal value
84 *
85 * Further Details
86 * ===============
87 *
88 * If UPLO = 'U', the matrix Q is represented as a product of elementary
89 * reflectors
90 *
91 * Q = H(n-1) . . . H(2) H(1).
92 *
93 * Each H(i) has the form
94 *
95 * H(i) = I - tau * v * v'
96 *
97 * where tau is a real scalar, and v is a real vector with
98 * v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
99 * A(1:i-1,i+1), and tau in TAU(i).
100 *
101 * If UPLO = 'L', the matrix Q is represented as a product of elementary
102 * reflectors
103 *
104 * Q = H(1) H(2) . . . H(n-1).
105 *
106 * Each H(i) has the form
107 *
108 * H(i) = I - tau * v * v'
109 *
110 * where tau is a real scalar, and v is a real vector with
111 * v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
112 * and tau in TAU(i).
113 *
114 * The contents of A on exit are illustrated by the following examples
115 * with n = 5:
116 *
117 * if UPLO = 'U': if UPLO = 'L':
118 *
119 * ( d e v2 v3 v4 ) ( d )
120 * ( d e v3 v4 ) ( e d )
121 * ( d e v4 ) ( v1 e d )
122 * ( d e ) ( v1 v2 e d )
123 * ( d ) ( v1 v2 v3 e d )
124 *
125 * where d and e denote diagonal and off-diagonal elements of T, and vi
126 * denotes an element of the vector defining H(i).
127 *
128 * =====================================================================
129 *
130 * .. Parameters ..
131  DOUBLE PRECISION ONE
132  parameter( one = 1.0d+0 )
133 * ..
134 * .. Local Scalars ..
135  LOGICAL LQUERY, UPPER
136  INTEGER I, IINFO, IWS, J, KK, LDWORK, LWKOPT, NB,
137  $ NBMIN, NX
138 * ..
139 * .. External Subroutines ..
140  EXTERNAL dlatrd, dsyr2k, dsytd2, xerbla
141 * ..
142 * .. Intrinsic Functions ..
143  INTRINSIC max
144 * ..
145 * .. External Functions ..
146  LOGICAL LSAME
147  INTEGER ILAENV
148  EXTERNAL lsame, ilaenv
149 * ..
150 * .. Executable Statements ..
151 *
152 * Test the input parameters
153 *
154  info = 0
155  upper = lsame( uplo, 'U' )
156  lquery = ( lwork.EQ.-1 )
157  IF( .NOT.upper .AND. .NOT.lsame( uplo, 'L' ) ) THEN
158  info = -1
159  ELSE IF( n.LT.0 ) THEN
160  info = -2
161  ELSE IF( lda.LT.max( 1, n ) ) THEN
162  info = -4
163  ELSE IF( lwork.LT.1 .AND. .NOT.lquery ) THEN
164  info = -9
165  END IF
166 *
167  IF( info.EQ.0 ) THEN
168 *
169 * Determine the block size.
170 *
171  nb = ilaenv( 1, 'DSYTRD', uplo, n, -1, -1, -1 )
172  lwkopt = n*nb
173  work( 1 ) = lwkopt
174  END IF
175 *
176  IF( info.NE.0 ) THEN
177  CALL xerbla( 'DSYTRD', -info )
178  RETURN
179  ELSE IF( lquery ) THEN
180  RETURN
181  END IF
182 *
183 * Quick return if possible
184 *
185  IF( n.EQ.0 ) THEN
186  work( 1 ) = 1
187  RETURN
188  END IF
189 *
190  nx = n
191  iws = 1
192  IF( nb.GT.1 .AND. nb.LT.n ) THEN
193 *
194 * Determine when to cross over from blocked to unblocked code
195 * (last block is always handled by unblocked code).
196 *
197  nx = max( nb, ilaenv( 3, 'DSYTRD', uplo, n, -1, -1, -1 ) )
198  IF( nx.LT.n ) THEN
199 *
200 * Determine if workspace is large enough for blocked code.
201 *
202  ldwork = n
203  iws = ldwork*nb
204  IF( lwork.LT.iws ) THEN
205 *
206 * Not enough workspace to use optimal NB: determine the
207 * minimum value of NB, and reduce NB or force use of
208 * unblocked code by setting NX = N.
209 *
210  nb = max( lwork / ldwork, 1 )
211  nbmin = ilaenv( 2, 'DSYTRD', uplo, n, -1, -1, -1 )
212  IF( nb.LT.nbmin )
213  $ nx = n
214  END IF
215  ELSE
216  nx = n
217  END IF
218  ELSE
219  nb = 1
220  END IF
221 *
222  IF( upper ) THEN
223 *
224 * Reduce the upper triangle of A.
225 * Columns 1:kk are handled by the unblocked method.
226 *
227  kk = n - ( ( n-nx+nb-1 ) / nb )*nb
228  DO 20 i = n - nb + 1, kk + 1, -nb
229 *
230 * Reduce columns i:i+nb-1 to tridiagonal form and form the
231 * matrix W which is needed to update the unreduced part of
232 * the matrix
233 *
234  CALL dlatrd( uplo, i+nb-1, nb, a, lda, e, tau, work,
235  $ ldwork )
236 *
237 * Update the unreduced submatrix A(1:i-1,1:i-1), using an
238 * update of the form: A := A - V*W' - W*V'
239 *
240  CALL dsyr2k( uplo, 'No transpose', i-1, nb, -one, a( 1, i ),
241  $ lda, work, ldwork, one, a, lda )
242 *
243 * Copy superdiagonal elements back into A, and diagonal
244 * elements into D
245 *
246  DO 10 j = i, i + nb - 1
247  a( j-1, j ) = e( j-1 )
248  d( j ) = a( j, j )
249  10 CONTINUE
250  20 CONTINUE
251 *
252 * Use unblocked code to reduce the last or only block
253 *
254  CALL dsytd2( uplo, kk, a, lda, d, e, tau, iinfo )
255  ELSE
256 *
257 * Reduce the lower triangle of A
258 *
259  DO 40 i = 1, n - nx, nb
260 *
261 * Reduce columns i:i+nb-1 to tridiagonal form and form the
262 * matrix W which is needed to update the unreduced part of
263 * the matrix
264 *
265  CALL dlatrd( uplo, n-i+1, nb, a( i, i ), lda, e( i ),
266  $ tau( i ), work, ldwork )
267 *
268 * Update the unreduced submatrix A(i+ib:n,i+ib:n), using
269 * an update of the form: A := A - V*W' - W*V'
270 *
271  CALL dsyr2k( uplo, 'No transpose', n-i-nb+1, nb, -one,
272  $ a( i+nb, i ), lda, work( nb+1 ), ldwork, one,
273  $ a( i+nb, i+nb ), lda )
274 *
275 * Copy subdiagonal elements back into A, and diagonal
276 * elements into D
277 *
278  DO 30 j = i, i + nb - 1
279  a( j+1, j ) = e( j )
280  d( j ) = a( j, j )
281  30 CONTINUE
282  40 CONTINUE
283 *
284 * Use unblocked code to reduce the last or only block
285 *
286  CALL dsytd2( uplo, n-i+1, a( i, i ), lda, d( i ), e( i ),
287  $ tau( i ), iinfo )
288  END IF
289 *
290  work( 1 ) = lwkopt
291  RETURN
292 *
293 * End of DSYTRD
294 *
295  END
subroutine dlatrd(UPLO, N, NB, A, LDA, E, TAU, W, LDW)
Definition: dlatrd.f:2
subroutine dsyr2k(UPLO, TRANS, N, K, ALPHA, A, LDA, B, LDB, BETA, C, LDC)
Definition: dsyr2k.f:3
subroutine dsytd2(UPLO, N, A, LDA, D, E, TAU, INFO)
Definition: dsytd2.f:2
subroutine dsytrd(UPLO, N, A, LDA, D, E, TAU, WORK, LWORK, INFO)
Definition: dsytrd.f:2
subroutine xerbla(SRNAME, INFO)
Definition: xerbla.f:2