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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347
  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,
  100. *> dimension (LWORK)
  101. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  102. *> \endverbatim
  103. *>
  104. *> \param[in] LWORK
  105. *> \verbatim
  106. *> LWORK is INTEGER
  107. *> The dimension of the array WORK.
  108. *> If N <= 1, LWORK must be at least 1.
  109. *> If JOBZ = 'N' and N > 1, LWORK must be at least 2*N+1.
  110. *> If JOBZ = 'V' and N > 1, LWORK must be at least
  111. *> 1 + 6*N + 2*N**2.
  112. *>
  113. *> If LWORK = -1, then a workspace query is assumed; the routine
  114. *> only calculates the optimal sizes of the WORK and IWORK
  115. *> arrays, returns these values as the first entries of the WORK
  116. *> and IWORK arrays, and no error message related to LWORK or
  117. *> LIWORK is issued by XERBLA.
  118. *> \endverbatim
  119. *>
  120. *> \param[out] IWORK
  121. *> \verbatim
  122. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  123. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  124. *> \endverbatim
  125. *>
  126. *> \param[in] LIWORK
  127. *> \verbatim
  128. *> LIWORK is INTEGER
  129. *> The dimension of the array IWORK.
  130. *> If N <= 1, LIWORK must be at least 1.
  131. *> If JOBZ = 'N' and N > 1, LIWORK must be at least 1.
  132. *> If JOBZ = 'V' and N > 1, LIWORK must be at least 3 + 5*N.
  133. *>
  134. *> If LIWORK = -1, then a workspace query is assumed; the
  135. *> routine only calculates the optimal sizes of the WORK and
  136. *> IWORK arrays, returns these values as the first entries of
  137. *> the WORK and IWORK arrays, and no error message related to
  138. *> LWORK or LIWORK is issued by XERBLA.
  139. *> \endverbatim
  140. *>
  141. *> \param[out] INFO
  142. *> \verbatim
  143. *> INFO is INTEGER
  144. *> = 0: successful exit
  145. *> < 0: if INFO = -i, the i-th argument had an illegal value
  146. *> > 0: if INFO = i and JOBZ = 'N', then the algorithm failed
  147. *> to converge; i off-diagonal elements of an intermediate
  148. *> tridiagonal form did not converge to zero;
  149. *> if INFO = i and JOBZ = 'V', then the algorithm failed
  150. *> to compute an eigenvalue while working on the submatrix
  151. *> lying in rows and columns INFO/(N+1) through
  152. *> mod(INFO,N+1).
  153. *> \endverbatim
  154. *
  155. * Authors:
  156. * ========
  157. *
  158. *> \author Univ. of Tennessee
  159. *> \author Univ. of California Berkeley
  160. *> \author Univ. of Colorado Denver
  161. *> \author NAG Ltd.
  162. *
  163. *> \ingroup doubleSYeigen
  164. *
  165. *> \par Contributors:
  166. * ==================
  167. *>
  168. *> Jeff Rutter, Computer Science Division, University of California
  169. *> at Berkeley, USA \n
  170. *> Modified by Francoise Tisseur, University of Tennessee \n
  171. *> Modified description of INFO. Sven, 16 Feb 05. \n
  172. *>
  173. * =====================================================================
  174. SUBROUTINE DSYEVD( JOBZ, UPLO, N, A, LDA, W, WORK, LWORK, IWORK,
  175. $ LIWORK, INFO )
  176. *
  177. * -- LAPACK driver routine --
  178. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  179. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  180. *
  181. * .. Scalar Arguments ..
  182. CHARACTER JOBZ, UPLO
  183. INTEGER INFO, LDA, LIWORK, LWORK, N
  184. * ..
  185. * .. Array Arguments ..
  186. INTEGER IWORK( * )
  187. DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * )
  188. * ..
  189. *
  190. * =====================================================================
  191. *
  192. * .. Parameters ..
  193. DOUBLE PRECISION ZERO, ONE
  194. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  195. * ..
  196. * .. Local Scalars ..
  197. *
  198. LOGICAL LOWER, LQUERY, WANTZ
  199. INTEGER IINFO, INDE, INDTAU, INDWK2, INDWRK, ISCALE,
  200. $ LIOPT, LIWMIN, LLWORK, LLWRK2, LOPT, LWMIN
  201. DOUBLE PRECISION ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN, SIGMA,
  202. $ SMLNUM
  203. * ..
  204. * .. External Functions ..
  205. LOGICAL LSAME
  206. INTEGER ILAENV
  207. DOUBLE PRECISION DLAMCH, DLANSY
  208. EXTERNAL LSAME, DLAMCH, DLANSY, ILAENV
  209. * ..
  210. * .. External Subroutines ..
  211. EXTERNAL DLACPY, DLASCL, DORMTR, DSCAL, DSTEDC, DSTERF,
  212. $ DSYTRD, XERBLA
  213. * ..
  214. * .. Intrinsic Functions ..
  215. INTRINSIC MAX, SQRT
  216. * ..
  217. * .. Executable Statements ..
  218. *
  219. * Test the input parameters.
  220. *
  221. WANTZ = LSAME( JOBZ, 'V' )
  222. LOWER = LSAME( UPLO, 'L' )
  223. LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
  224. *
  225. INFO = 0
  226. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  227. INFO = -1
  228. ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
  229. INFO = -2
  230. ELSE IF( N.LT.0 ) THEN
  231. INFO = -3
  232. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  233. INFO = -5
  234. END IF
  235. *
  236. IF( INFO.EQ.0 ) THEN
  237. IF( N.LE.1 ) THEN
  238. LIWMIN = 1
  239. LWMIN = 1
  240. LOPT = LWMIN
  241. LIOPT = LIWMIN
  242. ELSE
  243. IF( WANTZ ) THEN
  244. LIWMIN = 3 + 5*N
  245. LWMIN = 1 + 6*N + 2*N**2
  246. ELSE
  247. LIWMIN = 1
  248. LWMIN = 2*N + 1
  249. END IF
  250. LOPT = MAX( LWMIN, 2*N +
  251. $ N*ILAENV( 1, 'DSYTRD', UPLO, N, -1, -1, -1 ) )
  252. LIOPT = LIWMIN
  253. END IF
  254. WORK( 1 ) = LOPT
  255. IWORK( 1 ) = LIOPT
  256. *
  257. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  258. INFO = -8
  259. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  260. INFO = -10
  261. END IF
  262. END IF
  263. *
  264. IF( INFO.NE.0 ) THEN
  265. CALL XERBLA( 'DSYEVD', -INFO )
  266. RETURN
  267. ELSE IF( LQUERY ) THEN
  268. RETURN
  269. END IF
  270. *
  271. * Quick return if possible
  272. *
  273. IF( N.EQ.0 )
  274. $ RETURN
  275. *
  276. IF( N.EQ.1 ) THEN
  277. W( 1 ) = A( 1, 1 )
  278. IF( WANTZ )
  279. $ A( 1, 1 ) = ONE
  280. RETURN
  281. END IF
  282. *
  283. * Get machine constants.
  284. *
  285. SAFMIN = DLAMCH( 'Safe minimum' )
  286. EPS = DLAMCH( 'Precision' )
  287. SMLNUM = SAFMIN / EPS
  288. BIGNUM = ONE / SMLNUM
  289. RMIN = SQRT( SMLNUM )
  290. RMAX = SQRT( BIGNUM )
  291. *
  292. * Scale matrix to allowable range, if necessary.
  293. *
  294. ANRM = DLANSY( 'M', UPLO, N, A, LDA, WORK )
  295. ISCALE = 0
  296. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  297. ISCALE = 1
  298. SIGMA = RMIN / ANRM
  299. ELSE IF( ANRM.GT.RMAX ) THEN
  300. ISCALE = 1
  301. SIGMA = RMAX / ANRM
  302. END IF
  303. IF( ISCALE.EQ.1 )
  304. $ CALL DLASCL( UPLO, 0, 0, ONE, SIGMA, N, N, A, LDA, INFO )
  305. *
  306. * Call DSYTRD to reduce symmetric matrix to tridiagonal form.
  307. *
  308. INDE = 1
  309. INDTAU = INDE + N
  310. INDWRK = INDTAU + N
  311. LLWORK = LWORK - INDWRK + 1
  312. INDWK2 = INDWRK + N*N
  313. LLWRK2 = LWORK - INDWK2 + 1
  314. *
  315. CALL DSYTRD( UPLO, N, A, LDA, W, WORK( INDE ), WORK( INDTAU ),
  316. $ WORK( INDWRK ), LLWORK, IINFO )
  317. *
  318. * For eigenvalues only, call DSTERF. For eigenvectors, first call
  319. * DSTEDC to generate the eigenvector matrix, WORK(INDWRK), of the
  320. * tridiagonal matrix, then call DORMTR to multiply it by the
  321. * Householder transformations stored in A.
  322. *
  323. IF( .NOT.WANTZ ) THEN
  324. CALL DSTERF( N, W, WORK( INDE ), INFO )
  325. ELSE
  326. CALL DSTEDC( 'I', N, W, WORK( INDE ), WORK( INDWRK ), N,
  327. $ WORK( INDWK2 ), LLWRK2, IWORK, LIWORK, INFO )
  328. CALL DORMTR( 'L', UPLO, 'N', N, N, A, LDA, WORK( INDTAU ),
  329. $ WORK( INDWRK ), N, WORK( INDWK2 ), LLWRK2, IINFO )
  330. CALL DLACPY( 'A', N, N, WORK( INDWRK ), N, A, LDA )
  331. END IF
  332. *
  333. * If matrix was scaled, then rescale eigenvalues appropriately.
  334. *
  335. IF( ISCALE.EQ.1 )
  336. $ CALL DSCAL( N, ONE / SIGMA, W, 1 )
  337. *
  338. WORK( 1 ) = LOPT
  339. IWORK( 1 ) = LIOPT
  340. *
  341. RETURN
  342. *
  343. * End of DSYEVD
  344. *
  345. END