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.

slarre.f 32 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908
  1. *> \brief \b SLARRE given the tridiagonal matrix T, sets small off-diagonal elements to zero and for each unreduced block Ti, finds base representations and eigenvalues.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download SLARRE + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/slarre.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/slarre.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/slarre.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE SLARRE( RANGE, N, VL, VU, IL, IU, D, E, E2,
  22. * RTOL1, RTOL2, SPLTOL, NSPLIT, ISPLIT, M,
  23. * W, WERR, WGAP, IBLOCK, INDEXW, GERS, PIVMIN,
  24. * WORK, IWORK, INFO )
  25. *
  26. * .. Scalar Arguments ..
  27. * CHARACTER RANGE
  28. * INTEGER IL, INFO, IU, M, N, NSPLIT
  29. * REAL PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ),
  33. * $ INDEXW( * )
  34. * REAL D( * ), E( * ), E2( * ), GERS( * ),
  35. * $ W( * ),WERR( * ), WGAP( * ), WORK( * )
  36. * ..
  37. *
  38. *
  39. *> \par Purpose:
  40. * =============
  41. *>
  42. *> \verbatim
  43. *>
  44. *> To find the desired eigenvalues of a given real symmetric
  45. *> tridiagonal matrix T, SLARRE sets any "small" off-diagonal
  46. *> elements to zero, and for each unreduced block T_i, it finds
  47. *> (a) a suitable shift at one end of the block's spectrum,
  48. *> (b) the base representation, T_i - sigma_i I = L_i D_i L_i^T, and
  49. *> (c) eigenvalues of each L_i D_i L_i^T.
  50. *> The representations and eigenvalues found are then used by
  51. *> SSTEMR to compute the eigenvectors of T.
  52. *> The accuracy varies depending on whether bisection is used to
  53. *> find a few eigenvalues or the dqds algorithm (subroutine SLASQ2) to
  54. *> conpute all and then discard any unwanted one.
  55. *> As an added benefit, SLARRE also outputs the n
  56. *> Gerschgorin intervals for the matrices L_i D_i L_i^T.
  57. *> \endverbatim
  58. *
  59. * Arguments:
  60. * ==========
  61. *
  62. *> \param[in] RANGE
  63. *> \verbatim
  64. *> RANGE is CHARACTER*1
  65. *> = 'A': ("All") all eigenvalues will be found.
  66. *> = 'V': ("Value") all eigenvalues in the half-open interval
  67. *> (VL, VU] will be found.
  68. *> = 'I': ("Index") the IL-th through IU-th eigenvalues (of the
  69. *> entire matrix) will be found.
  70. *> \endverbatim
  71. *>
  72. *> \param[in] N
  73. *> \verbatim
  74. *> N is INTEGER
  75. *> The order of the matrix. N > 0.
  76. *> \endverbatim
  77. *>
  78. *> \param[in,out] VL
  79. *> \verbatim
  80. *> VL is REAL
  81. *> If RANGE='V', the lower bound for the eigenvalues.
  82. *> Eigenvalues less than or equal to VL, or greater than VU,
  83. *> will not be returned. VL < VU.
  84. *> If RANGE='I' or ='A', SLARRE computes bounds on the desired
  85. *> part of the spectrum.
  86. *> \endverbatim
  87. *>
  88. *> \param[in,out] VU
  89. *> \verbatim
  90. *> VU is REAL
  91. *> If RANGE='V', the upper bound for the eigenvalues.
  92. *> Eigenvalues less than or equal to VL, or greater than VU,
  93. *> will not be returned. VL < VU.
  94. *> If RANGE='I' or ='A', SLARRE computes bounds on the desired
  95. *> part of the spectrum.
  96. *> \endverbatim
  97. *>
  98. *> \param[in] IL
  99. *> \verbatim
  100. *> IL is INTEGER
  101. *> If RANGE='I', the index of the
  102. *> smallest eigenvalue to be returned.
  103. *> 1 <= IL <= IU <= N.
  104. *> \endverbatim
  105. *>
  106. *> \param[in] IU
  107. *> \verbatim
  108. *> IU is INTEGER
  109. *> If RANGE='I', the index of the
  110. *> largest eigenvalue to be returned.
  111. *> 1 <= IL <= IU <= N.
  112. *> \endverbatim
  113. *>
  114. *> \param[in,out] D
  115. *> \verbatim
  116. *> D is REAL array, dimension (N)
  117. *> On entry, the N diagonal elements of the tridiagonal
  118. *> matrix T.
  119. *> On exit, the N diagonal elements of the diagonal
  120. *> matrices D_i.
  121. *> \endverbatim
  122. *>
  123. *> \param[in,out] E
  124. *> \verbatim
  125. *> E is REAL array, dimension (N)
  126. *> On entry, the first (N-1) entries contain the subdiagonal
  127. *> elements of the tridiagonal matrix T; E(N) need not be set.
  128. *> On exit, E contains the subdiagonal elements of the unit
  129. *> bidiagonal matrices L_i. The entries E( ISPLIT( I ) ),
  130. *> 1 <= I <= NSPLIT, contain the base points sigma_i on output.
  131. *> \endverbatim
  132. *>
  133. *> \param[in,out] E2
  134. *> \verbatim
  135. *> E2 is REAL array, dimension (N)
  136. *> On entry, the first (N-1) entries contain the SQUARES of the
  137. *> subdiagonal elements of the tridiagonal matrix T;
  138. *> E2(N) need not be set.
  139. *> On exit, the entries E2( ISPLIT( I ) ),
  140. *> 1 <= I <= NSPLIT, have been set to zero
  141. *> \endverbatim
  142. *>
  143. *> \param[in] RTOL1
  144. *> \verbatim
  145. *> RTOL1 is REAL
  146. *> \endverbatim
  147. *>
  148. *> \param[in] RTOL2
  149. *> \verbatim
  150. *> RTOL2 is REAL
  151. *> Parameters for bisection.
  152. *> An interval [LEFT,RIGHT] has converged if
  153. *> RIGHT-LEFT < MAX( RTOL1*GAP, RTOL2*MAX(|LEFT|,|RIGHT|) )
  154. *> \endverbatim
  155. *>
  156. *> \param[in] SPLTOL
  157. *> \verbatim
  158. *> SPLTOL is REAL
  159. *> The threshold for splitting.
  160. *> \endverbatim
  161. *>
  162. *> \param[out] NSPLIT
  163. *> \verbatim
  164. *> NSPLIT is INTEGER
  165. *> The number of blocks T splits into. 1 <= NSPLIT <= N.
  166. *> \endverbatim
  167. *>
  168. *> \param[out] ISPLIT
  169. *> \verbatim
  170. *> ISPLIT is INTEGER array, dimension (N)
  171. *> The splitting points, at which T breaks up into blocks.
  172. *> The first block consists of rows/columns 1 to ISPLIT(1),
  173. *> the second of rows/columns ISPLIT(1)+1 through ISPLIT(2),
  174. *> etc., and the NSPLIT-th consists of rows/columns
  175. *> ISPLIT(NSPLIT-1)+1 through ISPLIT(NSPLIT)=N.
  176. *> \endverbatim
  177. *>
  178. *> \param[out] M
  179. *> \verbatim
  180. *> M is INTEGER
  181. *> The total number of eigenvalues (of all L_i D_i L_i^T)
  182. *> found.
  183. *> \endverbatim
  184. *>
  185. *> \param[out] W
  186. *> \verbatim
  187. *> W is REAL array, dimension (N)
  188. *> The first M elements contain the eigenvalues. The
  189. *> eigenvalues of each of the blocks, L_i D_i L_i^T, are
  190. *> sorted in ascending order ( SLARRE may use the
  191. *> remaining N-M elements as workspace).
  192. *> \endverbatim
  193. *>
  194. *> \param[out] WERR
  195. *> \verbatim
  196. *> WERR is REAL array, dimension (N)
  197. *> The error bound on the corresponding eigenvalue in W.
  198. *> \endverbatim
  199. *>
  200. *> \param[out] WGAP
  201. *> \verbatim
  202. *> WGAP is REAL array, dimension (N)
  203. *> The separation from the right neighbor eigenvalue in W.
  204. *> The gap is only with respect to the eigenvalues of the same block
  205. *> as each block has its own representation tree.
  206. *> Exception: at the right end of a block we store the left gap
  207. *> \endverbatim
  208. *>
  209. *> \param[out] IBLOCK
  210. *> \verbatim
  211. *> IBLOCK is INTEGER array, dimension (N)
  212. *> The indices of the blocks (submatrices) associated with the
  213. *> corresponding eigenvalues in W; IBLOCK(i)=1 if eigenvalue
  214. *> W(i) belongs to the first block from the top, =2 if W(i)
  215. *> belongs to the second block, etc.
  216. *> \endverbatim
  217. *>
  218. *> \param[out] INDEXW
  219. *> \verbatim
  220. *> INDEXW is INTEGER array, dimension (N)
  221. *> The indices of the eigenvalues within each block (submatrix);
  222. *> for example, INDEXW(i)= 10 and IBLOCK(i)=2 imply that the
  223. *> i-th eigenvalue W(i) is the 10-th eigenvalue in block 2
  224. *> \endverbatim
  225. *>
  226. *> \param[out] GERS
  227. *> \verbatim
  228. *> GERS is REAL array, dimension (2*N)
  229. *> The N Gerschgorin intervals (the i-th Gerschgorin interval
  230. *> is (GERS(2*i-1), GERS(2*i)).
  231. *> \endverbatim
  232. *>
  233. *> \param[out] PIVMIN
  234. *> \verbatim
  235. *> PIVMIN is REAL
  236. *> The minimum pivot in the Sturm sequence for T.
  237. *> \endverbatim
  238. *>
  239. *> \param[out] WORK
  240. *> \verbatim
  241. *> WORK is REAL array, dimension (6*N)
  242. *> Workspace.
  243. *> \endverbatim
  244. *>
  245. *> \param[out] IWORK
  246. *> \verbatim
  247. *> IWORK is INTEGER array, dimension (5*N)
  248. *> Workspace.
  249. *> \endverbatim
  250. *>
  251. *> \param[out] INFO
  252. *> \verbatim
  253. *> INFO is INTEGER
  254. *> = 0: successful exit
  255. *> > 0: A problem occurred in SLARRE.
  256. *> < 0: One of the called subroutines signaled an internal problem.
  257. *> Needs inspection of the corresponding parameter IINFO
  258. *> for further information.
  259. *>
  260. *> =-1: Problem in SLARRD.
  261. *> = 2: No base representation could be found in MAXTRY iterations.
  262. *> Increasing MAXTRY and recompilation might be a remedy.
  263. *> =-3: Problem in SLARRB when computing the refined root
  264. *> representation for SLASQ2.
  265. *> =-4: Problem in SLARRB when preforming bisection on the
  266. *> desired part of the spectrum.
  267. *> =-5: Problem in SLASQ2.
  268. *> =-6: Problem in SLASQ2.
  269. *> \endverbatim
  270. *
  271. * Authors:
  272. * ========
  273. *
  274. *> \author Univ. of Tennessee
  275. *> \author Univ. of California Berkeley
  276. *> \author Univ. of Colorado Denver
  277. *> \author NAG Ltd.
  278. *
  279. *> \date June 2016
  280. *
  281. *> \ingroup OTHERauxiliary
  282. *
  283. *> \par Further Details:
  284. * =====================
  285. *>
  286. *> \verbatim
  287. *>
  288. *> The base representations are required to suffer very little
  289. *> element growth and consequently define all their eigenvalues to
  290. *> high relative accuracy.
  291. *> \endverbatim
  292. *
  293. *> \par Contributors:
  294. * ==================
  295. *>
  296. *> Beresford Parlett, University of California, Berkeley, USA \n
  297. *> Jim Demmel, University of California, Berkeley, USA \n
  298. *> Inderjit Dhillon, University of Texas, Austin, USA \n
  299. *> Osni Marques, LBNL/NERSC, USA \n
  300. *> Christof Voemel, University of California, Berkeley, USA \n
  301. *>
  302. * =====================================================================
  303. SUBROUTINE SLARRE( RANGE, N, VL, VU, IL, IU, D, E, E2,
  304. $ RTOL1, RTOL2, SPLTOL, NSPLIT, ISPLIT, M,
  305. $ W, WERR, WGAP, IBLOCK, INDEXW, GERS, PIVMIN,
  306. $ WORK, IWORK, INFO )
  307. *
  308. * -- LAPACK auxiliary routine (version 3.8.0) --
  309. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  310. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  311. * June 2016
  312. *
  313. * .. Scalar Arguments ..
  314. CHARACTER RANGE
  315. INTEGER IL, INFO, IU, M, N, NSPLIT
  316. REAL PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU
  317. * ..
  318. * .. Array Arguments ..
  319. INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ),
  320. $ INDEXW( * )
  321. REAL D( * ), E( * ), E2( * ), GERS( * ),
  322. $ W( * ),WERR( * ), WGAP( * ), WORK( * )
  323. * ..
  324. *
  325. * =====================================================================
  326. *
  327. * .. Parameters ..
  328. REAL FAC, FOUR, FOURTH, FUDGE, HALF, HNDRD,
  329. $ MAXGROWTH, ONE, PERT, TWO, ZERO
  330. PARAMETER ( ZERO = 0.0E0, ONE = 1.0E0,
  331. $ TWO = 2.0E0, FOUR=4.0E0,
  332. $ HNDRD = 100.0E0,
  333. $ PERT = 4.0E0,
  334. $ HALF = ONE/TWO, FOURTH = ONE/FOUR, FAC= HALF,
  335. $ MAXGROWTH = 64.0E0, FUDGE = 2.0E0 )
  336. INTEGER MAXTRY, ALLRNG, INDRNG, VALRNG
  337. PARAMETER ( MAXTRY = 6, ALLRNG = 1, INDRNG = 2,
  338. $ VALRNG = 3 )
  339. * ..
  340. * .. Local Scalars ..
  341. LOGICAL FORCEB, NOREP, USEDQD
  342. INTEGER CNT, CNT1, CNT2, I, IBEGIN, IDUM, IEND, IINFO,
  343. $ IN, INDL, INDU, IRANGE, J, JBLK, MB, MM,
  344. $ WBEGIN, WEND
  345. REAL AVGAP, BSRTOL, CLWDTH, DMAX, DPIVOT, EABS,
  346. $ EMAX, EOLD, EPS, GL, GU, ISLEFT, ISRGHT, RTL,
  347. $ RTOL, S1, S2, SAFMIN, SGNDEF, SIGMA, SPDIAM,
  348. $ TAU, TMP, TMP1
  349. * ..
  350. * .. Local Arrays ..
  351. INTEGER ISEED( 4 )
  352. * ..
  353. * .. External Functions ..
  354. LOGICAL LSAME
  355. REAL SLAMCH
  356. EXTERNAL SLAMCH, LSAME
  357. * ..
  358. * .. External Subroutines ..
  359. EXTERNAL SCOPY, SLARNV, SLARRA, SLARRB, SLARRC, SLARRD,
  360. $ SLASQ2, SLARRK
  361. * ..
  362. * .. Intrinsic Functions ..
  363. INTRINSIC ABS, MAX, MIN
  364. * ..
  365. * .. Executable Statements ..
  366. *
  367. INFO = 0
  368. *
  369. * Quick return if possible
  370. *
  371. IF( N.LE.0 ) THEN
  372. RETURN
  373. END IF
  374. *
  375. * Decode RANGE
  376. *
  377. IF( LSAME( RANGE, 'A' ) ) THEN
  378. IRANGE = ALLRNG
  379. ELSE IF( LSAME( RANGE, 'V' ) ) THEN
  380. IRANGE = VALRNG
  381. ELSE IF( LSAME( RANGE, 'I' ) ) THEN
  382. IRANGE = INDRNG
  383. END IF
  384. M = 0
  385. * Get machine constants
  386. SAFMIN = SLAMCH( 'S' )
  387. EPS = SLAMCH( 'P' )
  388. * Set parameters
  389. RTL = HNDRD*EPS
  390. * If one were ever to ask for less initial precision in BSRTOL,
  391. * one should keep in mind that for the subset case, the extremal
  392. * eigenvalues must be at least as accurate as the current setting
  393. * (eigenvalues in the middle need not as much accuracy)
  394. BSRTOL = SQRT(EPS)*(0.5E-3)
  395. * Treat case of 1x1 matrix for quick return
  396. IF( N.EQ.1 ) THEN
  397. IF( (IRANGE.EQ.ALLRNG).OR.
  398. $ ((IRANGE.EQ.VALRNG).AND.(D(1).GT.VL).AND.(D(1).LE.VU)).OR.
  399. $ ((IRANGE.EQ.INDRNG).AND.(IL.EQ.1).AND.(IU.EQ.1)) ) THEN
  400. M = 1
  401. W(1) = D(1)
  402. * The computation error of the eigenvalue is zero
  403. WERR(1) = ZERO
  404. WGAP(1) = ZERO
  405. IBLOCK( 1 ) = 1
  406. INDEXW( 1 ) = 1
  407. GERS(1) = D( 1 )
  408. GERS(2) = D( 1 )
  409. ENDIF
  410. * store the shift for the initial RRR, which is zero in this case
  411. E(1) = ZERO
  412. RETURN
  413. END IF
  414. * General case: tridiagonal matrix of order > 1
  415. *
  416. * Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter.
  417. * Compute maximum off-diagonal entry and pivmin.
  418. GL = D(1)
  419. GU = D(1)
  420. EOLD = ZERO
  421. EMAX = ZERO
  422. E(N) = ZERO
  423. DO 5 I = 1,N
  424. WERR(I) = ZERO
  425. WGAP(I) = ZERO
  426. EABS = ABS( E(I) )
  427. IF( EABS .GE. EMAX ) THEN
  428. EMAX = EABS
  429. END IF
  430. TMP1 = EABS + EOLD
  431. GERS( 2*I-1) = D(I) - TMP1
  432. GL = MIN( GL, GERS( 2*I - 1))
  433. GERS( 2*I ) = D(I) + TMP1
  434. GU = MAX( GU, GERS(2*I) )
  435. EOLD = EABS
  436. 5 CONTINUE
  437. * The minimum pivot allowed in the Sturm sequence for T
  438. PIVMIN = SAFMIN * MAX( ONE, EMAX**2 )
  439. * Compute spectral diameter. The Gerschgorin bounds give an
  440. * estimate that is wrong by at most a factor of SQRT(2)
  441. SPDIAM = GU - GL
  442. * Compute splitting points
  443. CALL SLARRA( N, D, E, E2, SPLTOL, SPDIAM,
  444. $ NSPLIT, ISPLIT, IINFO )
  445. * Can force use of bisection instead of faster DQDS.
  446. * Option left in the code for future multisection work.
  447. FORCEB = .FALSE.
  448. * Initialize USEDQD, DQDS should be used for ALLRNG unless someone
  449. * explicitly wants bisection.
  450. USEDQD = (( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB))
  451. IF( (IRANGE.EQ.ALLRNG) .AND. (.NOT. FORCEB) ) THEN
  452. * Set interval [VL,VU] that contains all eigenvalues
  453. VL = GL
  454. VU = GU
  455. ELSE
  456. * We call SLARRD to find crude approximations to the eigenvalues
  457. * in the desired range. In case IRANGE = INDRNG, we also obtain the
  458. * interval (VL,VU] that contains all the wanted eigenvalues.
  459. * An interval [LEFT,RIGHT] has converged if
  460. * RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT))
  461. * SLARRD needs a WORK of size 4*N, IWORK of size 3*N
  462. CALL SLARRD( RANGE, 'B', N, VL, VU, IL, IU, GERS,
  463. $ BSRTOL, D, E, E2, PIVMIN, NSPLIT, ISPLIT,
  464. $ MM, W, WERR, VL, VU, IBLOCK, INDEXW,
  465. $ WORK, IWORK, IINFO )
  466. IF( IINFO.NE.0 ) THEN
  467. INFO = -1
  468. RETURN
  469. ENDIF
  470. * Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0
  471. DO 14 I = MM+1,N
  472. W( I ) = ZERO
  473. WERR( I ) = ZERO
  474. IBLOCK( I ) = 0
  475. INDEXW( I ) = 0
  476. 14 CONTINUE
  477. END IF
  478. ***
  479. * Loop over unreduced blocks
  480. IBEGIN = 1
  481. WBEGIN = 1
  482. DO 170 JBLK = 1, NSPLIT
  483. IEND = ISPLIT( JBLK )
  484. IN = IEND - IBEGIN + 1
  485. * 1 X 1 block
  486. IF( IN.EQ.1 ) THEN
  487. IF( (IRANGE.EQ.ALLRNG).OR.( (IRANGE.EQ.VALRNG).AND.
  488. $ ( D( IBEGIN ).GT.VL ).AND.( D( IBEGIN ).LE.VU ) )
  489. $ .OR. ( (IRANGE.EQ.INDRNG).AND.(IBLOCK(WBEGIN).EQ.JBLK))
  490. $ ) THEN
  491. M = M + 1
  492. W( M ) = D( IBEGIN )
  493. WERR(M) = ZERO
  494. * The gap for a single block doesn't matter for the later
  495. * algorithm and is assigned an arbitrary large value
  496. WGAP(M) = ZERO
  497. IBLOCK( M ) = JBLK
  498. INDEXW( M ) = 1
  499. WBEGIN = WBEGIN + 1
  500. ENDIF
  501. * E( IEND ) holds the shift for the initial RRR
  502. E( IEND ) = ZERO
  503. IBEGIN = IEND + 1
  504. GO TO 170
  505. END IF
  506. *
  507. * Blocks of size larger than 1x1
  508. *
  509. * E( IEND ) will hold the shift for the initial RRR, for now set it =0
  510. E( IEND ) = ZERO
  511. *
  512. * Find local outer bounds GL,GU for the block
  513. GL = D(IBEGIN)
  514. GU = D(IBEGIN)
  515. DO 15 I = IBEGIN , IEND
  516. GL = MIN( GERS( 2*I-1 ), GL )
  517. GU = MAX( GERS( 2*I ), GU )
  518. 15 CONTINUE
  519. SPDIAM = GU - GL
  520. IF(.NOT. ((IRANGE.EQ.ALLRNG).AND.(.NOT.FORCEB)) ) THEN
  521. * Count the number of eigenvalues in the current block.
  522. MB = 0
  523. DO 20 I = WBEGIN,MM
  524. IF( IBLOCK(I).EQ.JBLK ) THEN
  525. MB = MB+1
  526. ELSE
  527. GOTO 21
  528. ENDIF
  529. 20 CONTINUE
  530. 21 CONTINUE
  531. IF( MB.EQ.0) THEN
  532. * No eigenvalue in the current block lies in the desired range
  533. * E( IEND ) holds the shift for the initial RRR
  534. E( IEND ) = ZERO
  535. IBEGIN = IEND + 1
  536. GO TO 170
  537. ELSE
  538. * Decide whether dqds or bisection is more efficient
  539. USEDQD = ( (MB .GT. FAC*IN) .AND. (.NOT.FORCEB) )
  540. WEND = WBEGIN + MB - 1
  541. * Calculate gaps for the current block
  542. * In later stages, when representations for individual
  543. * eigenvalues are different, we use SIGMA = E( IEND ).
  544. SIGMA = ZERO
  545. DO 30 I = WBEGIN, WEND - 1
  546. WGAP( I ) = MAX( ZERO,
  547. $ W(I+1)-WERR(I+1) - (W(I)+WERR(I)) )
  548. 30 CONTINUE
  549. WGAP( WEND ) = MAX( ZERO,
  550. $ VU - SIGMA - (W( WEND )+WERR( WEND )))
  551. * Find local index of the first and last desired evalue.
  552. INDL = INDEXW(WBEGIN)
  553. INDU = INDEXW( WEND )
  554. ENDIF
  555. ENDIF
  556. IF(( (IRANGE.EQ.ALLRNG) .AND. (.NOT. FORCEB) ).OR.USEDQD) THEN
  557. * Case of DQDS
  558. * Find approximations to the extremal eigenvalues of the block
  559. CALL SLARRK( IN, 1, GL, GU, D(IBEGIN),
  560. $ E2(IBEGIN), PIVMIN, RTL, TMP, TMP1, IINFO )
  561. IF( IINFO.NE.0 ) THEN
  562. INFO = -1
  563. RETURN
  564. ENDIF
  565. ISLEFT = MAX(GL, TMP - TMP1
  566. $ - HNDRD * EPS* ABS(TMP - TMP1))
  567. CALL SLARRK( IN, IN, GL, GU, D(IBEGIN),
  568. $ E2(IBEGIN), PIVMIN, RTL, TMP, TMP1, IINFO )
  569. IF( IINFO.NE.0 ) THEN
  570. INFO = -1
  571. RETURN
  572. ENDIF
  573. ISRGHT = MIN(GU, TMP + TMP1
  574. $ + HNDRD * EPS * ABS(TMP + TMP1))
  575. * Improve the estimate of the spectral diameter
  576. SPDIAM = ISRGHT - ISLEFT
  577. ELSE
  578. * Case of bisection
  579. * Find approximations to the wanted extremal eigenvalues
  580. ISLEFT = MAX(GL, W(WBEGIN) - WERR(WBEGIN)
  581. $ - HNDRD * EPS*ABS(W(WBEGIN)- WERR(WBEGIN) ))
  582. ISRGHT = MIN(GU,W(WEND) + WERR(WEND)
  583. $ + HNDRD * EPS * ABS(W(WEND)+ WERR(WEND)))
  584. ENDIF
  585. * Decide whether the base representation for the current block
  586. * L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I
  587. * should be on the left or the right end of the current block.
  588. * The strategy is to shift to the end which is "more populated"
  589. * Furthermore, decide whether to use DQDS for the computation of
  590. * the eigenvalue approximations at the end of SLARRE or bisection.
  591. * dqds is chosen if all eigenvalues are desired or the number of
  592. * eigenvalues to be computed is large compared to the blocksize.
  593. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  594. * If all the eigenvalues have to be computed, we use dqd
  595. USEDQD = .TRUE.
  596. * INDL is the local index of the first eigenvalue to compute
  597. INDL = 1
  598. INDU = IN
  599. * MB = number of eigenvalues to compute
  600. MB = IN
  601. WEND = WBEGIN + MB - 1
  602. * Define 1/4 and 3/4 points of the spectrum
  603. S1 = ISLEFT + FOURTH * SPDIAM
  604. S2 = ISRGHT - FOURTH * SPDIAM
  605. ELSE
  606. * SLARRD has computed IBLOCK and INDEXW for each eigenvalue
  607. * approximation.
  608. * choose sigma
  609. IF( USEDQD ) THEN
  610. S1 = ISLEFT + FOURTH * SPDIAM
  611. S2 = ISRGHT - FOURTH * SPDIAM
  612. ELSE
  613. TMP = MIN(ISRGHT,VU) - MAX(ISLEFT,VL)
  614. S1 = MAX(ISLEFT,VL) + FOURTH * TMP
  615. S2 = MIN(ISRGHT,VU) - FOURTH * TMP
  616. ENDIF
  617. ENDIF
  618. * Compute the negcount at the 1/4 and 3/4 points
  619. IF(MB.GT.1) THEN
  620. CALL SLARRC( 'T', IN, S1, S2, D(IBEGIN),
  621. $ E(IBEGIN), PIVMIN, CNT, CNT1, CNT2, IINFO)
  622. ENDIF
  623. IF(MB.EQ.1) THEN
  624. SIGMA = GL
  625. SGNDEF = ONE
  626. ELSEIF( CNT1 - INDL .GE. INDU - CNT2 ) THEN
  627. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  628. SIGMA = MAX(ISLEFT,GL)
  629. ELSEIF( USEDQD ) THEN
  630. * use Gerschgorin bound as shift to get pos def matrix
  631. * for dqds
  632. SIGMA = ISLEFT
  633. ELSE
  634. * use approximation of the first desired eigenvalue of the
  635. * block as shift
  636. SIGMA = MAX(ISLEFT,VL)
  637. ENDIF
  638. SGNDEF = ONE
  639. ELSE
  640. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  641. SIGMA = MIN(ISRGHT,GU)
  642. ELSEIF( USEDQD ) THEN
  643. * use Gerschgorin bound as shift to get neg def matrix
  644. * for dqds
  645. SIGMA = ISRGHT
  646. ELSE
  647. * use approximation of the first desired eigenvalue of the
  648. * block as shift
  649. SIGMA = MIN(ISRGHT,VU)
  650. ENDIF
  651. SGNDEF = -ONE
  652. ENDIF
  653. * An initial SIGMA has been chosen that will be used for computing
  654. * T - SIGMA I = L D L^T
  655. * Define the increment TAU of the shift in case the initial shift
  656. * needs to be refined to obtain a factorization with not too much
  657. * element growth.
  658. IF( USEDQD ) THEN
  659. * The initial SIGMA was to the outer end of the spectrum
  660. * the matrix is definite and we need not retreat.
  661. TAU = SPDIAM*EPS*N + TWO*PIVMIN
  662. TAU = MAX( TAU,TWO*EPS*ABS(SIGMA) )
  663. ELSE
  664. IF(MB.GT.1) THEN
  665. CLWDTH = W(WEND) + WERR(WEND) - W(WBEGIN) - WERR(WBEGIN)
  666. AVGAP = ABS(CLWDTH / REAL(WEND-WBEGIN))
  667. IF( SGNDEF.EQ.ONE ) THEN
  668. TAU = HALF*MAX(WGAP(WBEGIN),AVGAP)
  669. TAU = MAX(TAU,WERR(WBEGIN))
  670. ELSE
  671. TAU = HALF*MAX(WGAP(WEND-1),AVGAP)
  672. TAU = MAX(TAU,WERR(WEND))
  673. ENDIF
  674. ELSE
  675. TAU = WERR(WBEGIN)
  676. ENDIF
  677. ENDIF
  678. *
  679. DO 80 IDUM = 1, MAXTRY
  680. * Compute L D L^T factorization of tridiagonal matrix T - sigma I.
  681. * Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of
  682. * pivots in WORK(2*IN+1:3*IN)
  683. DPIVOT = D( IBEGIN ) - SIGMA
  684. WORK( 1 ) = DPIVOT
  685. DMAX = ABS( WORK(1) )
  686. J = IBEGIN
  687. DO 70 I = 1, IN - 1
  688. WORK( 2*IN+I ) = ONE / WORK( I )
  689. TMP = E( J )*WORK( 2*IN+I )
  690. WORK( IN+I ) = TMP
  691. DPIVOT = ( D( J+1 )-SIGMA ) - TMP*E( J )
  692. WORK( I+1 ) = DPIVOT
  693. DMAX = MAX( DMAX, ABS(DPIVOT) )
  694. J = J + 1
  695. 70 CONTINUE
  696. * check for element growth
  697. IF( DMAX .GT. MAXGROWTH*SPDIAM ) THEN
  698. NOREP = .TRUE.
  699. ELSE
  700. NOREP = .FALSE.
  701. ENDIF
  702. IF( USEDQD .AND. .NOT.NOREP ) THEN
  703. * Ensure the definiteness of the representation
  704. * All entries of D (of L D L^T) must have the same sign
  705. DO 71 I = 1, IN
  706. TMP = SGNDEF*WORK( I )
  707. IF( TMP.LT.ZERO ) NOREP = .TRUE.
  708. 71 CONTINUE
  709. ENDIF
  710. IF(NOREP) THEN
  711. * Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin
  712. * shift which makes the matrix definite. So we should end up
  713. * here really only in the case of IRANGE = VALRNG or INDRNG.
  714. IF( IDUM.EQ.MAXTRY-1 ) THEN
  715. IF( SGNDEF.EQ.ONE ) THEN
  716. * The fudged Gerschgorin shift should succeed
  717. SIGMA =
  718. $ GL - FUDGE*SPDIAM*EPS*N - FUDGE*TWO*PIVMIN
  719. ELSE
  720. SIGMA =
  721. $ GU + FUDGE*SPDIAM*EPS*N + FUDGE*TWO*PIVMIN
  722. END IF
  723. ELSE
  724. SIGMA = SIGMA - SGNDEF * TAU
  725. TAU = TWO * TAU
  726. END IF
  727. ELSE
  728. * an initial RRR is found
  729. GO TO 83
  730. END IF
  731. 80 CONTINUE
  732. * if the program reaches this point, no base representation could be
  733. * found in MAXTRY iterations.
  734. INFO = 2
  735. RETURN
  736. 83 CONTINUE
  737. * At this point, we have found an initial base representation
  738. * T - SIGMA I = L D L^T with not too much element growth.
  739. * Store the shift.
  740. E( IEND ) = SIGMA
  741. * Store D and L.
  742. CALL SCOPY( IN, WORK, 1, D( IBEGIN ), 1 )
  743. CALL SCOPY( IN-1, WORK( IN+1 ), 1, E( IBEGIN ), 1 )
  744. IF(MB.GT.1 ) THEN
  745. *
  746. * Perturb each entry of the base representation by a small
  747. * (but random) relative amount to overcome difficulties with
  748. * glued matrices.
  749. *
  750. DO 122 I = 1, 4
  751. ISEED( I ) = 1
  752. 122 CONTINUE
  753. CALL SLARNV(2, ISEED, 2*IN-1, WORK(1))
  754. DO 125 I = 1,IN-1
  755. D(IBEGIN+I-1) = D(IBEGIN+I-1)*(ONE+EPS*PERT*WORK(I))
  756. E(IBEGIN+I-1) = E(IBEGIN+I-1)*(ONE+EPS*PERT*WORK(IN+I))
  757. 125 CONTINUE
  758. D(IEND) = D(IEND)*(ONE+EPS*FOUR*WORK(IN))
  759. *
  760. ENDIF
  761. *
  762. * Don't update the Gerschgorin intervals because keeping track
  763. * of the updates would be too much work in SLARRV.
  764. * We update W instead and use it to locate the proper Gerschgorin
  765. * intervals.
  766. * Compute the required eigenvalues of L D L' by bisection or dqds
  767. IF ( .NOT.USEDQD ) THEN
  768. * If SLARRD has been used, shift the eigenvalue approximations
  769. * according to their representation. This is necessary for
  770. * a uniform SLARRV since dqds computes eigenvalues of the
  771. * shifted representation. In SLARRV, W will always hold the
  772. * UNshifted eigenvalue approximation.
  773. DO 134 J=WBEGIN,WEND
  774. W(J) = W(J) - SIGMA
  775. WERR(J) = WERR(J) + ABS(W(J)) * EPS
  776. 134 CONTINUE
  777. * call SLARRB to reduce eigenvalue error of the approximations
  778. * from SLARRD
  779. DO 135 I = IBEGIN, IEND-1
  780. WORK( I ) = D( I ) * E( I )**2
  781. 135 CONTINUE
  782. * use bisection to find EV from INDL to INDU
  783. CALL SLARRB(IN, D(IBEGIN), WORK(IBEGIN),
  784. $ INDL, INDU, RTOL1, RTOL2, INDL-1,
  785. $ W(WBEGIN), WGAP(WBEGIN), WERR(WBEGIN),
  786. $ WORK( 2*N+1 ), IWORK, PIVMIN, SPDIAM,
  787. $ IN, IINFO )
  788. IF( IINFO .NE. 0 ) THEN
  789. INFO = -4
  790. RETURN
  791. END IF
  792. * SLARRB computes all gaps correctly except for the last one
  793. * Record distance to VU/GU
  794. WGAP( WEND ) = MAX( ZERO,
  795. $ ( VU-SIGMA ) - ( W( WEND ) + WERR( WEND ) ) )
  796. DO 138 I = INDL, INDU
  797. M = M + 1
  798. IBLOCK(M) = JBLK
  799. INDEXW(M) = I
  800. 138 CONTINUE
  801. ELSE
  802. * Call dqds to get all eigs (and then possibly delete unwanted
  803. * eigenvalues).
  804. * Note that dqds finds the eigenvalues of the L D L^T representation
  805. * of T to high relative accuracy. High relative accuracy
  806. * might be lost when the shift of the RRR is subtracted to obtain
  807. * the eigenvalues of T. However, T is not guaranteed to define its
  808. * eigenvalues to high relative accuracy anyway.
  809. * Set RTOL to the order of the tolerance used in SLASQ2
  810. * This is an ESTIMATED error, the worst case bound is 4*N*EPS
  811. * which is usually too large and requires unnecessary work to be
  812. * done by bisection when computing the eigenvectors
  813. RTOL = LOG(REAL(IN)) * FOUR * EPS
  814. J = IBEGIN
  815. DO 140 I = 1, IN - 1
  816. WORK( 2*I-1 ) = ABS( D( J ) )
  817. WORK( 2*I ) = E( J )*E( J )*WORK( 2*I-1 )
  818. J = J + 1
  819. 140 CONTINUE
  820. WORK( 2*IN-1 ) = ABS( D( IEND ) )
  821. WORK( 2*IN ) = ZERO
  822. CALL SLASQ2( IN, WORK, IINFO )
  823. IF( IINFO .NE. 0 ) THEN
  824. * If IINFO = -5 then an index is part of a tight cluster
  825. * and should be changed. The index is in IWORK(1) and the
  826. * gap is in WORK(N+1)
  827. INFO = -5
  828. RETURN
  829. ELSE
  830. * Test that all eigenvalues are positive as expected
  831. DO 149 I = 1, IN
  832. IF( WORK( I ).LT.ZERO ) THEN
  833. INFO = -6
  834. RETURN
  835. ENDIF
  836. 149 CONTINUE
  837. END IF
  838. IF( SGNDEF.GT.ZERO ) THEN
  839. DO 150 I = INDL, INDU
  840. M = M + 1
  841. W( M ) = WORK( IN-I+1 )
  842. IBLOCK( M ) = JBLK
  843. INDEXW( M ) = I
  844. 150 CONTINUE
  845. ELSE
  846. DO 160 I = INDL, INDU
  847. M = M + 1
  848. W( M ) = -WORK( I )
  849. IBLOCK( M ) = JBLK
  850. INDEXW( M ) = I
  851. 160 CONTINUE
  852. END IF
  853. DO 165 I = M - MB + 1, M
  854. * the value of RTOL below should be the tolerance in SLASQ2
  855. WERR( I ) = RTOL * ABS( W(I) )
  856. 165 CONTINUE
  857. DO 166 I = M - MB + 1, M - 1
  858. * compute the right gap between the intervals
  859. WGAP( I ) = MAX( ZERO,
  860. $ W(I+1)-WERR(I+1) - (W(I)+WERR(I)) )
  861. 166 CONTINUE
  862. WGAP( M ) = MAX( ZERO,
  863. $ ( VU-SIGMA ) - ( W( M ) + WERR( M ) ) )
  864. END IF
  865. * proceed with next block
  866. IBEGIN = IEND + 1
  867. WBEGIN = WEND + 1
  868. 170 CONTINUE
  869. *
  870. RETURN
  871. *
  872. * end of SLARRE
  873. *
  874. END