LAPACK 3.12.1
LAPACK: Linear Algebra PACKage
Loading...
Searching...
No Matches
cheevd.f
Go to the documentation of this file.
1*> \brief <b> CHEEVD computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices</b>
2*
3* =========== DOCUMENTATION ===========
4*
5* Online html documentation available at
6* http://www.netlib.org/lapack/explore-html/
7*
8*> Download CHEEVD + dependencies
9*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevd.f">
10*> [TGZ]</a>
11*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevd.f">
12*> [ZIP]</a>
13*> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevd.f">
14*> [TXT]</a>
15*
16* Definition:
17* ===========
18*
19* SUBROUTINE CHEEVD( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
20* LRWORK, IWORK, LIWORK, INFO )
21*
22* .. Scalar Arguments ..
23* CHARACTER JOBZ, UPLO
24* INTEGER INFO, LDA, LIWORK, LRWORK, LWORK, N
25* ..
26* .. Array Arguments ..
27* INTEGER IWORK( * )
28* REAL RWORK( * ), W( * )
29* COMPLEX A( LDA, * ), WORK( * )
30* ..
31*
32*
33*> \par Purpose:
34* =============
35*>
36*> \verbatim
37*>
38*> CHEEVD computes all eigenvalues and, optionally, eigenvectors of a
39*> complex Hermitian matrix A. If eigenvectors are desired, it uses a
40*> divide and conquer algorithm.
41*>
42*> \endverbatim
43*
44* Arguments:
45* ==========
46*
47*> \param[in] JOBZ
48*> \verbatim
49*> JOBZ is CHARACTER*1
50*> = 'N': Compute eigenvalues only;
51*> = 'V': Compute eigenvalues and eigenvectors.
52*> \endverbatim
53*>
54*> \param[in] UPLO
55*> \verbatim
56*> UPLO is CHARACTER*1
57*> = 'U': Upper triangle of A is stored;
58*> = 'L': Lower triangle of A is stored.
59*> \endverbatim
60*>
61*> \param[in] N
62*> \verbatim
63*> N is INTEGER
64*> The order of the matrix A. N >= 0.
65*> \endverbatim
66*>
67*> \param[in,out] A
68*> \verbatim
69*> A is COMPLEX array, dimension (LDA, N)
70*> On entry, the Hermitian matrix A. If UPLO = 'U', the
71*> leading N-by-N upper triangular part of A contains the
72*> upper triangular part of the matrix A. If UPLO = 'L',
73*> the leading N-by-N lower triangular part of A contains
74*> the lower triangular part of the matrix A.
75*> On exit, if JOBZ = 'V', then if INFO = 0, A contains the
76*> orthonormal eigenvectors of the matrix A.
77*> If JOBZ = 'N', then on exit the lower triangle (if UPLO='L')
78*> or the upper triangle (if UPLO='U') of A, including the
79*> diagonal, is destroyed.
80*> \endverbatim
81*>
82*> \param[in] LDA
83*> \verbatim
84*> LDA is INTEGER
85*> The leading dimension of the array A. LDA >= max(1,N).
86*> \endverbatim
87*>
88*> \param[out] W
89*> \verbatim
90*> W is REAL array, dimension (N)
91*> If INFO = 0, the eigenvalues in ascending order.
92*> \endverbatim
93*>
94*> \param[out] WORK
95*> \verbatim
96*> WORK is COMPLEX array, dimension (MAX(1,LWORK))
97*> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
98*> \endverbatim
99*>
100*> \param[in] LWORK
101*> \verbatim
102*> LWORK is INTEGER
103*> The length of the array WORK.
104*> If N <= 1, LWORK must be at least 1.
105*> If JOBZ = 'N' and N > 1, LWORK must be at least N + 1.
106*> If JOBZ = 'V' and N > 1, LWORK must be at least 2*N + N**2.
107*>
108*> If LWORK = -1, then a workspace query is assumed; the routine
109*> only calculates the optimal sizes of the WORK, RWORK and
110*> IWORK arrays, returns these values as the first entries of
111*> the WORK, RWORK and IWORK arrays, and no error message
112*> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
113*> \endverbatim
114*>
115*> \param[out] RWORK
116*> \verbatim
117*> RWORK is REAL array, dimension (MAX(1,LRWORK))
118*> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
119*> \endverbatim
120*>
121*> \param[in] LRWORK
122*> \verbatim
123*> LRWORK is INTEGER
124*> The dimension of the array RWORK.
125*> If N <= 1, LRWORK must be at least 1.
126*> If JOBZ = 'N' and N > 1, LRWORK must be at least N.
127*> If JOBZ = 'V' and N > 1, LRWORK must be at least
128*> 1 + 5*N + 2*N**2.
129*>
130*> If LRWORK = -1, then a workspace query is assumed; the
131*> routine only calculates the optimal sizes of the WORK, RWORK
132*> and IWORK arrays, returns these values as the first entries
133*> of the WORK, RWORK and IWORK arrays, and no error message
134*> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
135*> \endverbatim
136*>
137*> \param[out] IWORK
138*> \verbatim
139*> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
140*> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
141*> \endverbatim
142*>
143*> \param[in] LIWORK
144*> \verbatim
145*> LIWORK is INTEGER
146*> The dimension of the array IWORK.
147*> If N <= 1, LIWORK must be at least 1.
148*> If JOBZ = 'N' and N > 1, LIWORK must be at least 1.
149*> If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
150*>
151*> If LIWORK = -1, then a workspace query is assumed; the
152*> routine only calculates the optimal sizes of the WORK, RWORK
153*> and IWORK arrays, returns these values as the first entries
154*> of the WORK, RWORK and IWORK arrays, and no error message
155*> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
156*> \endverbatim
157*>
158*> \param[out] INFO
159*> \verbatim
160*> INFO is INTEGER
161*> = 0: successful exit
162*> < 0: if INFO = -i, the i-th argument had an illegal value
163*> > 0: if INFO = i and JOBZ = 'N', then the algorithm failed
164*> to converge; i off-diagonal elements of an intermediate
165*> tridiagonal form did not converge to zero;
166*> if INFO = i and JOBZ = 'V', then the algorithm failed
167*> to compute an eigenvalue while working on the submatrix
168*> lying in rows and columns INFO/(N+1) through
169*> mod(INFO,N+1).
170*> \endverbatim
171*
172* Authors:
173* ========
174*
175*> \author Univ. of Tennessee
176*> \author Univ. of California Berkeley
177*> \author Univ. of Colorado Denver
178*> \author NAG Ltd.
179*
180*> \ingroup heevd
181*
182*> \par Further Details:
183* =====================
184*>
185*> Modified description of INFO. Sven, 16 Feb 05.
186*
187*> \par Contributors:
188* ==================
189*>
190*> Jeff Rutter, Computer Science Division, University of California
191*> at Berkeley, USA
192*>
193* =====================================================================
194 SUBROUTINE cheevd( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK,
195 $ RWORK,
196 $ LRWORK, IWORK, LIWORK, INFO )
197*
198* -- LAPACK driver routine --
199* -- LAPACK is a software package provided by Univ. of Tennessee, --
200* -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
201*
202* .. Scalar Arguments ..
203 CHARACTER JOBZ, UPLO
204 INTEGER INFO, LDA, LIWORK, LRWORK, LWORK, N
205* ..
206* .. Array Arguments ..
207 INTEGER IWORK( * )
208 REAL RWORK( * ), W( * )
209 COMPLEX A( LDA, * ), WORK( * )
210* ..
211*
212* =====================================================================
213*
214* .. Parameters ..
215 REAL ZERO, ONE
216 PARAMETER ( ZERO = 0.0e0, one = 1.0e0 )
217 COMPLEX CONE
218 parameter( cone = ( 1.0e0, 0.0e0 ) )
219* ..
220* .. Local Scalars ..
221 LOGICAL LOWER, LQUERY, WANTZ
222 INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWK2,
223 $ indwrk, iscale, liopt, liwmin, llrwk, llwork,
224 $ llwrk2, lopt, lropt, lrwmin, lwmin
225 REAL ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
226 $ SMLNUM
227* ..
228* .. External Functions ..
229 LOGICAL LSAME
230 INTEGER ILAENV
231 REAL CLANHE, SLAMCH, SROUNDUP_LWORK
232 EXTERNAL ilaenv, lsame, clanhe, slamch,
233 $ sroundup_lwork
234* ..
235* .. External Subroutines ..
236 EXTERNAL chetrd, clacpy, clascl, cstedc, cunmtr,
237 $ sscal,
238 $ ssterf, xerbla
239* ..
240* .. Intrinsic Functions ..
241 INTRINSIC max, sqrt
242* ..
243* .. Executable Statements ..
244*
245* Test the input parameters.
246*
247 wantz = lsame( jobz, 'V' )
248 lower = lsame( uplo, 'L' )
249 lquery = ( lwork.EQ.-1 .OR. lrwork.EQ.-1 .OR. liwork.EQ.-1 )
250*
251 info = 0
252 IF( .NOT.( wantz .OR. lsame( jobz, 'N' ) ) ) THEN
253 info = -1
254 ELSE IF( .NOT.( lower .OR. lsame( uplo, 'U' ) ) ) THEN
255 info = -2
256 ELSE IF( n.LT.0 ) THEN
257 info = -3
258 ELSE IF( lda.LT.max( 1, n ) ) THEN
259 info = -5
260 END IF
261*
262 IF( info.EQ.0 ) THEN
263 IF( n.LE.1 ) THEN
264 lwmin = 1
265 lrwmin = 1
266 liwmin = 1
267 lopt = lwmin
268 lropt = lrwmin
269 liopt = liwmin
270 ELSE
271 IF( wantz ) THEN
272 lwmin = 2*n + n*n
273 lrwmin = 1 + 5*n + 2*n**2
274 liwmin = 3 + 5*n
275 ELSE
276 lwmin = n + 1
277 lrwmin = n
278 liwmin = 1
279 END IF
280 lopt = max( lwmin, n +
281 $ n*ilaenv( 1, 'CHETRD', uplo, n, -1, -1,
282 $ -1 ) )
283 lropt = lrwmin
284 liopt = liwmin
285 END IF
286 work( 1 ) = sroundup_lwork( lopt )
287 rwork( 1 ) = sroundup_lwork( lropt )
288 iwork( 1 ) = liopt
289*
290 IF( lwork.LT.lwmin .AND. .NOT.lquery ) THEN
291 info = -8
292 ELSE IF( lrwork.LT.lrwmin .AND. .NOT.lquery ) THEN
293 info = -10
294 ELSE IF( liwork.LT.liwmin .AND. .NOT.lquery ) THEN
295 info = -12
296 END IF
297 END IF
298*
299 IF( info.NE.0 ) THEN
300 CALL xerbla( 'CHEEVD', -info )
301 RETURN
302 ELSE IF( lquery ) THEN
303 RETURN
304 END IF
305*
306* Quick return if possible
307*
308 IF( n.EQ.0 )
309 $ RETURN
310*
311 IF( n.EQ.1 ) THEN
312 w( 1 ) = real( a( 1, 1 ) )
313 IF( wantz )
314 $ a( 1, 1 ) = cone
315 RETURN
316 END IF
317*
318* Get machine constants.
319*
320 safmin = slamch( 'Safe minimum' )
321 eps = slamch( 'Precision' )
322 smlnum = safmin / eps
323 bignum = one / smlnum
324 rmin = sqrt( smlnum )
325 rmax = sqrt( bignum )
326*
327* Scale matrix to allowable range, if necessary.
328*
329 anrm = clanhe( 'M', uplo, n, a, lda, rwork )
330 iscale = 0
331 IF( anrm.GT.zero .AND. anrm.LT.rmin ) THEN
332 iscale = 1
333 sigma = rmin / anrm
334 ELSE IF( anrm.GT.rmax ) THEN
335 iscale = 1
336 sigma = rmax / anrm
337 END IF
338 IF( iscale.EQ.1 )
339 $ CALL clascl( uplo, 0, 0, one, sigma, n, n, a, lda, info )
340*
341* Call CHETRD to reduce Hermitian matrix to tridiagonal form.
342*
343 inde = 1
344 indtau = 1
345 indwrk = indtau + n
346 indrwk = inde + n
347 indwk2 = indwrk + n*n
348 llwork = lwork - indwrk + 1
349 llwrk2 = lwork - indwk2 + 1
350 llrwk = lrwork - indrwk + 1
351 CALL chetrd( uplo, n, a, lda, w, rwork( inde ), work( indtau ),
352 $ work( indwrk ), llwork, iinfo )
353*
354* For eigenvalues only, call SSTERF. For eigenvectors, first call
355* CSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the
356* tridiagonal matrix, then call CUNMTR to multiply it to the
357* Householder transformations represented as Householder vectors in
358* A.
359*
360 IF( .NOT.wantz ) THEN
361 CALL ssterf( n, w, rwork( inde ), info )
362 ELSE
363 CALL cstedc( 'I', n, w, rwork( inde ), work( indwrk ), n,
364 $ work( indwk2 ), llwrk2, rwork( indrwk ), llrwk,
365 $ iwork, liwork, info )
366 CALL cunmtr( 'L', uplo, 'N', n, n, a, lda, work( indtau ),
367 $ work( indwrk ), n, work( indwk2 ), llwrk2, iinfo )
368 CALL clacpy( 'A', n, n, work( indwrk ), n, a, lda )
369 END IF
370*
371* If matrix was scaled, then rescale eigenvalues appropriately.
372*
373 IF( iscale.EQ.1 ) THEN
374 IF( info.EQ.0 ) THEN
375 imax = n
376 ELSE
377 imax = info - 1
378 END IF
379 CALL sscal( imax, one / sigma, w, 1 )
380 END IF
381*
382 work( 1 ) = sroundup_lwork( lopt )
383 rwork( 1 ) = sroundup_lwork( lropt )
384 iwork( 1 ) = liopt
385*
386 RETURN
387*
388* End of CHEEVD
389*
390 END
subroutine xerbla(srname, info)
Definition cblat2.f:3285
subroutine cheevd(jobz, uplo, n, a, lda, w, work, lwork, rwork, lrwork, iwork, liwork, info)
CHEEVD computes the eigenvalues and, optionally, the left and/or right eigenvectors for HE matrices
Definition cheevd.f:197
subroutine chetrd(uplo, n, a, lda, d, e, tau, work, lwork, info)
CHETRD
Definition chetrd.f:191
subroutine clacpy(uplo, m, n, a, lda, b, ldb)
CLACPY copies all or part of one two-dimensional array to another.
Definition clacpy.f:101
subroutine clascl(type, kl, ku, cfrom, cto, m, n, a, lda, info)
CLASCL multiplies a general rectangular matrix by a real scalar defined as cto/cfrom.
Definition clascl.f:142
subroutine sscal(n, sa, sx, incx)
SSCAL
Definition sscal.f:79
subroutine cstedc(compz, n, d, e, z, ldz, work, lwork, rwork, lrwork, iwork, liwork, info)
CSTEDC
Definition cstedc.f:204
subroutine ssterf(n, d, e, info)
SSTERF
Definition ssterf.f:84
subroutine cunmtr(side, uplo, trans, m, n, a, lda, tau, c, ldc, work, lwork, info)
CUNMTR
Definition cunmtr.f:171