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.

cheevd.f 13 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  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. *> \htmlonly
  9. *> Download CHEEVD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/cheevd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/cheevd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/cheevd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHEEVD( 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. * REAL RWORK( * ), W( * )
  31. * COMPLEX A( LDA, * ), WORK( * )
  32. * ..
  33. *
  34. *
  35. *> \par Purpose:
  36. * =============
  37. *>
  38. *> \verbatim
  39. *>
  40. *> CHEEVD 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 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 REAL 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 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 REAL array,
  120. *> dimension (LRWORK)
  121. *> On exit, if INFO = 0, RWORK(1) returns the optimal LRWORK.
  122. *> \endverbatim
  123. *>
  124. *> \param[in] LRWORK
  125. *> \verbatim
  126. *> LRWORK is INTEGER
  127. *> The dimension of the array RWORK.
  128. *> If N <= 1, LRWORK must be at least 1.
  129. *> If JOBZ = 'N' and N > 1, LRWORK must be at least N.
  130. *> If JOBZ = 'V' and N > 1, LRWORK must be at least
  131. *> 1 + 5*N + 2*N**2.
  132. *>
  133. *> If LRWORK = -1, then a workspace query is assumed; the
  134. *> routine only calculates the optimal sizes of the WORK, RWORK
  135. *> and IWORK arrays, returns these values as the first entries
  136. *> of the WORK, RWORK and IWORK arrays, and no error message
  137. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  138. *> \endverbatim
  139. *>
  140. *> \param[out] IWORK
  141. *> \verbatim
  142. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  143. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  144. *> \endverbatim
  145. *>
  146. *> \param[in] LIWORK
  147. *> \verbatim
  148. *> LIWORK is INTEGER
  149. *> The dimension of the array IWORK.
  150. *> If N <= 1, LIWORK must be at least 1.
  151. *> If JOBZ = 'N' and N > 1, LIWORK must be at least 1.
  152. *> If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
  153. *>
  154. *> If LIWORK = -1, then a workspace query is assumed; the
  155. *> routine only calculates the optimal sizes of the WORK, RWORK
  156. *> and IWORK arrays, returns these values as the first entries
  157. *> of the WORK, RWORK and IWORK arrays, and no error message
  158. *> related to LWORK or LRWORK or LIWORK is issued by XERBLA.
  159. *> \endverbatim
  160. *>
  161. *> \param[out] INFO
  162. *> \verbatim
  163. *> INFO is INTEGER
  164. *> = 0: successful exit
  165. *> < 0: if INFO = -i, the i-th argument had an illegal value
  166. *> > 0: if INFO = i and JOBZ = 'N', then the algorithm failed
  167. *> to converge; i off-diagonal elements of an intermediate
  168. *> tridiagonal form did not converge to zero;
  169. *> if INFO = i and JOBZ = 'V', then the algorithm failed
  170. *> to compute an eigenvalue while working on the submatrix
  171. *> lying in rows and columns INFO/(N+1) through
  172. *> mod(INFO,N+1).
  173. *> \endverbatim
  174. *
  175. * Authors:
  176. * ========
  177. *
  178. *> \author Univ. of Tennessee
  179. *> \author Univ. of California Berkeley
  180. *> \author Univ. of Colorado Denver
  181. *> \author NAG Ltd.
  182. *
  183. *> \ingroup heevd
  184. *
  185. *> \par Further Details:
  186. * =====================
  187. *>
  188. *> Modified description of INFO. Sven, 16 Feb 05.
  189. *
  190. *> \par Contributors:
  191. * ==================
  192. *>
  193. *> Jeff Rutter, Computer Science Division, University of California
  194. *> at Berkeley, USA
  195. *>
  196. * =====================================================================
  197. SUBROUTINE CHEEVD( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, RWORK,
  198. $ LRWORK, IWORK, LIWORK, INFO )
  199. *
  200. * -- LAPACK driver routine --
  201. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  202. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  203. *
  204. * .. Scalar Arguments ..
  205. CHARACTER JOBZ, UPLO
  206. INTEGER INFO, LDA, LIWORK, LRWORK, LWORK, N
  207. * ..
  208. * .. Array Arguments ..
  209. INTEGER IWORK( * )
  210. REAL RWORK( * ), W( * )
  211. COMPLEX A( LDA, * ), WORK( * )
  212. * ..
  213. *
  214. * =====================================================================
  215. *
  216. * .. Parameters ..
  217. REAL ZERO, ONE
  218. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0 )
  219. COMPLEX CONE
  220. PARAMETER ( CONE = ( 1.0E0, 0.0E0 ) )
  221. * ..
  222. * .. Local Scalars ..
  223. LOGICAL LOWER, LQUERY, WANTZ
  224. INTEGER IINFO, IMAX, INDE, INDRWK, INDTAU, INDWK2,
  225. $ INDWRK, ISCALE, LIOPT, LIWMIN, LLRWK, LLWORK,
  226. $ LLWRK2, LOPT, LROPT, LRWMIN, LWMIN
  227. REAL ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
  228. $ SMLNUM
  229. * ..
  230. * .. External Functions ..
  231. LOGICAL LSAME
  232. INTEGER ILAENV
  233. REAL CLANHE, SLAMCH, SROUNDUP_LWORK
  234. EXTERNAL ILAENV, LSAME, CLANHE, SLAMCH, SROUNDUP_LWORK
  235. * ..
  236. * .. External Subroutines ..
  237. EXTERNAL CHETRD, CLACPY, CLASCL, CSTEDC, CUNMTR, 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, -1 ) )
  282. LROPT = LRWMIN
  283. LIOPT = LIWMIN
  284. END IF
  285. WORK( 1 ) = SROUNDUP_LWORK(LOPT)
  286. RWORK( 1 ) = LROPT
  287. IWORK( 1 ) = LIOPT
  288. *
  289. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  290. INFO = -8
  291. ELSE IF( LRWORK.LT.LRWMIN .AND. .NOT.LQUERY ) THEN
  292. INFO = -10
  293. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  294. INFO = -12
  295. END IF
  296. END IF
  297. *
  298. IF( INFO.NE.0 ) THEN
  299. CALL XERBLA( 'CHEEVD', -INFO )
  300. RETURN
  301. ELSE IF( LQUERY ) THEN
  302. RETURN
  303. END IF
  304. *
  305. * Quick return if possible
  306. *
  307. IF( N.EQ.0 )
  308. $ RETURN
  309. *
  310. IF( N.EQ.1 ) THEN
  311. W( 1 ) = REAL( A( 1, 1 ) )
  312. IF( WANTZ )
  313. $ A( 1, 1 ) = CONE
  314. RETURN
  315. END IF
  316. *
  317. * Get machine constants.
  318. *
  319. SAFMIN = SLAMCH( 'Safe minimum' )
  320. EPS = SLAMCH( 'Precision' )
  321. SMLNUM = SAFMIN / EPS
  322. BIGNUM = ONE / SMLNUM
  323. RMIN = SQRT( SMLNUM )
  324. RMAX = SQRT( BIGNUM )
  325. *
  326. * Scale matrix to allowable range, if necessary.
  327. *
  328. ANRM = CLANHE( 'M', UPLO, N, A, LDA, RWORK )
  329. ISCALE = 0
  330. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  331. ISCALE = 1
  332. SIGMA = RMIN / ANRM
  333. ELSE IF( ANRM.GT.RMAX ) THEN
  334. ISCALE = 1
  335. SIGMA = RMAX / ANRM
  336. END IF
  337. IF( ISCALE.EQ.1 )
  338. $ CALL CLASCL( UPLO, 0, 0, ONE, SIGMA, N, N, A, LDA, INFO )
  339. *
  340. * Call CHETRD to reduce Hermitian matrix to tridiagonal form.
  341. *
  342. INDE = 1
  343. INDTAU = 1
  344. INDWRK = INDTAU + N
  345. INDRWK = INDE + N
  346. INDWK2 = INDWRK + N*N
  347. LLWORK = LWORK - INDWRK + 1
  348. LLWRK2 = LWORK - INDWK2 + 1
  349. LLRWK = LRWORK - INDRWK + 1
  350. CALL CHETRD( UPLO, N, A, LDA, W, RWORK( INDE ), WORK( INDTAU ),
  351. $ WORK( INDWRK ), LLWORK, IINFO )
  352. *
  353. * For eigenvalues only, call SSTERF. For eigenvectors, first call
  354. * CSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the
  355. * tridiagonal matrix, then call CUNMTR to multiply it to the
  356. * Householder transformations represented as Householder vectors in
  357. * A.
  358. *
  359. IF( .NOT.WANTZ ) THEN
  360. CALL SSTERF( N, W, RWORK( INDE ), INFO )
  361. ELSE
  362. CALL CSTEDC( 'I', N, W, RWORK( INDE ), WORK( INDWRK ), N,
  363. $ WORK( INDWK2 ), LLWRK2, RWORK( INDRWK ), LLRWK,
  364. $ IWORK, LIWORK, INFO )
  365. CALL CUNMTR( 'L', UPLO, 'N', N, N, A, LDA, WORK( INDTAU ),
  366. $ WORK( INDWRK ), N, WORK( INDWK2 ), LLWRK2, IINFO )
  367. CALL CLACPY( 'A', N, N, WORK( INDWRK ), N, A, LDA )
  368. END IF
  369. *
  370. * If matrix was scaled, then rescale eigenvalues appropriately.
  371. *
  372. IF( ISCALE.EQ.1 ) THEN
  373. IF( INFO.EQ.0 ) THEN
  374. IMAX = N
  375. ELSE
  376. IMAX = INFO - 1
  377. END IF
  378. CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
  379. END IF
  380. *
  381. WORK( 1 ) = SROUNDUP_LWORK(LOPT)
  382. RWORK( 1 ) = LROPT
  383. IWORK( 1 ) = LIOPT
  384. *
  385. RETURN
  386. *
  387. * End of CHEEVD
  388. *
  389. END