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.

ssyevr.f 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694
  1. *> \brief <b> SSYEVR 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 SSYEVR + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/ssyevr.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/ssyevr.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/ssyevr.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SSYEVR( 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. * REAL ABSTOL, VL, VU
  29. * ..
  30. * .. Array Arguments ..
  31. * INTEGER ISUPPZ( * ), IWORK( * )
  32. * REAL A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
  33. * ..
  34. *
  35. *
  36. *> \par Purpose:
  37. * =============
  38. *>
  39. *> \verbatim
  40. *>
  41. *> SSYEVR 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. *> SSYEVR first reduces the matrix A to tridiagonal form T with a call
  47. *> to SSYTRD. Then, whenever possible, SSYEVR calls SSTEMR to compute
  48. *> the eigenspectrum using Relatively Robust Representations. SSTEMR
  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 SSTEMR'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 : SSYEVR calls SSTEMR when the full spectrum is requested
  90. *> on machines which conform to the ieee-754 floating point standard.
  91. *> SSYEVR calls SSTEBZ and SSTEIN on non-ieee machines and
  92. *> when partial spectrum requests are made.
  93. *>
  94. *> Normal execution of SSTEMR 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, SSTEBZ and
  118. *> SSTEIN 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 REAL 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 REAL
  156. *> If RANGE='V', the lower bound of the interval to
  157. *> be searched for eigenvalues. VL < VU.
  158. *> Not referenced if RANGE = 'A' or 'I'.
  159. *> \endverbatim
  160. *>
  161. *> \param[in] VU
  162. *> \verbatim
  163. *> VU is REAL
  164. *> If RANGE='V', the upper bound of the interval to
  165. *> be searched for eigenvalues. VL < VU.
  166. *> Not referenced if RANGE = 'A' or 'I'.
  167. *> \endverbatim
  168. *>
  169. *> \param[in] IL
  170. *> \verbatim
  171. *> IL is INTEGER
  172. *> If RANGE='I', the index of the
  173. *> smallest eigenvalue to be returned.
  174. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  175. *> Not referenced if RANGE = 'A' or 'V'.
  176. *> \endverbatim
  177. *>
  178. *> \param[in] IU
  179. *> \verbatim
  180. *> IU is INTEGER
  181. *> If RANGE='I', the index of the
  182. *> largest eigenvalue to be returned.
  183. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  184. *> Not referenced if RANGE = 'A' or 'V'.
  185. *> \endverbatim
  186. *>
  187. *> \param[in] ABSTOL
  188. *> \verbatim
  189. *> ABSTOL is REAL
  190. *> The absolute error tolerance for the eigenvalues.
  191. *> An approximate eigenvalue is accepted as converged
  192. *> when it is determined to lie in an interval [a,b]
  193. *> of width less than or equal to
  194. *>
  195. *> ABSTOL + EPS * max( |a|,|b| ) ,
  196. *>
  197. *> where EPS is the machine precision. If ABSTOL is less than
  198. *> or equal to zero, then EPS*|T| will be used in its place,
  199. *> where |T| is the 1-norm of the tridiagonal matrix obtained
  200. *> by reducing A to tridiagonal form.
  201. *>
  202. *> See "Computing Small Singular Values of Bidiagonal Matrices
  203. *> with Guaranteed High Relative Accuracy," by Demmel and
  204. *> Kahan, LAPACK Working Note #3.
  205. *>
  206. *> If high relative accuracy is important, set ABSTOL to
  207. *> SLAMCH( 'Safe minimum' ). Doing so will guarantee that
  208. *> eigenvalues are computed to high relative accuracy when
  209. *> possible in future releases. The current code does not
  210. *> make any guarantees about high relative accuracy, but
  211. *> future releases will. See J. Barlow and J. Demmel,
  212. *> "Computing Accurate Eigensystems of Scaled Diagonally
  213. *> Dominant Matrices", LAPACK Working Note #7, for a discussion
  214. *> of which matrices define their eigenvalues to high relative
  215. *> accuracy.
  216. *> \endverbatim
  217. *>
  218. *> \param[out] M
  219. *> \verbatim
  220. *> M is INTEGER
  221. *> The total number of eigenvalues found. 0 <= M <= N.
  222. *> If RANGE = 'A', M = N, and if RANGE = 'I', M = IU-IL+1.
  223. *> \endverbatim
  224. *>
  225. *> \param[out] W
  226. *> \verbatim
  227. *> W is REAL array, dimension (N)
  228. *> The first M elements contain the selected eigenvalues in
  229. *> ascending order.
  230. *> \endverbatim
  231. *>
  232. *> \param[out] Z
  233. *> \verbatim
  234. *> Z is REAL array, dimension (LDZ, max(1,M))
  235. *> If JOBZ = 'V', then if INFO = 0, the first M columns of Z
  236. *> contain the orthonormal eigenvectors of the matrix A
  237. *> corresponding to the selected eigenvalues, with the i-th
  238. *> column of Z holding the eigenvector associated with W(i).
  239. *> If JOBZ = 'N', then Z is not referenced.
  240. *> Note: the user must ensure that at least max(1,M) columns are
  241. *> supplied in the array Z; if RANGE = 'V', the exact value of M
  242. *> is not known in advance and an upper bound must be used.
  243. *> Supplying N columns is always safe.
  244. *> \endverbatim
  245. *>
  246. *> \param[in] LDZ
  247. *> \verbatim
  248. *> LDZ is INTEGER
  249. *> The leading dimension of the array Z. LDZ >= 1, and if
  250. *> JOBZ = 'V', LDZ >= max(1,N).
  251. *> \endverbatim
  252. *>
  253. *> \param[out] ISUPPZ
  254. *> \verbatim
  255. *> ISUPPZ is INTEGER array, dimension ( 2*max(1,M) )
  256. *> The support of the eigenvectors in Z, i.e., the indices
  257. *> indicating the nonzero elements in Z. The i-th eigenvector
  258. *> is nonzero only in elements ISUPPZ( 2*i-1 ) through
  259. *> ISUPPZ( 2*i ). This is an output of SSTEMR (tridiagonal
  260. *> matrix). The support of the eigenvectors of A is typically
  261. *> 1:N because of the orthogonal transformations applied by SORMTR.
  262. *> Implemented only for RANGE = 'A' or 'I' and IU - IL = N - 1
  263. *> \endverbatim
  264. *>
  265. *> \param[out] WORK
  266. *> \verbatim
  267. *> WORK is REAL array, dimension (MAX(1,LWORK))
  268. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  269. *> \endverbatim
  270. *>
  271. *> \param[in] LWORK
  272. *> \verbatim
  273. *> LWORK is INTEGER
  274. *> The dimension of the array WORK.
  275. *> If N <= 1, LWORK >= 1, else LWORK >= 26*N.
  276. *> For optimal efficiency, LWORK >= (NB+6)*N,
  277. *> where NB is the max of the blocksize for SSYTRD and SORMTR
  278. *> returned by ILAENV.
  279. *>
  280. *> If LWORK = -1, then a workspace query is assumed; the routine
  281. *> only calculates the optimal sizes of the WORK and IWORK
  282. *> arrays, returns these values as the first entries of the WORK
  283. *> and IWORK arrays, and no error message related to LWORK or
  284. *> LIWORK is issued by XERBLA.
  285. *> \endverbatim
  286. *>
  287. *> \param[out] IWORK
  288. *> \verbatim
  289. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  290. *> On exit, if INFO = 0, IWORK(1) returns the optimal LWORK.
  291. *> \endverbatim
  292. *>
  293. *> \param[in] LIWORK
  294. *> \verbatim
  295. *> LIWORK is INTEGER
  296. *> The dimension of the array IWORK.
  297. *> If N <= 1, LIWORK >= 1, else LIWORK >= 10*N.
  298. *>
  299. *> If LIWORK = -1, then a workspace query is assumed; the
  300. *> routine only calculates the optimal sizes of the WORK and
  301. *> IWORK arrays, returns these values as the first entries of
  302. *> the WORK and IWORK arrays, and no error message related to
  303. *> LWORK or LIWORK is issued by XERBLA.
  304. *> \endverbatim
  305. *>
  306. *> \param[out] INFO
  307. *> \verbatim
  308. *> INFO is INTEGER
  309. *> = 0: successful exit
  310. *> < 0: if INFO = -i, the i-th argument had an illegal value
  311. *> > 0: Internal error
  312. *> \endverbatim
  313. *
  314. * Authors:
  315. * ========
  316. *
  317. *> \author Univ. of Tennessee
  318. *> \author Univ. of California Berkeley
  319. *> \author Univ. of Colorado Denver
  320. *> \author NAG Ltd.
  321. *
  322. *> \ingroup heevr
  323. *
  324. *> \par Contributors:
  325. * ==================
  326. *>
  327. *> Inderjit Dhillon, IBM Almaden, USA \n
  328. *> Osni Marques, LBNL/NERSC, USA \n
  329. *> Ken Stanley, Computer Science Division, University of
  330. *> California at Berkeley, USA \n
  331. *> Jason Riedy, Computer Science Division, University of
  332. *> California at Berkeley, USA \n
  333. *>
  334. * =====================================================================
  335. SUBROUTINE SSYEVR( JOBZ, RANGE, UPLO, N, A, LDA, VL, VU, IL, IU,
  336. $ ABSTOL, M, W, Z, LDZ, ISUPPZ, WORK, LWORK,
  337. $ IWORK, LIWORK, INFO )
  338. *
  339. * -- LAPACK driver routine --
  340. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  341. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  342. *
  343. * .. Scalar Arguments ..
  344. CHARACTER JOBZ, RANGE, UPLO
  345. INTEGER IL, INFO, IU, LDA, LDZ, LIWORK, LWORK, M, N
  346. REAL ABSTOL, VL, VU
  347. * ..
  348. * .. Array Arguments ..
  349. INTEGER ISUPPZ( * ), IWORK( * )
  350. REAL A( LDA, * ), W( * ), WORK( * ), Z( LDZ, * )
  351. * ..
  352. *
  353. * =====================================================================
  354. *
  355. * .. Parameters ..
  356. REAL ZERO, ONE, TWO
  357. PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
  358. * ..
  359. * .. Local Scalars ..
  360. LOGICAL ALLEIG, INDEIG, LOWER, LQUERY, TEST, VALEIG,
  361. $ WANTZ, TRYRAC
  362. CHARACTER ORDER
  363. INTEGER I, IEEEOK, IINFO, IMAX, INDD, INDDD, INDE,
  364. $ INDEE, INDIBL, INDIFL, INDISP, INDIWO, INDTAU,
  365. $ INDWK, INDWKN, ISCALE, J, JJ, LIWMIN,
  366. $ LLWORK, LLWRKN, LWKOPT, LWMIN, NB, NSPLIT
  367. REAL ABSTLL, ANRM, BIGNUM, EPS, RMAX, RMIN, SAFMIN,
  368. $ SIGMA, SMLNUM, TMP1, VLL, VUU
  369. * ..
  370. * .. External Functions ..
  371. LOGICAL LSAME
  372. INTEGER ILAENV
  373. REAL SLAMCH, SLANSY, SROUNDUP_LWORK
  374. EXTERNAL LSAME, ILAENV, SLAMCH, SLANSY, SROUNDUP_LWORK
  375. * ..
  376. * .. External Subroutines ..
  377. EXTERNAL SCOPY, SORMTR, SSCAL, SSTEBZ, SSTEMR, SSTEIN,
  378. $ SSTERF, SSWAP, SSYTRD, XERBLA
  379. * ..
  380. * .. Intrinsic Functions ..
  381. INTRINSIC MAX, MIN, SQRT
  382. * ..
  383. * .. Executable Statements ..
  384. *
  385. * Test the input parameters.
  386. *
  387. IEEEOK = ILAENV( 10, 'SSYEVR', 'N', 1, 2, 3, 4 )
  388. *
  389. LOWER = LSAME( UPLO, 'L' )
  390. WANTZ = LSAME( JOBZ, 'V' )
  391. ALLEIG = LSAME( RANGE, 'A' )
  392. VALEIG = LSAME( RANGE, 'V' )
  393. INDEIG = LSAME( RANGE, 'I' )
  394. *
  395. LQUERY = ( ( LWORK.EQ.-1 ) .OR. ( LIWORK.EQ.-1 ) )
  396. *
  397. IF( N.LE.1 ) THEN
  398. LWMIN = 1
  399. LIWMIN = 1
  400. ELSE
  401. LWMIN = 26*N
  402. LIWMIN = 10*N
  403. END IF
  404. *
  405. INFO = 0
  406. IF( .NOT.( WANTZ .OR. LSAME( JOBZ, 'N' ) ) ) THEN
  407. INFO = -1
  408. ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
  409. INFO = -2
  410. ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO, 'U' ) ) ) THEN
  411. INFO = -3
  412. ELSE IF( N.LT.0 ) THEN
  413. INFO = -4
  414. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  415. INFO = -6
  416. ELSE
  417. IF( VALEIG ) THEN
  418. IF( N.GT.0 .AND. VU.LE.VL )
  419. $ INFO = -8
  420. ELSE IF( INDEIG ) THEN
  421. IF( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) THEN
  422. INFO = -9
  423. ELSE IF( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) THEN
  424. INFO = -10
  425. END IF
  426. END IF
  427. END IF
  428. IF( INFO.EQ.0 ) THEN
  429. IF( LDZ.LT.1 .OR. ( WANTZ .AND. LDZ.LT.N ) ) THEN
  430. INFO = -15
  431. END IF
  432. END IF
  433. *
  434. IF( INFO.EQ.0 ) THEN
  435. NB = ILAENV( 1, 'SSYTRD', UPLO, N, -1, -1, -1 )
  436. NB = MAX( NB, ILAENV( 1, 'SORMTR', UPLO, N, -1, -1, -1 ) )
  437. LWKOPT = MAX( ( NB+1 )*N, LWMIN )
  438. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  439. IWORK( 1 ) = LIWMIN
  440. *
  441. IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
  442. INFO = -18
  443. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT.LQUERY ) THEN
  444. INFO = -20
  445. END IF
  446. END IF
  447. *
  448. IF( INFO.NE.0 ) THEN
  449. CALL XERBLA( 'SSYEVR', -INFO )
  450. RETURN
  451. ELSE IF( LQUERY ) THEN
  452. RETURN
  453. END IF
  454. *
  455. * Quick return if possible
  456. *
  457. M = 0
  458. IF( N.EQ.0 ) THEN
  459. WORK( 1 ) = 1
  460. RETURN
  461. END IF
  462. *
  463. IF( N.EQ.1 ) THEN
  464. WORK( 1 ) = 26
  465. IF( ALLEIG .OR. INDEIG ) THEN
  466. M = 1
  467. W( 1 ) = A( 1, 1 )
  468. ELSE
  469. IF( VL.LT.A( 1, 1 ) .AND. VU.GE.A( 1, 1 ) ) THEN
  470. M = 1
  471. W( 1 ) = A( 1, 1 )
  472. END IF
  473. END IF
  474. IF( WANTZ ) THEN
  475. Z( 1, 1 ) = ONE
  476. ISUPPZ( 1 ) = 1
  477. ISUPPZ( 2 ) = 1
  478. END IF
  479. RETURN
  480. END IF
  481. *
  482. * Get machine constants.
  483. *
  484. SAFMIN = SLAMCH( 'Safe minimum' )
  485. EPS = SLAMCH( 'Precision' )
  486. SMLNUM = SAFMIN / EPS
  487. BIGNUM = ONE / SMLNUM
  488. RMIN = SQRT( SMLNUM )
  489. RMAX = MIN( SQRT( BIGNUM ), ONE / SQRT( SQRT( SAFMIN ) ) )
  490. *
  491. * Scale matrix to allowable range, if necessary.
  492. *
  493. ISCALE = 0
  494. ABSTLL = ABSTOL
  495. IF (VALEIG) THEN
  496. VLL = VL
  497. VUU = VU
  498. END IF
  499. ANRM = SLANSY( 'M', UPLO, N, A, LDA, WORK )
  500. IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
  501. ISCALE = 1
  502. SIGMA = RMIN / ANRM
  503. ELSE IF( ANRM.GT.RMAX ) THEN
  504. ISCALE = 1
  505. SIGMA = RMAX / ANRM
  506. END IF
  507. IF( ISCALE.EQ.1 ) THEN
  508. IF( LOWER ) THEN
  509. DO 10 J = 1, N
  510. CALL SSCAL( N-J+1, SIGMA, A( J, J ), 1 )
  511. 10 CONTINUE
  512. ELSE
  513. DO 20 J = 1, N
  514. CALL SSCAL( J, SIGMA, A( 1, J ), 1 )
  515. 20 CONTINUE
  516. END IF
  517. IF( ABSTOL.GT.0 )
  518. $ ABSTLL = ABSTOL*SIGMA
  519. IF( VALEIG ) THEN
  520. VLL = VL*SIGMA
  521. VUU = VU*SIGMA
  522. END IF
  523. END IF
  524. * Initialize indices into workspaces. Note: The IWORK indices are
  525. * used only if SSTERF or SSTEMR fail.
  526. * WORK(INDTAU:INDTAU+N-1) stores the scalar factors of the
  527. * elementary reflectors used in SSYTRD.
  528. INDTAU = 1
  529. * WORK(INDD:INDD+N-1) stores the tridiagonal's diagonal entries.
  530. INDD = INDTAU + N
  531. * WORK(INDE:INDE+N-1) stores the off-diagonal entries of the
  532. * tridiagonal matrix from SSYTRD.
  533. INDE = INDD + N
  534. * WORK(INDDD:INDDD+N-1) is a copy of the diagonal entries over
  535. * -written by SSTEMR (the SSTERF path copies the diagonal to W).
  536. INDDD = INDE + N
  537. * WORK(INDEE:INDEE+N-1) is a copy of the off-diagonal entries over
  538. * -written while computing the eigenvalues in SSTERF and SSTEMR.
  539. INDEE = INDDD + N
  540. * INDWK is the starting offset of the left-over workspace, and
  541. * LLWORK is the remaining workspace size.
  542. INDWK = INDEE + N
  543. LLWORK = LWORK - INDWK + 1
  544. * IWORK(INDIBL:INDIBL+M-1) corresponds to IBLOCK in SSTEBZ and
  545. * stores the block indices of each of the M<=N eigenvalues.
  546. INDIBL = 1
  547. * IWORK(INDISP:INDISP+NSPLIT-1) corresponds to ISPLIT in SSTEBZ and
  548. * stores the starting and finishing indices of each block.
  549. INDISP = INDIBL + N
  550. * IWORK(INDIFL:INDIFL+N-1) stores the indices of eigenvectors
  551. * that corresponding to eigenvectors that fail to converge in
  552. * SSTEIN. This information is discarded; if any fail, the driver
  553. * returns INFO > 0.
  554. INDIFL = INDISP + N
  555. * INDIWO is the offset of the remaining integer workspace.
  556. INDIWO = INDIFL + N
  557. *
  558. * Call SSYTRD to reduce symmetric matrix to tridiagonal form.
  559. *
  560. CALL SSYTRD( UPLO, N, A, LDA, WORK( INDD ), WORK( INDE ),
  561. $ WORK( INDTAU ), WORK( INDWK ), LLWORK, IINFO )
  562. *
  563. * If all eigenvalues are desired
  564. * then call SSTERF or SSTEMR and SORMTR.
  565. *
  566. TEST = .FALSE.
  567. IF( INDEIG ) THEN
  568. IF( IL.EQ.1 .AND. IU.EQ.N ) THEN
  569. TEST = .TRUE.
  570. END IF
  571. END IF
  572. IF( ( ALLEIG.OR.TEST ) .AND. ( IEEEOK.EQ.1 ) ) THEN
  573. IF( .NOT.WANTZ ) THEN
  574. CALL SCOPY( N, WORK( INDD ), 1, W, 1 )
  575. CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
  576. CALL SSTERF( N, W, WORK( INDEE ), INFO )
  577. ELSE
  578. CALL SCOPY( N-1, WORK( INDE ), 1, WORK( INDEE ), 1 )
  579. CALL SCOPY( N, WORK( INDD ), 1, WORK( INDDD ), 1 )
  580. *
  581. IF (ABSTOL .LE. TWO*N*EPS) THEN
  582. TRYRAC = .TRUE.
  583. ELSE
  584. TRYRAC = .FALSE.
  585. END IF
  586. CALL SSTEMR( JOBZ, 'A', N, WORK( INDDD ), WORK( INDEE ),
  587. $ VL, VU, IL, IU, M, W, Z, LDZ, N, ISUPPZ,
  588. $ TRYRAC, WORK( INDWK ), LWORK, IWORK, LIWORK,
  589. $ INFO )
  590. *
  591. *
  592. *
  593. * Apply orthogonal matrix used in reduction to tridiagonal
  594. * form to eigenvectors returned by SSTEMR.
  595. *
  596. IF( WANTZ .AND. INFO.EQ.0 ) THEN
  597. INDWKN = INDE
  598. LLWRKN = LWORK - INDWKN + 1
  599. CALL SORMTR( 'L', UPLO, 'N', N, M, A, LDA,
  600. $ WORK( INDTAU ), Z, LDZ, WORK( INDWKN ),
  601. $ LLWRKN, IINFO )
  602. END IF
  603. END IF
  604. *
  605. *
  606. IF( INFO.EQ.0 ) THEN
  607. * Everything worked. Skip SSTEBZ/SSTEIN. IWORK(:) are
  608. * undefined.
  609. M = N
  610. GO TO 30
  611. END IF
  612. INFO = 0
  613. END IF
  614. *
  615. * Otherwise, call SSTEBZ and, if eigenvectors are desired, SSTEIN.
  616. * Also call SSTEBZ and SSTEIN if SSTEMR fails.
  617. *
  618. IF( WANTZ ) THEN
  619. ORDER = 'B'
  620. ELSE
  621. ORDER = 'E'
  622. END IF
  623. CALL SSTEBZ( RANGE, ORDER, N, VLL, VUU, IL, IU, ABSTLL,
  624. $ WORK( INDD ), WORK( INDE ), M, NSPLIT, W,
  625. $ IWORK( INDIBL ), IWORK( INDISP ), WORK( INDWK ),
  626. $ IWORK( INDIWO ), INFO )
  627. *
  628. IF( WANTZ ) THEN
  629. CALL SSTEIN( N, WORK( INDD ), WORK( INDE ), M, W,
  630. $ IWORK( INDIBL ), IWORK( INDISP ), Z, LDZ,
  631. $ WORK( INDWK ), IWORK( INDIWO ), IWORK( INDIFL ),
  632. $ INFO )
  633. *
  634. * Apply orthogonal matrix used in reduction to tridiagonal
  635. * form to eigenvectors returned by SSTEIN.
  636. *
  637. INDWKN = INDE
  638. LLWRKN = LWORK - INDWKN + 1
  639. CALL SORMTR( 'L', UPLO, 'N', N, M, A, LDA, WORK( INDTAU ), Z,
  640. $ LDZ, WORK( INDWKN ), LLWRKN, IINFO )
  641. END IF
  642. *
  643. * If matrix was scaled, then rescale eigenvalues appropriately.
  644. *
  645. * Jump here if SSTEMR/SSTEIN succeeded.
  646. 30 CONTINUE
  647. IF( ISCALE.EQ.1 ) THEN
  648. IF( INFO.EQ.0 ) THEN
  649. IMAX = M
  650. ELSE
  651. IMAX = INFO - 1
  652. END IF
  653. CALL SSCAL( IMAX, ONE / SIGMA, W, 1 )
  654. END IF
  655. *
  656. * If eigenvalues are not in order, then sort them, along with
  657. * eigenvectors. Note: We do not sort the IFAIL portion of IWORK.
  658. * It may not be initialized (if SSTEMR/SSTEIN succeeded), and we do
  659. * not return this detailed information to the user.
  660. *
  661. IF( WANTZ ) THEN
  662. DO 50 J = 1, M - 1
  663. I = 0
  664. TMP1 = W( J )
  665. DO 40 JJ = J + 1, M
  666. IF( W( JJ ).LT.TMP1 ) THEN
  667. I = JJ
  668. TMP1 = W( JJ )
  669. END IF
  670. 40 CONTINUE
  671. *
  672. IF( I.NE.0 ) THEN
  673. W( I ) = W( J )
  674. W( J ) = TMP1
  675. CALL SSWAP( N, Z( 1, I ), 1, Z( 1, J ), 1 )
  676. END IF
  677. 50 CONTINUE
  678. END IF
  679. *
  680. * Set WORK(1) to optimal workspace size.
  681. *
  682. WORK( 1 ) = SROUNDUP_LWORK( LWKOPT )
  683. IWORK( 1 ) = LIWMIN
  684. *
  685. RETURN
  686. *
  687. * End of SSYEVR
  688. *
  689. END