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.

slarrd.f 30 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866
  1. *> \brief \b SLARRD computes the eigenvalues of a symmetric tridiagonal matrix to suitable accuracy.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLARRD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarrd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarrd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarrd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLARRD( RANGE, ORDER, N, VL, VU, IL, IU, GERS,
  22. * RELTOL, D, E, E2, PIVMIN, NSPLIT, ISPLIT,
  23. * M, W, WERR, WL, WU, IBLOCK, INDEXW,
  24. * WORK, IWORK, INFO )
  25. *
  26. * .. Scalar Arguments ..
  27. * CHARACTER ORDER, RANGE
  28. * INTEGER IL, INFO, IU, M, N, NSPLIT
  29. * REAL PIVMIN, RELTOL, VL, VU, WL, WU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER IBLOCK( * ), INDEXW( * ),
  33. * $ ISPLIT( * ), IWORK( * )
  34. * REAL D( * ), E( * ), E2( * ),
  35. * $ GERS( * ), W( * ), WERR( * ), WORK( * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> SLARRD computes the eigenvalues of a symmetric tridiagonal
  45. *> matrix T to suitable accuracy. This is an auxiliary code to be
  46. *> called from SSTEMR.
  47. *> The user may ask for all eigenvalues, all eigenvalues
  48. *> in the half-open interval (VL, VU], or the IL-th through IU-th
  49. *> eigenvalues.
  50. *>
  51. *> To avoid overflow, the matrix must be scaled so that its
  52. *> largest element is no greater than overflow**(1/2) * underflow**(1/4) in absolute value, and for greatest
  53. *> accuracy, it should not be much smaller than that.
  54. *>
  55. *> See W. Kahan "Accurate Eigenvalues of a Symmetric Tridiagonal
  56. *> Matrix", Report CS41, Computer Science Dept., Stanford
  57. *> University, July 21, 1966.
  58. *> \endverbatim
  59. *
  60. * Arguments:
  61. * ==========
  62. *
  63. *> \param[in] RANGE
  64. *> \verbatim
  65. *> RANGE is CHARACTER*1
  66. *> = 'A': ("All") all eigenvalues will be found.
  67. *> = 'V': ("Value") all eigenvalues in the half-open interval
  68. *> (VL, VU] will be found.
  69. *> = 'I': ("Index") the IL-th through IU-th eigenvalues (of the
  70. *> entire matrix) will be found.
  71. *> \endverbatim
  72. *>
  73. *> \param[in] ORDER
  74. *> \verbatim
  75. *> ORDER is CHARACTER*1
  76. *> = 'B': ("By Block") the eigenvalues will be grouped by
  77. *> split-off block (see IBLOCK, ISPLIT) and
  78. *> ordered from smallest to largest within
  79. *> the block.
  80. *> = 'E': ("Entire matrix")
  81. *> the eigenvalues for the entire matrix
  82. *> will be ordered from smallest to
  83. *> largest.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] N
  87. *> \verbatim
  88. *> N is INTEGER
  89. *> The order of the tridiagonal matrix T. N >= 0.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] VL
  93. *> \verbatim
  94. *> VL is REAL
  95. *> If RANGE='V', the lower bound of the interval to
  96. *> be searched for eigenvalues. Eigenvalues less than or equal
  97. *> to VL, or greater than VU, will not be returned. VL < VU.
  98. *> Not referenced if RANGE = 'A' or 'I'.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] VU
  102. *> \verbatim
  103. *> VU is REAL
  104. *> If RANGE='V', the upper bound of the interval to
  105. *> be searched for eigenvalues. Eigenvalues less than or equal
  106. *> to VL, or greater than VU, will not be returned. VL < VU.
  107. *> Not referenced if RANGE = 'A' or 'I'.
  108. *> \endverbatim
  109. *>
  110. *> \param[in] IL
  111. *> \verbatim
  112. *> IL is INTEGER
  113. *> If RANGE='I', the index of the
  114. *> smallest eigenvalue to be returned.
  115. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  116. *> Not referenced if RANGE = 'A' or 'V'.
  117. *> \endverbatim
  118. *>
  119. *> \param[in] IU
  120. *> \verbatim
  121. *> IU is INTEGER
  122. *> If RANGE='I', the index of the
  123. *> largest eigenvalue to be returned.
  124. *> 1 <= IL <= IU <= N, if N > 0; IL = 1 and IU = 0 if N = 0.
  125. *> Not referenced if RANGE = 'A' or 'V'.
  126. *> \endverbatim
  127. *>
  128. *> \param[in] GERS
  129. *> \verbatim
  130. *> GERS is REAL array, dimension (2*N)
  131. *> The N Gerschgorin intervals (the i-th Gerschgorin interval
  132. *> is (GERS(2*i-1), GERS(2*i)).
  133. *> \endverbatim
  134. *>
  135. *> \param[in] RELTOL
  136. *> \verbatim
  137. *> RELTOL is REAL
  138. *> The minimum relative width of an interval. When an interval
  139. *> is narrower than RELTOL times the larger (in
  140. *> magnitude) endpoint, then it is considered to be
  141. *> sufficiently small, i.e., converged. Note: this should
  142. *> always be at least radix*machine epsilon.
  143. *> \endverbatim
  144. *>
  145. *> \param[in] D
  146. *> \verbatim
  147. *> D is REAL array, dimension (N)
  148. *> The n diagonal elements of the tridiagonal matrix T.
  149. *> \endverbatim
  150. *>
  151. *> \param[in] E
  152. *> \verbatim
  153. *> E is REAL array, dimension (N-1)
  154. *> The (n-1) off-diagonal elements of the tridiagonal matrix T.
  155. *> \endverbatim
  156. *>
  157. *> \param[in] E2
  158. *> \verbatim
  159. *> E2 is REAL array, dimension (N-1)
  160. *> The (n-1) squared off-diagonal elements of the tridiagonal matrix T.
  161. *> \endverbatim
  162. *>
  163. *> \param[in] PIVMIN
  164. *> \verbatim
  165. *> PIVMIN is REAL
  166. *> The minimum pivot allowed in the Sturm sequence for T.
  167. *> \endverbatim
  168. *>
  169. *> \param[in] NSPLIT
  170. *> \verbatim
  171. *> NSPLIT is INTEGER
  172. *> The number of diagonal blocks in the matrix T.
  173. *> 1 <= NSPLIT <= N.
  174. *> \endverbatim
  175. *>
  176. *> \param[in] ISPLIT
  177. *> \verbatim
  178. *> ISPLIT is INTEGER array, dimension (N)
  179. *> The splitting points, at which T breaks up into submatrices.
  180. *> The first submatrix consists of rows/columns 1 to ISPLIT(1),
  181. *> the second of rows/columns ISPLIT(1)+1 through ISPLIT(2),
  182. *> etc., and the NSPLIT-th consists of rows/columns
  183. *> ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N.
  184. *> (Only the first NSPLIT elements will actually be used, but
  185. *> since the user cannot know a priori what value NSPLIT will
  186. *> have, N words must be reserved for ISPLIT.)
  187. *> \endverbatim
  188. *>
  189. *> \param[out] M
  190. *> \verbatim
  191. *> M is INTEGER
  192. *> The actual number of eigenvalues found. 0 <= M <= N.
  193. *> (See also the description of INFO=2,3.)
  194. *> \endverbatim
  195. *>
  196. *> \param[out] W
  197. *> \verbatim
  198. *> W is REAL array, dimension (N)
  199. *> On exit, the first M elements of W will contain the
  200. *> eigenvalue approximations. SLARRD computes an interval
  201. *> I_j = (a_j, b_j] that includes eigenvalue j. The eigenvalue
  202. *> approximation is given as the interval midpoint
  203. *> W(j)= ( a_j + b_j)/2. The corresponding error is bounded by
  204. *> WERR(j) = abs( a_j - b_j)/2
  205. *> \endverbatim
  206. *>
  207. *> \param[out] WERR
  208. *> \verbatim
  209. *> WERR is REAL array, dimension (N)
  210. *> The error bound on the corresponding eigenvalue approximation
  211. *> in W.
  212. *> \endverbatim
  213. *>
  214. *> \param[out] WL
  215. *> \verbatim
  216. *> WL is REAL
  217. *> \endverbatim
  218. *>
  219. *> \param[out] WU
  220. *> \verbatim
  221. *> WU is REAL
  222. *> The interval (WL, WU] contains all the wanted eigenvalues.
  223. *> If RANGE='V', then WL=VL and WU=VU.
  224. *> If RANGE='A', then WL and WU are the global Gerschgorin bounds
  225. *> on the spectrum.
  226. *> If RANGE='I', then WL and WU are computed by SLAEBZ from the
  227. *> index range specified.
  228. *> \endverbatim
  229. *>
  230. *> \param[out] IBLOCK
  231. *> \verbatim
  232. *> IBLOCK is INTEGER array, dimension (N)
  233. *> At each row/column j where E(j) is zero or small, the
  234. *> matrix T is considered to split into a block diagonal
  235. *> matrix. On exit, if INFO = 0, IBLOCK(i) specifies to which
  236. *> block (from 1 to the number of blocks) the eigenvalue W(i)
  237. *> belongs. (SLARRD may use the remaining N-M elements as
  238. *> workspace.)
  239. *> \endverbatim
  240. *>
  241. *> \param[out] INDEXW
  242. *> \verbatim
  243. *> INDEXW is INTEGER array, dimension (N)
  244. *> The indices of the eigenvalues within each block (submatrix);
  245. *> for example, INDEXW(i)= j and IBLOCK(i)=k imply that the
  246. *> i-th eigenvalue W(i) is the j-th eigenvalue in block k.
  247. *> \endverbatim
  248. *>
  249. *> \param[out] WORK
  250. *> \verbatim
  251. *> WORK is REAL array, dimension (4*N)
  252. *> \endverbatim
  253. *>
  254. *> \param[out] IWORK
  255. *> \verbatim
  256. *> IWORK is INTEGER array, dimension (3*N)
  257. *> \endverbatim
  258. *>
  259. *> \param[out] INFO
  260. *> \verbatim
  261. *> INFO is INTEGER
  262. *> = 0: successful exit
  263. *> < 0: if INFO = -i, the i-th argument had an illegal value
  264. *> > 0: some or all of the eigenvalues failed to converge or
  265. *> were not computed:
  266. *> =1 or 3: Bisection failed to converge for some
  267. *> eigenvalues; these eigenvalues are flagged by a
  268. *> negative block number. The effect is that the
  269. *> eigenvalues may not be as accurate as the
  270. *> absolute and relative tolerances. This is
  271. *> generally caused by unexpectedly inaccurate
  272. *> arithmetic.
  273. *> =2 or 3: RANGE='I' only: Not all of the eigenvalues
  274. *> IL:IU were found.
  275. *> Effect: M < IU+1-IL
  276. *> Cause: non-monotonic arithmetic, causing the
  277. *> Sturm sequence to be non-monotonic.
  278. *> Cure: recalculate, using RANGE='A', and pick
  279. *> out eigenvalues IL:IU. In some cases,
  280. *> increasing the PARAMETER "FUDGE" may
  281. *> make things work.
  282. *> = 4: RANGE='I', and the Gershgorin interval
  283. *> initially used was too small. No eigenvalues
  284. *> were computed.
  285. *> Probable cause: your machine has sloppy
  286. *> floating-point arithmetic.
  287. *> Cure: Increase the PARAMETER "FUDGE",
  288. *> recompile, and try again.
  289. *> \endverbatim
  290. *
  291. *> \par Internal Parameters:
  292. * =========================
  293. *>
  294. *> \verbatim
  295. *> FUDGE REAL, default = 2
  296. *> A "fudge factor" to widen the Gershgorin intervals. Ideally,
  297. *> a value of 1 should work, but on machines with sloppy
  298. *> arithmetic, this needs to be larger. The default for
  299. *> publicly released versions should be large enough to handle
  300. *> the worst machine around. Note that this has no effect
  301. *> on accuracy of the solution.
  302. *> \endverbatim
  303. *>
  304. *> \par Contributors:
  305. * ==================
  306. *>
  307. *> W. Kahan, University of California, Berkeley, USA \n
  308. *> Beresford Parlett, University of California, Berkeley, USA \n
  309. *> Jim Demmel, University of California, Berkeley, USA \n
  310. *> Inderjit Dhillon, University of Texas, Austin, USA \n
  311. *> Osni Marques, LBNL/NERSC, USA \n
  312. *> Christof Voemel, University of California, Berkeley, USA \n
  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 OTHERauxiliary
  323. *
  324. * =====================================================================
  325. SUBROUTINE SLARRD( RANGE, ORDER, N, VL, VU, IL, IU, GERS,
  326. $ RELTOL, D, E, E2, PIVMIN, NSPLIT, ISPLIT,
  327. $ M, W, WERR, WL, WU, IBLOCK, INDEXW,
  328. $ WORK, IWORK, INFO )
  329. *
  330. * -- LAPACK auxiliary routine --
  331. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  332. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  333. *
  334. * .. Scalar Arguments ..
  335. CHARACTER ORDER, RANGE
  336. INTEGER IL, INFO, IU, M, N, NSPLIT
  337. REAL PIVMIN, RELTOL, VL, VU, WL, WU
  338. * ..
  339. * .. Array Arguments ..
  340. INTEGER IBLOCK( * ), INDEXW( * ),
  341. $ ISPLIT( * ), IWORK( * )
  342. REAL D( * ), E( * ), E2( * ),
  343. $ GERS( * ), W( * ), WERR( * ), WORK( * )
  344. * ..
  345. *
  346. * =====================================================================
  347. *
  348. * .. Parameters ..
  349. REAL ZERO, ONE, TWO, HALF, FUDGE
  350. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0,
  351. $ TWO = 2.0E0, HALF = ONE/TWO,
  352. $ FUDGE = TWO )
  353. INTEGER ALLRNG, VALRNG, INDRNG
  354. PARAMETER ( ALLRNG = 1, VALRNG = 2, INDRNG = 3 )
  355. * ..
  356. * .. Local Scalars ..
  357. LOGICAL NCNVRG, TOOFEW
  358. INTEGER I, IB, IBEGIN, IDISCL, IDISCU, IE, IEND, IINFO,
  359. $ IM, IN, IOFF, IOUT, IRANGE, ITMAX, ITMP1,
  360. $ ITMP2, IW, IWOFF, J, JBLK, JDISC, JE, JEE, NB,
  361. $ NWL, NWU
  362. REAL ATOLI, EPS, GL, GU, RTOLI, TMP1, TMP2,
  363. $ TNORM, UFLOW, WKILL, WLU, WUL
  364. * ..
  365. * .. Local Arrays ..
  366. INTEGER IDUMMA( 1 )
  367. * ..
  368. * .. External Functions ..
  369. LOGICAL LSAME
  370. INTEGER ILAENV
  371. REAL SLAMCH
  372. EXTERNAL LSAME, ILAENV, SLAMCH
  373. * ..
  374. * .. External Subroutines ..
  375. EXTERNAL SLAEBZ
  376. * ..
  377. * .. Intrinsic Functions ..
  378. INTRINSIC ABS, INT, LOG, MAX, MIN
  379. * ..
  380. * .. Executable Statements ..
  381. *
  382. INFO = 0
  383. *
  384. * Quick return if possible
  385. *
  386. IF( N.LE.0 ) THEN
  387. RETURN
  388. END IF
  389. *
  390. * Decode RANGE
  391. *
  392. IF( LSAME( RANGE, 'A' ) ) THEN
  393. IRANGE = ALLRNG
  394. ELSE IF( LSAME( RANGE, 'V' ) ) THEN
  395. IRANGE = VALRNG
  396. ELSE IF( LSAME( RANGE, 'I' ) ) THEN
  397. IRANGE = INDRNG
  398. ELSE
  399. IRANGE = 0
  400. END IF
  401. *
  402. * Check for Errors
  403. *
  404. IF( IRANGE.LE.0 ) THEN
  405. INFO = -1
  406. ELSE IF( .NOT.(LSAME(ORDER,'B').OR.LSAME(ORDER,'E')) ) THEN
  407. INFO = -2
  408. ELSE IF( N.LT.0 ) THEN
  409. INFO = -3
  410. ELSE IF( IRANGE.EQ.VALRNG ) THEN
  411. IF( VL.GE.VU )
  412. $ INFO = -5
  413. ELSE IF( IRANGE.EQ.INDRNG .AND.
  414. $ ( IL.LT.1 .OR. IL.GT.MAX( 1, N ) ) ) THEN
  415. INFO = -6
  416. ELSE IF( IRANGE.EQ.INDRNG .AND.
  417. $ ( IU.LT.MIN( N, IL ) .OR. IU.GT.N ) ) THEN
  418. INFO = -7
  419. END IF
  420. *
  421. IF( INFO.NE.0 ) THEN
  422. RETURN
  423. END IF
  424. * Initialize error flags
  425. INFO = 0
  426. NCNVRG = .FALSE.
  427. TOOFEW = .FALSE.
  428. * Quick return if possible
  429. M = 0
  430. IF( N.EQ.0 ) RETURN
  431. * Simplification:
  432. IF( IRANGE.EQ.INDRNG .AND. IL.EQ.1 .AND. IU.EQ.N ) IRANGE = 1
  433. * Get machine constants
  434. EPS = SLAMCH( 'P' )
  435. UFLOW = SLAMCH( 'U' )
  436. * Special Case when N=1
  437. * Treat case of 1x1 matrix for quick return
  438. IF( N.EQ.1 ) THEN
  439. IF( (IRANGE.EQ.ALLRNG).OR.
  440. $ ((IRANGE.EQ.VALRNG).AND.(D(1).GT.VL).AND.(D(1).LE.VU)).OR.
  441. $ ((IRANGE.EQ.INDRNG).AND.(IL.EQ.1).AND.(IU.EQ.1)) ) THEN
  442. M = 1
  443. W(1) = D(1)
  444. * The computation error of the eigenvalue is zero
  445. WERR(1) = ZERO
  446. IBLOCK( 1 ) = 1
  447. INDEXW( 1 ) = 1
  448. ENDIF
  449. RETURN
  450. END IF
  451. * NB is the minimum vector length for vector bisection, or 0
  452. * if only scalar is to be done.
  453. NB = ILAENV( 1, 'SSTEBZ', ' ', N, -1, -1, -1 )
  454. IF( NB.LE.1 ) NB = 0
  455. * Find global spectral radius
  456. GL = D(1)
  457. GU = D(1)
  458. DO 5 I = 1,N
  459. GL = MIN( GL, GERS( 2*I - 1))
  460. GU = MAX( GU, GERS(2*I) )
  461. 5 CONTINUE
  462. * Compute global Gerschgorin bounds and spectral diameter
  463. TNORM = MAX( ABS( GL ), ABS( GU ) )
  464. GL = GL - FUDGE*TNORM*EPS*N - FUDGE*TWO*PIVMIN
  465. GU = GU + FUDGE*TNORM*EPS*N + FUDGE*TWO*PIVMIN
  466. * [JAN/28/2009] remove the line below since SPDIAM variable not use
  467. * SPDIAM = GU - GL
  468. * Input arguments for SLAEBZ:
  469. * The relative tolerance. An interval (a,b] lies within
  470. * "relative tolerance" if b-a < RELTOL*max(|a|,|b|),
  471. RTOLI = RELTOL
  472. * Set the absolute tolerance for interval convergence to zero to force
  473. * interval convergence based on relative size of the interval.
  474. * This is dangerous because intervals might not converge when RELTOL is
  475. * small. But at least a very small number should be selected so that for
  476. * strongly graded matrices, the code can get relatively accurate
  477. * eigenvalues.
  478. ATOLI = FUDGE*TWO*UFLOW + FUDGE*TWO*PIVMIN
  479. IF( IRANGE.EQ.INDRNG ) THEN
  480. * RANGE='I': Compute an interval containing eigenvalues
  481. * IL through IU. The initial interval [GL,GU] from the global
  482. * Gerschgorin bounds GL and GU is refined by SLAEBZ.
  483. ITMAX = INT( ( LOG( TNORM+PIVMIN )-LOG( PIVMIN ) ) /
  484. $ LOG( TWO ) ) + 2
  485. WORK( N+1 ) = GL
  486. WORK( N+2 ) = GL
  487. WORK( N+3 ) = GU
  488. WORK( N+4 ) = GU
  489. WORK( N+5 ) = GL
  490. WORK( N+6 ) = GU
  491. IWORK( 1 ) = -1
  492. IWORK( 2 ) = -1
  493. IWORK( 3 ) = N + 1
  494. IWORK( 4 ) = N + 1
  495. IWORK( 5 ) = IL - 1
  496. IWORK( 6 ) = IU
  497. *
  498. CALL SLAEBZ( 3, ITMAX, N, 2, 2, NB, ATOLI, RTOLI, PIVMIN,
  499. $ D, E, E2, IWORK( 5 ), WORK( N+1 ), WORK( N+5 ), IOUT,
  500. $ IWORK, W, IBLOCK, IINFO )
  501. IF( IINFO .NE. 0 ) THEN
  502. INFO = IINFO
  503. RETURN
  504. END IF
  505. * On exit, output intervals may not be ordered by ascending negcount
  506. IF( IWORK( 6 ).EQ.IU ) THEN
  507. WL = WORK( N+1 )
  508. WLU = WORK( N+3 )
  509. NWL = IWORK( 1 )
  510. WU = WORK( N+4 )
  511. WUL = WORK( N+2 )
  512. NWU = IWORK( 4 )
  513. ELSE
  514. WL = WORK( N+2 )
  515. WLU = WORK( N+4 )
  516. NWL = IWORK( 2 )
  517. WU = WORK( N+3 )
  518. WUL = WORK( N+1 )
  519. NWU = IWORK( 3 )
  520. END IF
  521. * On exit, the interval [WL, WLU] contains a value with negcount NWL,
  522. * and [WUL, WU] contains a value with negcount NWU.
  523. IF( NWL.LT.0 .OR. NWL.GE.N .OR. NWU.LT.1 .OR. NWU.GT.N ) THEN
  524. INFO = 4
  525. RETURN
  526. END IF
  527. ELSEIF( IRANGE.EQ.VALRNG ) THEN
  528. WL = VL
  529. WU = VU
  530. ELSEIF( IRANGE.EQ.ALLRNG ) THEN
  531. WL = GL
  532. WU = GU
  533. ENDIF
  534. * Find Eigenvalues -- Loop Over blocks and recompute NWL and NWU.
  535. * NWL accumulates the number of eigenvalues .le. WL,
  536. * NWU accumulates the number of eigenvalues .le. WU
  537. M = 0
  538. IEND = 0
  539. INFO = 0
  540. NWL = 0
  541. NWU = 0
  542. *
  543. DO 70 JBLK = 1, NSPLIT
  544. IOFF = IEND
  545. IBEGIN = IOFF + 1
  546. IEND = ISPLIT( JBLK )
  547. IN = IEND - IOFF
  548. *
  549. IF( IN.EQ.1 ) THEN
  550. * 1x1 block
  551. IF( WL.GE.D( IBEGIN )-PIVMIN )
  552. $ NWL = NWL + 1
  553. IF( WU.GE.D( IBEGIN )-PIVMIN )
  554. $ NWU = NWU + 1
  555. IF( IRANGE.EQ.ALLRNG .OR.
  556. $ ( WL.LT.D( IBEGIN )-PIVMIN
  557. $ .AND. WU.GE. D( IBEGIN )-PIVMIN ) ) THEN
  558. M = M + 1
  559. W( M ) = D( IBEGIN )
  560. WERR(M) = ZERO
  561. * The gap for a single block doesn't matter for the later
  562. * algorithm and is assigned an arbitrary large value
  563. IBLOCK( M ) = JBLK
  564. INDEXW( M ) = 1
  565. END IF
  566. * Disabled 2x2 case because of a failure on the following matrix
  567. * RANGE = 'I', IL = IU = 4
  568. * Original Tridiagonal, d = [
  569. * -0.150102010615740E+00
  570. * -0.849897989384260E+00
  571. * -0.128208148052635E-15
  572. * 0.128257718286320E-15
  573. * ];
  574. * e = [
  575. * -0.357171383266986E+00
  576. * -0.180411241501588E-15
  577. * -0.175152352710251E-15
  578. * ];
  579. *
  580. * ELSE IF( IN.EQ.2 ) THEN
  581. ** 2x2 block
  582. * DISC = SQRT( (HALF*(D(IBEGIN)-D(IEND)))**2 + E(IBEGIN)**2 )
  583. * TMP1 = HALF*(D(IBEGIN)+D(IEND))
  584. * L1 = TMP1 - DISC
  585. * IF( WL.GE. L1-PIVMIN )
  586. * $ NWL = NWL + 1
  587. * IF( WU.GE. L1-PIVMIN )
  588. * $ NWU = NWU + 1
  589. * IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L1-PIVMIN .AND. WU.GE.
  590. * $ L1-PIVMIN ) ) THEN
  591. * M = M + 1
  592. * W( M ) = L1
  593. ** The uncertainty of eigenvalues of a 2x2 matrix is very small
  594. * WERR( M ) = EPS * ABS( W( M ) ) * TWO
  595. * IBLOCK( M ) = JBLK
  596. * INDEXW( M ) = 1
  597. * ENDIF
  598. * L2 = TMP1 + DISC
  599. * IF( WL.GE. L2-PIVMIN )
  600. * $ NWL = NWL + 1
  601. * IF( WU.GE. L2-PIVMIN )
  602. * $ NWU = NWU + 1
  603. * IF( IRANGE.EQ.ALLRNG .OR. ( WL.LT.L2-PIVMIN .AND. WU.GE.
  604. * $ L2-PIVMIN ) ) THEN
  605. * M = M + 1
  606. * W( M ) = L2
  607. ** The uncertainty of eigenvalues of a 2x2 matrix is very small
  608. * WERR( M ) = EPS * ABS( W( M ) ) * TWO
  609. * IBLOCK( M ) = JBLK
  610. * INDEXW( M ) = 2
  611. * ENDIF
  612. ELSE
  613. * General Case - block of size IN >= 2
  614. * Compute local Gerschgorin interval and use it as the initial
  615. * interval for SLAEBZ
  616. GU = D( IBEGIN )
  617. GL = D( IBEGIN )
  618. TMP1 = ZERO
  619. DO 40 J = IBEGIN, IEND
  620. GL = MIN( GL, GERS( 2*J - 1))
  621. GU = MAX( GU, GERS(2*J) )
  622. 40 CONTINUE
  623. * [JAN/28/2009]
  624. * change SPDIAM by TNORM in lines 2 and 3 thereafter
  625. * line 1: remove computation of SPDIAM (not useful anymore)
  626. * SPDIAM = GU - GL
  627. * GL = GL - FUDGE*SPDIAM*EPS*IN - FUDGE*PIVMIN
  628. * GU = GU + FUDGE*SPDIAM*EPS*IN + FUDGE*PIVMIN
  629. GL = GL - FUDGE*TNORM*EPS*IN - FUDGE*PIVMIN
  630. GU = GU + FUDGE*TNORM*EPS*IN + FUDGE*PIVMIN
  631. *
  632. IF( IRANGE.GT.1 ) THEN
  633. IF( GU.LT.WL ) THEN
  634. * the local block contains none of the wanted eigenvalues
  635. NWL = NWL + IN
  636. NWU = NWU + IN
  637. GO TO 70
  638. END IF
  639. * refine search interval if possible, only range (WL,WU] matters
  640. GL = MAX( GL, WL )
  641. GU = MIN( GU, WU )
  642. IF( GL.GE.GU )
  643. $ GO TO 70
  644. END IF
  645. * Find negcount of initial interval boundaries GL and GU
  646. WORK( N+1 ) = GL
  647. WORK( N+IN+1 ) = GU
  648. CALL SLAEBZ( 1, 0, IN, IN, 1, NB, ATOLI, RTOLI, PIVMIN,
  649. $ D( IBEGIN ), E( IBEGIN ), E2( IBEGIN ),
  650. $ IDUMMA, WORK( N+1 ), WORK( N+2*IN+1 ), IM,
  651. $ IWORK, W( M+1 ), IBLOCK( M+1 ), IINFO )
  652. IF( IINFO .NE. 0 ) THEN
  653. INFO = IINFO
  654. RETURN
  655. END IF
  656. *
  657. NWL = NWL + IWORK( 1 )
  658. NWU = NWU + IWORK( IN+1 )
  659. IWOFF = M - IWORK( 1 )
  660. * Compute Eigenvalues
  661. ITMAX = INT( ( LOG( GU-GL+PIVMIN )-LOG( PIVMIN ) ) /
  662. $ LOG( TWO ) ) + 2
  663. CALL SLAEBZ( 2, ITMAX, IN, IN, 1, NB, ATOLI, RTOLI, PIVMIN,
  664. $ D( IBEGIN ), E( IBEGIN ), E2( IBEGIN ),
  665. $ IDUMMA, WORK( N+1 ), WORK( N+2*IN+1 ), IOUT,
  666. $ IWORK, W( M+1 ), IBLOCK( M+1 ), IINFO )
  667. IF( IINFO .NE. 0 ) THEN
  668. INFO = IINFO
  669. RETURN
  670. END IF
  671. *
  672. * Copy eigenvalues into W and IBLOCK
  673. * Use -JBLK for block number for unconverged eigenvalues.
  674. * Loop over the number of output intervals from SLAEBZ
  675. DO 60 J = 1, IOUT
  676. * eigenvalue approximation is middle point of interval
  677. TMP1 = HALF*( WORK( J+N )+WORK( J+IN+N ) )
  678. * semi length of error interval
  679. TMP2 = HALF*ABS( WORK( J+N )-WORK( J+IN+N ) )
  680. IF( J.GT.IOUT-IINFO ) THEN
  681. * Flag non-convergence.
  682. NCNVRG = .TRUE.
  683. IB = -JBLK
  684. ELSE
  685. IB = JBLK
  686. END IF
  687. DO 50 JE = IWORK( J ) + 1 + IWOFF,
  688. $ IWORK( J+IN ) + IWOFF
  689. W( JE ) = TMP1
  690. WERR( JE ) = TMP2
  691. INDEXW( JE ) = JE - IWOFF
  692. IBLOCK( JE ) = IB
  693. 50 CONTINUE
  694. 60 CONTINUE
  695. *
  696. M = M + IM
  697. END IF
  698. 70 CONTINUE
  699. * If RANGE='I', then (WL,WU) contains eigenvalues NWL+1,...,NWU
  700. * If NWL+1 < IL or NWU > IU, discard extra eigenvalues.
  701. IF( IRANGE.EQ.INDRNG ) THEN
  702. IDISCL = IL - 1 - NWL
  703. IDISCU = NWU - IU
  704. *
  705. IF( IDISCL.GT.0 ) THEN
  706. IM = 0
  707. DO 80 JE = 1, M
  708. * Remove some of the smallest eigenvalues from the left so that
  709. * at the end IDISCL =0. Move all eigenvalues up to the left.
  710. IF( W( JE ).LE.WLU .AND. IDISCL.GT.0 ) THEN
  711. IDISCL = IDISCL - 1
  712. ELSE
  713. IM = IM + 1
  714. W( IM ) = W( JE )
  715. WERR( IM ) = WERR( JE )
  716. INDEXW( IM ) = INDEXW( JE )
  717. IBLOCK( IM ) = IBLOCK( JE )
  718. END IF
  719. 80 CONTINUE
  720. M = IM
  721. END IF
  722. IF( IDISCU.GT.0 ) THEN
  723. * Remove some of the largest eigenvalues from the right so that
  724. * at the end IDISCU =0. Move all eigenvalues up to the left.
  725. IM=M+1
  726. DO 81 JE = M, 1, -1
  727. IF( W( JE ).GE.WUL .AND. IDISCU.GT.0 ) THEN
  728. IDISCU = IDISCU - 1
  729. ELSE
  730. IM = IM - 1
  731. W( IM ) = W( JE )
  732. WERR( IM ) = WERR( JE )
  733. INDEXW( IM ) = INDEXW( JE )
  734. IBLOCK( IM ) = IBLOCK( JE )
  735. END IF
  736. 81 CONTINUE
  737. JEE = 0
  738. DO 82 JE = IM, M
  739. JEE = JEE + 1
  740. W( JEE ) = W( JE )
  741. WERR( JEE ) = WERR( JE )
  742. INDEXW( JEE ) = INDEXW( JE )
  743. IBLOCK( JEE ) = IBLOCK( JE )
  744. 82 CONTINUE
  745. M = M-IM+1
  746. END IF
  747. IF( IDISCL.GT.0 .OR. IDISCU.GT.0 ) THEN
  748. * Code to deal with effects of bad arithmetic. (If N(w) is
  749. * monotone non-decreasing, this should never happen.)
  750. * Some low eigenvalues to be discarded are not in (WL,WLU],
  751. * or high eigenvalues to be discarded are not in (WUL,WU]
  752. * so just kill off the smallest IDISCL/largest IDISCU
  753. * eigenvalues, by marking the corresponding IBLOCK = 0
  754. IF( IDISCL.GT.0 ) THEN
  755. WKILL = WU
  756. DO 100 JDISC = 1, IDISCL
  757. IW = 0
  758. DO 90 JE = 1, M
  759. IF( IBLOCK( JE ).NE.0 .AND.
  760. $ ( W( JE ).LT.WKILL .OR. IW.EQ.0 ) ) THEN
  761. IW = JE
  762. WKILL = W( JE )
  763. END IF
  764. 90 CONTINUE
  765. IBLOCK( IW ) = 0
  766. 100 CONTINUE
  767. END IF
  768. IF( IDISCU.GT.0 ) THEN
  769. WKILL = WL
  770. DO 120 JDISC = 1, IDISCU
  771. IW = 0
  772. DO 110 JE = 1, M
  773. IF( IBLOCK( JE ).NE.0 .AND.
  774. $ ( W( JE ).GE.WKILL .OR. IW.EQ.0 ) ) THEN
  775. IW = JE
  776. WKILL = W( JE )
  777. END IF
  778. 110 CONTINUE
  779. IBLOCK( IW ) = 0
  780. 120 CONTINUE
  781. END IF
  782. * Now erase all eigenvalues with IBLOCK set to zero
  783. IM = 0
  784. DO 130 JE = 1, M
  785. IF( IBLOCK( JE ).NE.0 ) THEN
  786. IM = IM + 1
  787. W( IM ) = W( JE )
  788. WERR( IM ) = WERR( JE )
  789. INDEXW( IM ) = INDEXW( JE )
  790. IBLOCK( IM ) = IBLOCK( JE )
  791. END IF
  792. 130 CONTINUE
  793. M = IM
  794. END IF
  795. IF( IDISCL.LT.0 .OR. IDISCU.LT.0 ) THEN
  796. TOOFEW = .TRUE.
  797. END IF
  798. END IF
  799. *
  800. IF(( IRANGE.EQ.ALLRNG .AND. M.NE.N ).OR.
  801. $ ( IRANGE.EQ.INDRNG .AND. M.NE.IU-IL+1 ) ) THEN
  802. TOOFEW = .TRUE.
  803. END IF
  804. * If ORDER='B', do nothing the eigenvalues are already sorted by
  805. * block.
  806. * If ORDER='E', sort the eigenvalues from smallest to largest
  807. IF( LSAME(ORDER,'E') .AND. NSPLIT.GT.1 ) THEN
  808. DO 150 JE = 1, M - 1
  809. IE = 0
  810. TMP1 = W( JE )
  811. DO 140 J = JE + 1, M
  812. IF( W( J ).LT.TMP1 ) THEN
  813. IE = J
  814. TMP1 = W( J )
  815. END IF
  816. 140 CONTINUE
  817. IF( IE.NE.0 ) THEN
  818. TMP2 = WERR( IE )
  819. ITMP1 = IBLOCK( IE )
  820. ITMP2 = INDEXW( IE )
  821. W( IE ) = W( JE )
  822. WERR( IE ) = WERR( JE )
  823. IBLOCK( IE ) = IBLOCK( JE )
  824. INDEXW( IE ) = INDEXW( JE )
  825. W( JE ) = TMP1
  826. WERR( JE ) = TMP2
  827. IBLOCK( JE ) = ITMP1
  828. INDEXW( JE ) = ITMP2
  829. END IF
  830. 150 CONTINUE
  831. END IF
  832. *
  833. INFO = 0
  834. IF( NCNVRG )
  835. $ INFO = INFO + 1
  836. IF( TOOFEW )
  837. $ INFO = INFO + 2
  838. RETURN
  839. *
  840. * End of SLARRD
  841. *
  842. END