3
* =========== DOCUMENTATION ===========
5
* Online html documentation available at
6
* http://www.netlib.org/lapack/explore-html/
9
*> Download DSTEDC + dependencies
10
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dstedc.f">
12
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dstedc.f">
14
*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dstedc.f">
21
* SUBROUTINE DSTEDC( COMPZ, N, D, E, Z, LDZ, WORK, LWORK, IWORK,
24
* .. Scalar Arguments ..
26
* INTEGER INFO, LDZ, LIWORK, LWORK, N
28
* .. Array Arguments ..
30
* DOUBLE PRECISION D( * ), E( * ), WORK( * ), Z( LDZ, * )
39
*> DSTEDC computes all eigenvalues and, optionally, eigenvectors of a
40
*> symmetric tridiagonal matrix using the divide and conquer method.
41
*> The eigenvectors of a full or band real symmetric matrix can also be
42
*> found if DSYTRD or DSPTRD or DSBTRD has been used to reduce this
43
*> matrix to tridiagonal form.
45
*> This code makes very mild assumptions about floating point
46
*> arithmetic. It will work on machines with a guard digit in
47
*> add/subtract, or on those binary machines without guard digits
48
*> which subtract like the Cray X-MP, Cray Y-MP, Cray C-90, or Cray-2.
49
*> It could conceivably fail on hexadecimal or decimal machines
50
*> without guard digits, but we know of none. See DLAED3 for details.
58
*> COMPZ is CHARACTER*1
59
*> = 'N': Compute eigenvalues only.
60
*> = 'I': Compute eigenvectors of tridiagonal matrix also.
61
*> = 'V': Compute eigenvectors of original dense symmetric
62
*> matrix also. On entry, Z contains the orthogonal
63
*> matrix used to reduce the original matrix to
70
*> The dimension of the symmetric tridiagonal matrix. N >= 0.
75
*> D is DOUBLE PRECISION array, dimension (N)
76
*> On entry, the diagonal elements of the tridiagonal matrix.
77
*> On exit, if INFO = 0, the eigenvalues in ascending order.
82
*> E is DOUBLE PRECISION array, dimension (N-1)
83
*> On entry, the subdiagonal elements of the tridiagonal matrix.
84
*> On exit, E has been destroyed.
89
*> Z is DOUBLE PRECISION array, dimension (LDZ,N)
90
*> On entry, if COMPZ = 'V', then Z contains the orthogonal
91
*> matrix used in the reduction to tridiagonal form.
92
*> On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
93
*> orthonormal eigenvectors of the original symmetric matrix,
94
*> and if COMPZ = 'I', Z contains the orthonormal eigenvectors
95
*> of the symmetric tridiagonal matrix.
96
*> If COMPZ = 'N', then Z is not referenced.
102
*> The leading dimension of the array Z. LDZ >= 1.
103
*> If eigenvectors are desired, then LDZ >= max(1,N).
108
*> WORK is DOUBLE PRECISION array,
110
*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
116
*> The dimension of the array WORK.
117
*> If COMPZ = 'N' or N <= 1 then LWORK must be at least 1.
118
*> If COMPZ = 'V' and N > 1 then LWORK must be at least
119
*> ( 1 + 3*N + 2*N*lg N + 4*N**2 ),
120
*> where lg( N ) = smallest integer k such
122
*> If COMPZ = 'I' and N > 1 then LWORK must be at least
123
*> ( 1 + 4*N + N**2 ).
124
*> Note that for COMPZ = 'I' or 'V', then if N is less than or
125
*> equal to the minimum divide size, usually 25, then LWORK need
126
*> only be max(1,2*(N-1)).
128
*> If LWORK = -1, then a workspace query is assumed; the routine
129
*> only calculates the optimal size of the WORK array, returns
130
*> this value as the first entry of the WORK array, and no error
131
*> message related to LWORK is issued by XERBLA.
136
*> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
137
*> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
143
*> The dimension of the array IWORK.
144
*> If COMPZ = 'N' or N <= 1 then LIWORK must be at least 1.
145
*> If COMPZ = 'V' and N > 1 then LIWORK must be at least
146
*> ( 6 + 6*N + 5*N*lg N ).
147
*> If COMPZ = 'I' and N > 1 then LIWORK must be at least
149
*> Note that for COMPZ = 'I' or 'V', then if N is less than or
150
*> equal to the minimum divide size, usually 25, then LIWORK
153
*> If LIWORK = -1, then a workspace query is assumed; the
154
*> routine only calculates the optimal size of the IWORK array,
155
*> returns this value as the first entry of the IWORK array, and
156
*> no error message related to LIWORK is issued by XERBLA.
162
*> = 0: successful exit.
163
*> < 0: if INFO = -i, the i-th argument had an illegal value.
164
*> > 0: The algorithm failed to compute an eigenvalue while
165
*> working on the submatrix lying in rows and columns
166
*> INFO/(N+1) through mod(INFO,N+1).
172
*> \author Univ. of Tennessee
173
*> \author Univ. of California Berkeley
174
*> \author Univ. of Colorado Denver
177
*> \date November 2011
179
*> \ingroup auxOTHERcomputational
181
*> \par Contributors:
184
*> Jeff Rutter, Computer Science Division, University of California
185
*> at Berkeley, USA \n
186
*> Modified by Francoise Tisseur, University of Tennessee
188
* =====================================================================
189
SUBROUTINE DSTEDC( COMPZ, N, D, E, Z, LDZ, WORK, LWORK, IWORK,
192
* -- LAPACK computational routine (version 3.4.0) --
193
* -- LAPACK is a software package provided by Univ. of Tennessee, --
194
* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
197
* .. Scalar Arguments ..
199
INTEGER INFO, LDZ, LIWORK, LWORK, N
201
* .. Array Arguments ..
203
DOUBLE PRECISION D( * ), E( * ), WORK( * ), Z( LDZ, * )
206
* =====================================================================
209
DOUBLE PRECISION ZERO, ONE, TWO
210
PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )
212
* .. Local Scalars ..
214
INTEGER FINISH, I, ICOMPZ, II, J, K, LGN, LIWMIN,
215
$ LWMIN, M, SMLSIZ, START, STOREZ, STRTRW
216
DOUBLE PRECISION EPS, ORGNRM, P, TINY
218
* .. External Functions ..
221
DOUBLE PRECISION DLAMCH, DLANST
222
EXTERNAL LSAME, ILAENV, DLAMCH, DLANST
224
* .. External Subroutines ..
225
EXTERNAL DGEMM, DLACPY, DLAED0, DLASCL, DLASET, DLASRT,
226
$ DSTEQR, DSTERF, DSWAP, XERBLA
228
* .. Intrinsic Functions ..
229
INTRINSIC ABS, DBLE, INT, LOG, MAX, MOD, SQRT
231
* .. Executable Statements ..
233
* Test the input parameters.
236
LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
238
IF( LSAME( COMPZ, 'N' ) ) THEN
240
ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
242
ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
247
IF( ICOMPZ.LT.0 ) THEN
249
ELSE IF( N.LT.0 ) THEN
251
ELSE IF( ( LDZ.LT.1 ) .OR.
252
$ ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1, N ) ) ) THEN
258
* Compute the workspace requirements
260
SMLSIZ = ILAENV( 9, 'DSTEDC', ' ', 0, 0, 0, 0 )
261
IF( N.LE.1 .OR. ICOMPZ.EQ.0 ) THEN
264
ELSE IF( N.LE.SMLSIZ ) THEN
268
LGN = INT( LOG( DBLE( N ) )/LOG( TWO ) )
273
IF( ICOMPZ.EQ.1 ) THEN
274
LWMIN = 1 + 3*N + 2*N*LGN + 4*N**2
275
LIWMIN = 6 + 6*N + 5*N*LGN
276
ELSE IF( ICOMPZ.EQ.2 ) THEN
277
LWMIN = 1 + 4*N + N**2
284
IF( LWORK.LT.LWMIN .AND. .NOT. LQUERY ) THEN
286
ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT. LQUERY ) THEN
292
CALL XERBLA( 'DSTEDC', -INFO )
294
ELSE IF (LQUERY) THEN
298
* Quick return if possible
308
* If the following conditional clause is removed, then the routine
309
* will use the Divide and Conquer routine to compute only the
310
* eigenvalues, which requires (3N + 3N**2) real workspace and
311
* (2 + 5N + 2N lg(N)) integer workspace.
312
* Since on many architectures DSTERF is much faster than any other
313
* algorithm for finding eigenvalues only, it is used here
314
* as the default. If the conditional clause is removed, then
315
* information on the size of workspace needs to be changed.
317
* If COMPZ = 'N', use DSTERF to compute the eigenvalues.
319
IF( ICOMPZ.EQ.0 ) THEN
320
CALL DSTERF( N, D, E, INFO )
324
* If N is smaller than the minimum divide size (SMLSIZ+1), then
325
* solve the problem with another solver.
327
IF( N.LE.SMLSIZ ) THEN
329
CALL DSTEQR( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
333
* If COMPZ = 'V', the Z matrix must be stored elsewhere for later
336
IF( ICOMPZ.EQ.1 ) THEN
342
IF( ICOMPZ.EQ.2 ) THEN
343
CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
348
ORGNRM = DLANST( 'M', N, D, E )
352
EPS = DLAMCH( 'Epsilon' )
356
* while ( START <= N )
359
IF( START.LE.N ) THEN
361
* Let FINISH be the position of the next subdiagonal entry
362
* such that E( FINISH ) <= TINY or FINISH = N if no such
363
* subdiagonal exists. The matrix identified by the elements
364
* between START and FINISH constitutes an independent
369
IF( FINISH.LT.N ) THEN
370
TINY = EPS*SQRT( ABS( D( FINISH ) ) )*
371
$ SQRT( ABS( D( FINISH+1 ) ) )
372
IF( ABS( E( FINISH ) ).GT.TINY ) THEN
378
* (Sub) Problem determined. Compute its size and solve it.
380
M = FINISH - START + 1
385
IF( M.GT.SMLSIZ ) THEN
389
ORGNRM = DLANST( 'M', M, D( START ), E( START ) )
390
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, M, 1, D( START ), M,
392
CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, M-1, 1, E( START ),
395
IF( ICOMPZ.EQ.1 ) THEN
400
CALL DLAED0( ICOMPZ, N, M, D( START ), E( START ),
401
$ Z( STRTRW, START ), LDZ, WORK( 1 ), N,
402
$ WORK( STOREZ ), IWORK, INFO )
404
INFO = ( INFO / ( M+1 )+START-1 )*( N+1 ) +
405
$ MOD( INFO, ( M+1 ) ) + START - 1
411
CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, M, 1, D( START ), M,
415
IF( ICOMPZ.EQ.1 ) THEN
417
* Since QR won't update a Z matrix which is larger than
418
* the length of D, we must solve the sub-problem in a
419
* workspace and then multiply back into Z.
421
CALL DSTEQR( 'I', M, D( START ), E( START ), WORK, M,
422
$ WORK( M*M+1 ), INFO )
423
CALL DLACPY( 'A', N, M, Z( 1, START ), LDZ,
424
$ WORK( STOREZ ), N )
425
CALL DGEMM( 'N', 'N', N, M, M, ONE,
426
$ WORK( STOREZ ), N, WORK, M, ZERO,
427
$ Z( 1, START ), LDZ )
428
ELSE IF( ICOMPZ.EQ.2 ) THEN
429
CALL DSTEQR( 'I', M, D( START ), E( START ),
430
$ Z( START, START ), LDZ, WORK, INFO )
432
CALL DSTERF( M, D( START ), E( START ), INFO )
435
INFO = START*( N+1 ) + FINISH
446
* If the problem split any number of times, then the eigenvalues
447
* will not be properly ordered. Here we permute the eigenvalues
448
* (and the associated eigenvectors) into ascending order.
451
IF( ICOMPZ.EQ.0 ) THEN
455
CALL DLASRT( 'I', N, D, INFO )
459
* Use Selection Sort to minimize swaps of eigenvectors
466
IF( D( J ).LT.P ) THEN
474
CALL DSWAP( N, Z( 1, I ), 1, Z( 1, K ), 1 )