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.

dsyevr.f 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672
  1. *> \brief <b> DSYEVR 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 DSYEVR + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dsyevr.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dsyevr.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dsyevr.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
  22. * ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
  23. * IWORK, LIWORK, INFO )
  24. *
  25. * .. Scalar Arguments ..
  26. * CHARACTER JOBZ, RANGE, UPLO
  27. * INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
  28. * DOUBLE PRECISION ABSTOL, VL, VU
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER ISUPPZ( * ), IWORK( * )
  32. * DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
  33. * ..
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> DSYEVR computes selected eigenvalues and, optionally, eigenvectors
  42. *> of a real symmetric matrix A. Eigenvalues and eigenvectors can be
  43. *> selected by specifying either a range of values or a range of
  44. *> indices for the desired eigenvalues.
  45. *>
  46. *> DSYEVR first reduces the matrix A to tridiagonal form T with a call
  47. *> to DSYTRD. Then, whenever possible, DSYEVR calls DSTEMR to compute
  48. *> the eigenspectrum using Relatively Robust Representations. DSTEMR
  49. *> computes eigenvalues by the dqds algorithm, while orthogonal
  50. *> eigenvectors are computed from various "good" L D L^T representations
  51. *> (also known as Relatively Robust Representations). Gram-Schmidt
  52. *> orthogonalization is avoided as far as possible. More specifically,
  53. *> the various steps of the algorithm are as follows.
  54. *>
  55. *> For each unreduced block (submatrix) of T,
  56. *> (a) Compute T - sigma I = L D L^T, so that L and D
  57. *> define all the wanted eigenvalues to high relative accuracy.
  58. *> This means that small relative changes in the entries of D and L
  59. *> cause only small relative changes in the eigenvalues and
  60. *> eigenvectors. The standard (unfactored) representation of the
  61. *> tridiagonal matrix T does not have this property in general.
  62. *> (b) Compute the eigenvalues to suitable accuracy.
  63. *> If the eigenvectors are desired, the algorithm attains full
  64. *> accuracy of the computed eigenvalues only right before
  65. *> the corresponding vectors have to be computed, see steps c) and d).
  66. *> (c) For each cluster of close eigenvalues, select a new
  67. *> shift close to the cluster, find a new factorization, and refine
  68. *> the shifted eigenvalues to suitable accuracy.
  69. *> (d) For each eigenvalue with a large enough relative separation compute
  70. *> the corresponding eigenvector by forming a rank revealing twisted
  71. *> factorization. Go back to (c) for any clusters that remain.
  72. *>
  73. *> The desired accuracy of the output can be specified by the input
  74. *> parameter ABSTOL.
  75. *>
  76. *> For more details, see DSTEMR's documentation and:
  77. *> - Inderjit S. Dhillon and Beresford N. Parlett: "Multiple representations
  78. *> to compute orthogonal eigenvectors of symmetric tridiagonal matrices,"
  79. *> Linear Algebra and its Applications, 387(1), pp. 1-28, August 2004.
  80. *> - Inderjit Dhillon and Beresford Parlett: "Orthogonal Eigenvectors and
  81. *> Relative Gaps," SIAM Journal on Matrix Analysis and Applications, Vol. 25,
  82. *> 2004. Also LAPACK Working Note 154.
  83. *> - Inderjit Dhillon: "A new O(n^2) algorithm for the symmetric
  84. *> tridiagonal eigenvalue/eigenvector problem",
  85. *> Computer Science Division Technical Report No. UCB/CSD-97-971,
  86. *> UC Berkeley, May 1997.
  87. *>
  88. *>
  89. *> Note 1 : DSYEVR calls DSTEMR when the full spectrum is requested
  90. *> on machines which conform to the ieee-754 floating point standard.
  91. *> DSYEVR calls DSTEBZ and SSTEIN on non-ieee machines and
  92. *> when partial spectrum requests are made.
  93. *>
  94. *> Normal execution of DSTEMR may create NaNs and infinities and
  95. *> hence may abort due to a floating point exception in environments
  96. *> which do not handle NaNs and infinities in the ieee standard default
  97. *> manner.
  98. *> \endverbatim
  99. *
  100. * Arguments:
  101. * ==========
  102. *
  103. *> \param[in] JOBZ
  104. *> \verbatim
  105. *> JOBZ is CHARACTER*1
  106. *> = 'N': Compute eigenvalues only;
  107. *> = 'V': Compute eigenvalues and eigenvectors.
  108. *> \endverbatim
  109. *>
  110. *> \param[in] RANGE
  111. *> \verbatim
  112. *> RANGE is CHARACTER*1
  113. *> = 'A': all eigenvalues will be found.
  114. *> = 'V': all eigenvalues in the half-open interval (VL,VU]
  115. *> will be found.
  116. *> = 'I': the IL-th through IU-th eigenvalues will be found.
  117. *> For RANGE = 'V' or 'I' and IU - IL < N - 1, DSTEBZ and
  118. *> DSTEIN are called
  119. *> \endverbatim
  120. *>
  121. *> \param[in] UPLO
  122. *> \verbatim
  123. *> UPLO is CHARACTER*1
  124. *> = 'U': Upper triangle of A is stored;
  125. *> = 'L': Lower triangle of A is stored.
  126. *> \endverbatim
  127. *>
  128. *> \param[in] N
  129. *> \verbatim
  130. *> N is INTEGER
  131. *> The order of the matrix A. N >= 0.
  132. *> \endverbatim
  133. *>
  134. *> \param[in,out] A
  135. *> \verbatim
  136. *> A is DOUBLE PRECISION array, dimension (LDA, N)
  137. *> On entry, the symmetric matrix A. If UPLO = 'U', the
  138. *> leading N-by-N upper triangular part of A contains the
  139. *> upper triangular part of the matrix A. If UPLO = 'L',
  140. *> the leading N-by-N lower triangular part of A contains
  141. *> the lower triangular part of the matrix A.
  142. *> On exit, the lower triangle (if UPLO='L') or the upper
  143. *> triangle (if UPLO='U') of A, including the diagonal, is
  144. *> destroyed.
  145. *> \endverbatim
  146. *>
  147. *> \param[in] LDA
  148. *> \verbatim
  149. *> LDA is INTEGER
  150. *> The leading dimension of the array A. LDA >= max(1,N).
  151. *> \endverbatim
  152. *>
  153. *> \param[in] VL
  154. *> \verbatim
  155. *> VL is DOUBLE PRECISION
  156. *> \endverbatim
  157. *>
  158. *> \param[in] VU
  159. *> \verbatim
  160. *> VU is DOUBLE PRECISION
  161. *> If RANGE='V', the lower and upper bounds of the interval to
  162. *> be searched for eigenvalues. VL < VU.
  163. *> Not referenced if RANGE = 'A' or 'I'.
  164. *> \endverbatim
  165. *>
  166. *> \param[in] IL
  167. *> \verbatim
  168. *> IL is INTEGER
  169. *> \endverbatim
  170. *>
  171. *> \param[in] IU
  172. *> \verbatim
  173. *> IU is INTEGER
  174. *> If RANGE='I', the indices (in ascending order) of the
  175. *> smallest and largest eigenvalues to be returned.
  176. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  177. *> Not referenced if RANGE = 'A' or 'V'.
  178. *> \endverbatim
  179. *>
  180. *> \param[in] ABSTOL
  181. *> \verbatim
  182. *> ABSTOL is DOUBLE PRECISION
  183. *> The absolute error tolerance for the eigenvalues.
  184. *> An approximate eigenvalue is accepted as converged
  185. *> when it is determined to lie in an interval [a,b]
  186. *> of width less than or equal to
  187. *>
  188. *> ABSTOL + EPS * max( |a|,|b| ) ,
  189. *>
  190. *> where EPS is the machine precision. If ABSTOL is less than
  191. *> or equal to zero, then EPS*|T| will be used in its place,
  192. *> where |T| is the 1-norm of the tridiagonal matrix obtained
  193. *> by reducing A to tridiagonal form.
  194. *>
  195. *> See "Computing Small Singular Values of Bidiagonal Matrices
  196. *> with Guaranteed High Relative Accuracy," by Demmel and
  197. *> Kahan, LAPACK Working Note #3.
  198. *>
  199. *> If high relative accuracy is important, set ABSTOL to
  200. *> DLAMCH( 'Safe minimum' ). Doing so will guarantee that
  201. *> eigenvalues are computed to high relative accuracy when
  202. *> possible in future releases. The current code does not
  203. *> make any guarantees about high relative accuracy, but
  204. *> future releases will. See J. Barlow and J. Demmel,
  205. *> "Computing Accurate Eigensystems of Scaled Diagonally
  206. *> Dominant Matrices", LAPACK Working Note #7, for a discussion
  207. *> of which matrices define their eigenvalues to high relative
  208. *> accuracy.
  209. *> \endverbatim
  210. *>
  211. *> \param[out] M
  212. *> \verbatim
  213. *> M is INTEGER
  214. *> The total number of eigenvalues found. 0 <= M <= N.
  215. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
  216. *> \endverbatim
  217. *>
  218. *> \param[out] W
  219. *> \verbatim
  220. *> W is DOUBLE PRECISION array, dimension (N)
  221. *> The first M elements contain the selected eigenvalues in
  222. *> ascending order.
  223. *> \endverbatim
  224. *>
  225. *> \param[out] Z
  226. *> \verbatim
  227. *> Z is DOUBLE PRECISION array, dimension (LDZ, max(1,M))
  228. *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
  229. *> contain the orthonormal eigenvectors of the matrix A
  230. *> corresponding to the selected eigenvalues, with the i-th
  231. *> column of Z holding the eigenvector associated with W(i).
  232. *> If JOBZ = 'N', then Z is not referenced.
  233. *> Note: the user must ensure that at least max(1,M) columns are
  234. *> supplied in the array Z; if RANGE = 'V', the exact value of M
  235. *> is not known in advance and an upper bound must be used.
  236. *> Supplying N columns is always safe.
  237. *> \endverbatim
  238. *>
  239. *> \param[in] LDZ
  240. *> \verbatim
  241. *> LDZ is INTEGER
  242. *> The leading dimension of the array Z. LDZ >= 1, and if
  243. *> JOBZ = 'V', LDZ >= max(1,N).
  244. *> \endverbatim
  245. *>
  246. *> \param[out] ISUPPZ
  247. *> \verbatim
  248. *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
  249. *> The support of the eigenvectors in Z, i.e., the indices
  250. *> indicating the nonzero elements in Z. The i-th eigenvector
  251. *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
  252. *> ISUPPZ( 2*i ).
  253. *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
  254. *> \endverbatim
  255. *>
  256. *> \param[out] WORK
  257. *> \verbatim
  258. *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  259. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  260. *> \endverbatim
  261. *>
  262. *> \param[in] LWORK
  263. *> \verbatim
  264. *> LWORK is INTEGER
  265. *> The dimension of the array WORK. LWORK >= max(1,26*N).
  266. *> For optimal efficiency, LWORK >= (NB+6)*N,
  267. *> where NB is the max of the blocksize for DSYTRD and DORMTR
  268. *> returned by ILAENV.
  269. *>
  270. *> If LWORK = -1, then a workspace query is assumed; the routine
  271. *> only calculates the optimal size of the WORK array, returns
  272. *> this value as the first entry of the WORK array, and no error
  273. *> message related to LWORK is issued by XERBLA.
  274. *> \endverbatim
  275. *>
  276. *> \param[out] IWORK
  277. *> \verbatim
  278. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  279. *> On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
  280. *> \endverbatim
  281. *>
  282. *> \param[in] LIWORK
  283. *> \verbatim
  284. *> LIWORK is INTEGER
  285. *> The dimension of the array IWORK. LIWORK >= max(1,10*N).
  286. *>
  287. *> If LIWORK = -1, then a workspace query is assumed; the
  288. *> routine only calculates the optimal size of the IWORK array,
  289. *> returns this value as the first entry of the IWORK array, and
  290. *> no error message related to LIWORK is issued by XERBLA.
  291. *> \endverbatim
  292. *>
  293. *> \param[out] INFO
  294. *> \verbatim
  295. *> INFO is INTEGER
  296. *> = 0: successful exit
  297. *> < 0: if INFO = -i, the i-th argument had an illegal value
  298. *> > 0: Internal error
  299. *> \endverbatim
  300. *
  301. * Authors:
  302. * ========
  303. *
  304. *> \author Univ. of Tennessee
  305. *> \author Univ. of California Berkeley
  306. *> \author Univ. of Colorado Denver
  307. *> \author NAG Ltd.
  308. *
  309. *> \date September 2012
  310. *
  311. *> \ingroup doubleSYeigen
  312. *
  313. *> \par Contributors:
  314. * ==================
  315. *>
  316. *> Inderjit Dhillon, IBM Almaden, USA \n
  317. *> Osni Marques, LBNL/NERSC, USA \n
  318. *> Ken Stanley, Computer Science Division, University of
  319. *> California at Berkeley, USA \n
  320. *> Jason Riedy, Computer Science Division, University of
  321. *> California at Berkeley, USA \n
  322. *>
  323. * =====================================================================
  324. SUBROUTINE DSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
  325. $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
  326. $ IWORK, LIWORK, INFO )
  327. *
  328. * -- LAPACK driver routine (version 3.4.2) --
  329. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  330. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  331. * September 2012
  332. *
  333. * .. Scalar Arguments ..
  334. CHARACTER JOBZ, RANGE, UPLO
  335. INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
  336. DOUBLE PRECISION ABSTOL, VL, VU
  337. * ..
  338. * .. Array Arguments ..
  339. INTEGER ISUPPZ( * ), IWORK( * )
  340. DOUBLE PRECISION A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
  341. * ..
  342. *
  343. * =====================================================================
  344. *
  345. * .. Parameters ..
  346. DOUBLE PRECISION ZERO, ONE, TWO
  347. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0, TWO = 2.0D+0 )
  348. * ..
  349. * .. Local Scalars ..
  350. LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, VALEIG, WANTZ,
  351. $ TRYRAC
  352. CHARACTER ORDER
  353. INTEGER I, IEEEOK, IINFO, IMAX, INDD, INDDD, INDE,
  354. $ INDEE, INDIBL, INDIFL, INDISP, INDIWO, INDTAU,
  355. $ INDWK, INDWKN, ISCALE, J, JJ, LIWMIN,
  356. $ LLWORK, LLWRKN, LWKOPT, LWMIN, NB, NSPLIT
  357. DOUBLE PRECISION ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
  358. $ SIGMA, SMLNUM, TMP1, VLL, VUU
  359. * ..
  360. * .. External Functions ..
  361. LOGICAL LSAME
  362. INTEGER ILAENV
  363. DOUBLE PRECISION DLAMCH, DLANSY
  364. EXTERNAL LSAME, ILAENV, DLAMCH, DLANSY
  365. * ..
  366. * .. External Subroutines ..
  367. EXTERNAL DCOPY, DORMTR, DSCAL, DSTEBZ, DSTEMR, DSTEIN,
  368. $ DSTERF, DSWAP, DSYTRD, XERBLA
  369. * ..
  370. * .. Intrinsic Functions ..
  371. INTRINSIC MAX, MIN, SQRT
  372. * ..
  373. * .. Executable Statements ..
  374. *
  375. * Test the input parameters.
  376. *
  377. IEEEOK = ILAENV( 10, 'DSYEVR', 'N', 1, 2, 3, 4 )
  378. *
  379. LOWER = LSAME( UPLO, 'L' )
  380. WANTZ = LSAME( JOBZ, 'V' )
  381. ALLEIG = LSAME( RANGE, 'A' )
  382. VALEIG = LSAME( RANGE, 'V' )
  383. INDEIG = LSAME( RANGE, 'I' )
  384. *
  385. LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
  386. *
  387. LWMIN = MAX( 1, 26*N )
  388. LIWMIN = MAX( 1, 10*N )
  389. *
  390. INFO = 0
  391. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  392. INFO = -1
  393. ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
  394. INFO = -2
  395. ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
  396. INFO = -3
  397. ELSE IF( N.LT.0 ) THEN
  398. INFO = -4
  399. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  400. INFO = -6
  401. ELSE
  402. IF( VALEIG ) THEN
  403. IF( N.GT.0 .AND. VU.LE.VL )
  404. $ INFO = -8
  405. ELSE IF( INDEIG ) THEN
  406. IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
  407. INFO = -9
  408. ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
  409. INFO = -10
  410. END IF
  411. END IF
  412. END IF
  413. IF( INFO.EQ.0 ) THEN
  414. IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  415. INFO = -15
  416. ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  417. INFO = -18
  418. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  419. INFO = -20
  420. END IF
  421. END IF
  422. *
  423. IF( INFO.EQ.0 ) THEN
  424. NB = ILAENV( 1, 'DSYTRD', UPLO, N, -1, -1, -1 )
  425. NB = MAX( NB, ILAENV( 1, 'DORMTR', UPLO, N, -1, -1, -1 ) )
  426. LWKOPT = MAX( ( NB+1 )*N, LWMIN )
  427. WORK( 1 ) = LWKOPT
  428. IWORK( 1 ) = LIWMIN
  429. END IF
  430. *
  431. IF( INFO.NE.0 ) THEN
  432. CALL XERBLA( 'DSYEVR', -INFO )
  433. RETURN
  434. ELSE IF( LQUERY ) THEN
  435. RETURN
  436. END IF
  437. *
  438. * Quick return if possible
  439. *
  440. M = 0
  441. IF( N.EQ.0 ) THEN
  442. WORK( 1 ) = 1
  443. RETURN
  444. END IF
  445. *
  446. IF( N.EQ.1 ) THEN
  447. WORK( 1 ) = 7
  448. IF( ALLEIG .OR. INDEIG ) THEN
  449. M = 1
  450. W( 1 ) = A( 1, 1 )
  451. ELSE
  452. IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN
  453. M = 1
  454. W( 1 ) = A( 1, 1 )
  455. END IF
  456. END IF
  457. IF( WANTZ ) THEN
  458. Z( 1, 1 ) = ONE
  459. ISUPPZ( 1 ) = 1
  460. ISUPPZ( 2 ) = 1
  461. END IF
  462. RETURN
  463. END IF
  464. *
  465. * Get machine constants.
  466. *
  467. SAFMIN = DLAMCH( 'Safe minimum' )
  468. EPS = DLAMCH( 'Precision' )
  469. SMLNUM = SAFMIN / EPS
  470. BIGNUM = ONE / SMLNUM
  471. RMIN = SQRT( SMLNUM )
  472. RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
  473. *
  474. * Scale matrix to allowable range, if necessary.
  475. *
  476. ISCALE = 0
  477. ABSTLL = ABSTOL
  478. IF (VALEIG) THEN
  479. VLL = VL
  480. VUU = VU
  481. END IF
  482. ANRM = DLANSY( 'M', UPLO, N, A, LDA, WORK )
  483. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  484. ISCALE = 1
  485. SIGMA = RMIN / ANRM
  486. ELSE IF( ANRM.GT.RMAX ) THEN
  487. ISCALE = 1
  488. SIGMA = RMAX / ANRM
  489. END IF
  490. IF( ISCALE.EQ.1 ) THEN
  491. IF( LOWER ) THEN
  492. DO 10 J = 1, N
  493. CALL DSCAL( N-J+1, SIGMA, A( J, J ), 1 )
  494. 10 CONTINUE
  495. ELSE
  496. DO 20 J = 1, N
  497. CALL DSCAL( J, SIGMA, A( 1, J ), 1 )
  498. 20 CONTINUE
  499. END IF
  500. IF( ABSTOL.GT.0 )
  501. $ ABSTLL = ABSTOL*SIGMA
  502. IF( VALEIG ) THEN
  503. VLL = VL*SIGMA
  504. VUU = VU*SIGMA
  505. END IF
  506. END IF
  507. * Initialize indices into workspaces. Note: The IWORK indices are
  508. * used only if DSTERF or DSTEMR fail.
  509. * WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
  510. * elementary reflectors used in DSYTRD.
  511. INDTAU = 1
  512. * WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
  513. INDD = INDTAU + N
  514. * WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
  515. * tridiagonal matrix from DSYTRD.
  516. INDE = INDD + N
  517. * WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
  518. * -written by DSTEMR (the DSTERF path copies the diagonal to W).
  519. INDDD = INDE + N
  520. * WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
  521. * -written while computing the eigenvalues in DSTERF and DSTEMR.
  522. INDEE = INDDD + N
  523. * INDWK is the starting offset of the left-over workspace, and
  524. * LLWORK is the remaining workspace size.
  525. INDWK = INDEE + N
  526. LLWORK = LWORK - INDWK + 1
  527. * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in DSTEBZ and
  528. * stores the block indices of each of the M<=N eigenvalues.
  529. INDIBL = 1
  530. * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in DSTEBZ and
  531. * stores the starting and finishing indices of each block.
  532. INDISP = INDIBL + N
  533. * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
  534. * that corresponding to eigenvectors that fail to converge in
  535. * DSTEIN. This information is discarded; if any fail, the driver
  536. * returns INFO > 0.
  537. INDIFL = INDISP + N
  538. * INDIWO is the offset of the remaining integer workspace.
  539. INDIWO = INDIFL + N
  540. *
  541. * Call DSYTRD to reduce symmetric matrix to tridiagonal form.
  542. *
  543. CALL DSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ),
  544. $ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
  545. *
  546. * If all eigenvalues are desired
  547. * then call DSTERF or DSTEMR and DORMTR.
  548. *
  549. IF( ( ALLEIG .OR. ( INDEIG .AND. IL.EQ.1 .AND. IU.EQ.N ) ) .AND.
  550. $ IEEEOK.EQ.1 ) THEN
  551. IF( .NOT.WANTZ ) THEN
  552. CALL DCOPY( N, WORK( INDD ), 1, W, 1 )
  553. CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
  554. CALL DSTERF( N, W, WORK( INDEE ), INFO )
  555. ELSE
  556. CALL DCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
  557. CALL DCOPY( N, WORK( INDD ), 1, WORK( INDDD ), 1 )
  558. *
  559. IF (ABSTOL .LE. TWO*N*EPS) THEN
  560. TRYRAC = .TRUE.
  561. ELSE
  562. TRYRAC = .FALSE.
  563. END IF
  564. CALL DSTEMR( JOBZ, 'A', N, WORK( INDDD ), WORK( INDEE ),
  565. $ VL, VU, IL, IU, M, W, Z, LDZ, N, ISUPPZ,
  566. $ TRYRAC, WORK( INDWK ), LWORK, IWORK, LIWORK,
  567. $ INFO )
  568. *
  569. *
  570. *
  571. * Apply orthogonal matrix used in reduction to tridiagonal
  572. * form to eigenvectors returned by DSTEIN.
  573. *
  574. IF( WANTZ .AND. INFO.EQ.0 ) THEN
  575. INDWKN = INDE
  576. LLWRKN = LWORK - INDWKN + 1
  577. CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA,
  578. $ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
  579. $ LLWRKN, IINFO )
  580. END IF
  581. END IF
  582. *
  583. *
  584. IF( INFO.EQ.0 ) THEN
  585. * Everything worked. Skip DSTEBZ/DSTEIN. IWORK(:) are
  586. * undefined.
  587. M = N
  588. GO TO 30
  589. END IF
  590. INFO = 0
  591. END IF
  592. *
  593. * Otherwise, call DSTEBZ and, if eigenvectors are desired, DSTEIN.
  594. * Also call DSTEBZ and DSTEIN if DSTEMR fails.
  595. *
  596. IF( WANTZ ) THEN
  597. ORDER = 'B'
  598. ELSE
  599. ORDER = 'E'
  600. END IF
  601. CALL DSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
  602. $ WORK( INDD ), WORK( INDE ), M, NSPLIT, W,
  603. $ IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWK ),
  604. $ IWORK( INDIWO ), INFO )
  605. *
  606. IF( WANTZ ) THEN
  607. CALL DSTEIN( N, WORK( INDD ), WORK( INDE ), M, W,
  608. $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
  609. $ WORK( INDWK ), IWORK( INDIWO ), IWORK( INDIFL ),
  610. $ INFO )
  611. *
  612. * Apply orthogonal matrix used in reduction to tridiagonal
  613. * form to eigenvectors returned by DSTEIN.
  614. *
  615. INDWKN = INDE
  616. LLWRKN = LWORK - INDWKN + 1
  617. CALL DORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
  618. $ LDZ, WORK( INDWKN ), LLWRKN, IINFO )
  619. END IF
  620. *
  621. * If matrix was scaled, then rescale eigenvalues appropriately.
  622. *
  623. * Jump here if DSTEMR/DSTEIN succeeded.
  624. 30 CONTINUE
  625. IF( ISCALE.EQ.1 ) THEN
  626. IF( INFO.EQ.0 ) THEN
  627. IMAX = M
  628. ELSE
  629. IMAX = INFO - 1
  630. END IF
  631. CALL DSCAL( IMAX, ONE / SIGMA, W, 1 )
  632. END IF
  633. *
  634. * If eigenvalues are not in order, then sort them, along with
  635. * eigenvectors. Note: We do not sort the IFAIL portion of IWORK.
  636. * It may not be initialized (if DSTEMR/DSTEIN succeeded), and we do
  637. * not return this detailed information to the user.
  638. *
  639. IF( WANTZ ) THEN
  640. DO 50 J = 1, M - 1
  641. I = 0
  642. TMP1 = W( J )
  643. DO 40 JJ = J + 1, M
  644. IF( W( JJ ).LT.TMP1 ) THEN
  645. I = JJ
  646. TMP1 = W( JJ )
  647. END IF
  648. 40 CONTINUE
  649. *
  650. IF( I.NE.0 ) THEN
  651. W( I ) = W( J )
  652. W( J ) = TMP1
  653. CALL DSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
  654. END IF
  655. 50 CONTINUE
  656. END IF
  657. *
  658. * Set WORK(1) to optimal workspace size.
  659. *
  660. WORK( 1 ) = LWKOPT
  661. IWORK( 1 ) = LIWMIN
  662. *
  663. RETURN
  664. *
  665. * End of DSYEVR
  666. *
  667. END