You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

zheevd.f 12 kB

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