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

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