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.

dsyevd.f 11 kB

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