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.

dlarre.f 32 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901
  1. *> \brief \b DLARRE 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 DLARRE + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlarre.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlarre.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlarre.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DLARRE( 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. * DOUBLE PRECISION PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU
  30. * ..
  31. * .. Array Arguments ..
  32. * INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ),
  33. * $ INDEXW( * )
  34. * DOUBLE PRECISION 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, DLARRE 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. *> DSTEMR 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 DLASQ2) to
  54. *> compute all and then discard any unwanted one.
  55. *> As an added benefit, DLARRE 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 DOUBLE PRECISION
  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', DLARRE computes bounds on the desired
  85. *> part of the spectrum.
  86. *> \endverbatim
  87. *>
  88. *> \param[in,out] VU
  89. *> \verbatim
  90. *> VU is DOUBLE PRECISION
  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', DLARRE 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION
  146. *> \endverbatim
  147. *>
  148. *> \param[in] RTOL2
  149. *> \verbatim
  150. *> RTOL2 is DOUBLE PRECISION
  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 DOUBLE PRECISION
  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 DOUBLE PRECISION 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 ( DLARRE may use the
  191. *> remaining N-M elements as workspace).
  192. *> \endverbatim
  193. *>
  194. *> \param[out] WERR
  195. *> \verbatim
  196. *> WERR is DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION 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 DOUBLE PRECISION
  236. *> The minimum pivot in the Sturm sequence for T.
  237. *> \endverbatim
  238. *>
  239. *> \param[out] WORK
  240. *> \verbatim
  241. *> WORK is DOUBLE PRECISION 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 DLARRE.
  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 DLARRD.
  261. *> = 2: No base representation could be found in MAXTRY iterations.
  262. *> Increasing MAXTRY and recompilation might be a remedy.
  263. *> =-3: Problem in DLARRB when computing the refined root
  264. *> representation for DLASQ2.
  265. *> =-4: Problem in DLARRB when preforming bisection on the
  266. *> desired part of the spectrum.
  267. *> =-5: Problem in DLASQ2.
  268. *> =-6: Problem in DLASQ2.
  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. *> \ingroup OTHERauxiliary
  280. *
  281. *> \par Further Details:
  282. * =====================
  283. *>
  284. *> \verbatim
  285. *>
  286. *> The base representations are required to suffer very little
  287. *> element growth and consequently define all their eigenvalues to
  288. *> high relative accuracy.
  289. *> \endverbatim
  290. *
  291. *> \par Contributors:
  292. * ==================
  293. *>
  294. *> Beresford Parlett, University of California, Berkeley, USA \n
  295. *> Jim Demmel, University of California, Berkeley, USA \n
  296. *> Inderjit Dhillon, University of Texas, Austin, USA \n
  297. *> Osni Marques, LBNL/NERSC, USA \n
  298. *> Christof Voemel, University of California, Berkeley, USA \n
  299. *>
  300. * =====================================================================
  301. SUBROUTINE DLARRE( RANGE, N, VL, VU, IL, IU, D, E, E2,
  302. $ RTOL1, RTOL2, SPLTOL, NSPLIT, ISPLIT, M,
  303. $ W, WERR, WGAP, IBLOCK, INDEXW, GERS, PIVMIN,
  304. $ WORK, IWORK, INFO )
  305. *
  306. * -- LAPACK auxiliary routine --
  307. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  308. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  309. *
  310. * .. Scalar Arguments ..
  311. CHARACTER RANGE
  312. INTEGER IL, INFO, IU, M, N, NSPLIT
  313. DOUBLE PRECISION PIVMIN, RTOL1, RTOL2, SPLTOL, VL, VU
  314. * ..
  315. * .. Array Arguments ..
  316. INTEGER IBLOCK( * ), ISPLIT( * ), IWORK( * ),
  317. $ INDEXW( * )
  318. DOUBLE PRECISION D( * ), E( * ), E2( * ), GERS( * ),
  319. $ W( * ),WERR( * ), WGAP( * ), WORK( * )
  320. * ..
  321. *
  322. * =====================================================================
  323. *
  324. * .. Parameters ..
  325. DOUBLE PRECISION FAC, FOUR, FOURTH, FUDGE, HALF, HNDRD,
  326. $ MAXGROWTH, ONE, PERT, TWO, ZERO
  327. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0,
  328. $ TWO = 2.0D0, FOUR=4.0D0,
  329. $ HNDRD = 100.0D0,
  330. $ PERT = 8.0D0,
  331. $ HALF = ONE/TWO, FOURTH = ONE/FOUR, FAC= HALF,
  332. $ MAXGROWTH = 64.0D0, FUDGE = 2.0D0 )
  333. INTEGER MAXTRY, ALLRNG, INDRNG, VALRNG
  334. PARAMETER ( MAXTRY = 6, ALLRNG = 1, INDRNG = 2,
  335. $ VALRNG = 3 )
  336. * ..
  337. * .. Local Scalars ..
  338. LOGICAL FORCEB, NOREP, USEDQD
  339. INTEGER CNT, CNT1, CNT2, I, IBEGIN, IDUM, IEND, IINFO,
  340. $ IN, INDL, INDU, IRANGE, J, JBLK, MB, MM,
  341. $ WBEGIN, WEND
  342. DOUBLE PRECISION AVGAP, BSRTOL, CLWDTH, DMAX, DPIVOT, EABS,
  343. $ EMAX, EOLD, EPS, GL, GU, ISLEFT, ISRGHT, RTL,
  344. $ RTOL, S1, S2, SAFMIN, SGNDEF, SIGMA, SPDIAM,
  345. $ TAU, TMP, TMP1
  346. * ..
  347. * .. Local Arrays ..
  348. INTEGER ISEED( 4 )
  349. * ..
  350. * .. External Functions ..
  351. LOGICAL LSAME
  352. DOUBLE PRECISION DLAMCH
  353. EXTERNAL DLAMCH, LSAME
  354. * ..
  355. * .. External Subroutines ..
  356. EXTERNAL DCOPY, DLARNV, DLARRA, DLARRB, DLARRC, DLARRD,
  357. $ DLASQ2, DLARRK
  358. * ..
  359. * .. Intrinsic Functions ..
  360. INTRINSIC ABS, MAX, MIN
  361. * ..
  362. * .. Executable Statements ..
  363. *
  364. INFO = 0
  365. NSPLIT = 0
  366. M = 0
  367. *
  368. * Quick return if possible
  369. *
  370. IF( N.LE.0 ) THEN
  371. RETURN
  372. END IF
  373. *
  374. * Decode RANGE
  375. *
  376. IF( LSAME( RANGE, 'A' ) ) THEN
  377. IRANGE = ALLRNG
  378. ELSE IF( LSAME( RANGE, 'V' ) ) THEN
  379. IRANGE = VALRNG
  380. ELSE IF( LSAME( RANGE, 'I' ) ) THEN
  381. IRANGE = INDRNG
  382. END IF
  383. * Get machine constants
  384. SAFMIN = DLAMCH( 'S' )
  385. EPS = DLAMCH( 'P' )
  386. * Set parameters
  387. RTL = SQRT(EPS)
  388. BSRTOL = SQRT(EPS)
  389. * Treat case of 1x1 matrix for quick return
  390. IF( N.EQ.1 ) THEN
  391. IF( (IRANGE.EQ.ALLRNG).OR.
  392. $ ((IRANGE.EQ.VALRNG).AND.(D(1).GT.VL).AND.(D(1).LE.VU)).OR.
  393. $ ((IRANGE.EQ.INDRNG).AND.(IL.EQ.1).AND.(IU.EQ.1)) ) THEN
  394. M = 1
  395. W(1) = D(1)
  396. * The computation error of the eigenvalue is zero
  397. WERR(1) = ZERO
  398. WGAP(1) = ZERO
  399. IBLOCK( 1 ) = 1
  400. INDEXW( 1 ) = 1
  401. GERS(1) = D( 1 )
  402. GERS(2) = D( 1 )
  403. ENDIF
  404. * store the shift for the initial RRR, which is zero in this case
  405. E(1) = ZERO
  406. RETURN
  407. END IF
  408. * General case: tridiagonal matrix of order > 1
  409. *
  410. * Init WERR, WGAP. Compute Gerschgorin intervals and spectral diameter.
  411. * Compute maximum off-diagonal entry and pivmin.
  412. GL = D(1)
  413. GU = D(1)
  414. EOLD = ZERO
  415. EMAX = ZERO
  416. E(N) = ZERO
  417. DO 5 I = 1,N
  418. WERR(I) = ZERO
  419. WGAP(I) = ZERO
  420. EABS = ABS( E(I) )
  421. IF( EABS .GE. EMAX ) THEN
  422. EMAX = EABS
  423. END IF
  424. TMP1 = EABS + EOLD
  425. GERS( 2*I-1) = D(I) - TMP1
  426. GL = MIN( GL, GERS( 2*I - 1))
  427. GERS( 2*I ) = D(I) + TMP1
  428. GU = MAX( GU, GERS(2*I) )
  429. EOLD = EABS
  430. 5 CONTINUE
  431. * The minimum pivot allowed in the Sturm sequence for T
  432. PIVMIN = SAFMIN * MAX( ONE, EMAX**2 )
  433. * Compute spectral diameter. The Gerschgorin bounds give an
  434. * estimate that is wrong by at most a factor of SQRT(2)
  435. SPDIAM = GU - GL
  436. * Compute splitting points
  437. CALL DLARRA( N, D, E, E2, SPLTOL, SPDIAM,
  438. $ NSPLIT, ISPLIT, IINFO )
  439. * Can force use of bisection instead of faster DQDS.
  440. * Option left in the code for future multisection work.
  441. FORCEB = .FALSE.
  442. * Initialize USEDQD, DQDS should be used for ALLRNG unless someone
  443. * explicitly wants bisection.
  444. USEDQD = (( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB))
  445. IF( (IRANGE.EQ.ALLRNG) .AND. (.NOT. FORCEB) ) THEN
  446. * Set interval [VL,VU] that contains all eigenvalues
  447. VL = GL
  448. VU = GU
  449. ELSE
  450. * We call DLARRD to find crude approximations to the eigenvalues
  451. * in the desired range. In case IRANGE = INDRNG, we also obtain the
  452. * interval (VL,VU] that contains all the wanted eigenvalues.
  453. * An interval [LEFT,RIGHT] has converged if
  454. * RIGHT-LEFT.LT.RTOL*MAX(ABS(LEFT),ABS(RIGHT))
  455. * DLARRD needs a WORK of size 4*N, IWORK of size 3*N
  456. CALL DLARRD( RANGE, 'B', N, VL, VU, IL, IU, GERS,
  457. $ BSRTOL, D, E, E2, PIVMIN, NSPLIT, ISPLIT,
  458. $ MM, W, WERR, VL, VU, IBLOCK, INDEXW,
  459. $ WORK, IWORK, IINFO )
  460. IF( IINFO.NE.0 ) THEN
  461. INFO = -1
  462. RETURN
  463. ENDIF
  464. * Make sure that the entries M+1 to N in W, WERR, IBLOCK, INDEXW are 0
  465. DO 14 I = MM+1,N
  466. W( I ) = ZERO
  467. WERR( I ) = ZERO
  468. IBLOCK( I ) = 0
  469. INDEXW( I ) = 0
  470. 14 CONTINUE
  471. END IF
  472. ***
  473. * Loop over unreduced blocks
  474. IBEGIN = 1
  475. WBEGIN = 1
  476. DO 170 JBLK = 1, NSPLIT
  477. IEND = ISPLIT( JBLK )
  478. IN = IEND - IBEGIN + 1
  479. * 1 X 1 block
  480. IF( IN.EQ.1 ) THEN
  481. IF( (IRANGE.EQ.ALLRNG).OR.( (IRANGE.EQ.VALRNG).AND.
  482. $ ( D( IBEGIN ).GT.VL ).AND.( D( IBEGIN ).LE.VU ) )
  483. $ .OR. ( (IRANGE.EQ.INDRNG).AND.(IBLOCK(WBEGIN).EQ.JBLK))
  484. $ ) THEN
  485. M = M + 1
  486. W( M ) = D( IBEGIN )
  487. WERR(M) = ZERO
  488. * The gap for a single block doesn't matter for the later
  489. * algorithm and is assigned an arbitrary large value
  490. WGAP(M) = ZERO
  491. IBLOCK( M ) = JBLK
  492. INDEXW( M ) = 1
  493. WBEGIN = WBEGIN + 1
  494. ENDIF
  495. * E( IEND ) holds the shift for the initial RRR
  496. E( IEND ) = ZERO
  497. IBEGIN = IEND + 1
  498. GO TO 170
  499. END IF
  500. *
  501. * Blocks of size larger than 1x1
  502. *
  503. * E( IEND ) will hold the shift for the initial RRR, for now set it =0
  504. E( IEND ) = ZERO
  505. *
  506. * Find local outer bounds GL,GU for the block
  507. GL = D(IBEGIN)
  508. GU = D(IBEGIN)
  509. DO 15 I = IBEGIN , IEND
  510. GL = MIN( GERS( 2*I-1 ), GL )
  511. GU = MAX( GERS( 2*I ), GU )
  512. 15 CONTINUE
  513. SPDIAM = GU - GL
  514. IF(.NOT. ((IRANGE.EQ.ALLRNG).AND.(.NOT.FORCEB)) ) THEN
  515. * Count the number of eigenvalues in the current block.
  516. MB = 0
  517. DO 20 I = WBEGIN,MM
  518. IF( IBLOCK(I).EQ.JBLK ) THEN
  519. MB = MB+1
  520. ELSE
  521. GOTO 21
  522. ENDIF
  523. 20 CONTINUE
  524. 21 CONTINUE
  525. IF( MB.EQ.0) THEN
  526. * No eigenvalue in the current block lies in the desired range
  527. * E( IEND ) holds the shift for the initial RRR
  528. E( IEND ) = ZERO
  529. IBEGIN = IEND + 1
  530. GO TO 170
  531. ELSE
  532. * Decide whether dqds or bisection is more efficient
  533. USEDQD = ( (MB .GT. FAC*IN) .AND. (.NOT.FORCEB) )
  534. WEND = WBEGIN + MB - 1
  535. * Calculate gaps for the current block
  536. * In later stages, when representations for individual
  537. * eigenvalues are different, we use SIGMA = E( IEND ).
  538. SIGMA = ZERO
  539. DO 30 I = WBEGIN, WEND - 1
  540. WGAP( I ) = MAX( ZERO,
  541. $ W(I+1)-WERR(I+1) - (W(I)+WERR(I)) )
  542. 30 CONTINUE
  543. WGAP( WEND ) = MAX( ZERO,
  544. $ VU - SIGMA - (W( WEND )+WERR( WEND )))
  545. * Find local index of the first and last desired evalue.
  546. INDL = INDEXW(WBEGIN)
  547. INDU = INDEXW( WEND )
  548. ENDIF
  549. ENDIF
  550. IF(( (IRANGE.EQ.ALLRNG) .AND. (.NOT. FORCEB) ).OR.USEDQD) THEN
  551. * Case of DQDS
  552. * Find approximations to the extremal eigenvalues of the block
  553. CALL DLARRK( IN, 1, 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. ISLEFT = MAX(GL, TMP - TMP1
  560. $ - HNDRD * EPS* ABS(TMP - TMP1))
  561. CALL DLARRK( IN, IN, GL, GU, D(IBEGIN),
  562. $ E2(IBEGIN), PIVMIN, RTL, TMP, TMP1, IINFO )
  563. IF( IINFO.NE.0 ) THEN
  564. INFO = -1
  565. RETURN
  566. ENDIF
  567. ISRGHT = MIN(GU, TMP + TMP1
  568. $ + HNDRD * EPS * ABS(TMP + TMP1))
  569. * Improve the estimate of the spectral diameter
  570. SPDIAM = ISRGHT - ISLEFT
  571. ELSE
  572. * Case of bisection
  573. * Find approximations to the wanted extremal eigenvalues
  574. ISLEFT = MAX(GL, W(WBEGIN) - WERR(WBEGIN)
  575. $ - HNDRD * EPS*ABS(W(WBEGIN)- WERR(WBEGIN) ))
  576. ISRGHT = MIN(GU,W(WEND) + WERR(WEND)
  577. $ + HNDRD * EPS * ABS(W(WEND)+ WERR(WEND)))
  578. ENDIF
  579. * Decide whether the base representation for the current block
  580. * L_JBLK D_JBLK L_JBLK^T = T_JBLK - sigma_JBLK I
  581. * should be on the left or the right end of the current block.
  582. * The strategy is to shift to the end which is "more populated"
  583. * Furthermore, decide whether to use DQDS for the computation of
  584. * the eigenvalue approximations at the end of DLARRE or bisection.
  585. * dqds is chosen if all eigenvalues are desired or the number of
  586. * eigenvalues to be computed is large compared to the blocksize.
  587. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  588. * If all the eigenvalues have to be computed, we use dqd
  589. USEDQD = .TRUE.
  590. * INDL is the local index of the first eigenvalue to compute
  591. INDL = 1
  592. INDU = IN
  593. * MB = number of eigenvalues to compute
  594. MB = IN
  595. WEND = WBEGIN + MB - 1
  596. * Define 1/4 and 3/4 points of the spectrum
  597. S1 = ISLEFT + FOURTH * SPDIAM
  598. S2 = ISRGHT - FOURTH * SPDIAM
  599. ELSE
  600. * DLARRD has computed IBLOCK and INDEXW for each eigenvalue
  601. * approximation.
  602. * choose sigma
  603. IF( USEDQD ) THEN
  604. S1 = ISLEFT + FOURTH * SPDIAM
  605. S2 = ISRGHT - FOURTH * SPDIAM
  606. ELSE
  607. TMP = MIN(ISRGHT,VU) - MAX(ISLEFT,VL)
  608. S1 = MAX(ISLEFT,VL) + FOURTH * TMP
  609. S2 = MIN(ISRGHT,VU) - FOURTH * TMP
  610. ENDIF
  611. ENDIF
  612. * Compute the negcount at the 1/4 and 3/4 points
  613. IF(MB.GT.1) THEN
  614. CALL DLARRC( 'T', IN, S1, S2, D(IBEGIN),
  615. $ E(IBEGIN), PIVMIN, CNT, CNT1, CNT2, IINFO)
  616. ENDIF
  617. IF(MB.EQ.1) THEN
  618. SIGMA = GL
  619. SGNDEF = ONE
  620. ELSEIF( CNT1 - INDL .GE. INDU - CNT2 ) THEN
  621. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  622. SIGMA = MAX(ISLEFT,GL)
  623. ELSEIF( USEDQD ) THEN
  624. * use Gerschgorin bound as shift to get pos def matrix
  625. * for dqds
  626. SIGMA = ISLEFT
  627. ELSE
  628. * use approximation of the first desired eigenvalue of the
  629. * block as shift
  630. SIGMA = MAX(ISLEFT,VL)
  631. ENDIF
  632. SGNDEF = ONE
  633. ELSE
  634. IF( ( IRANGE.EQ.ALLRNG ) .AND. (.NOT.FORCEB) ) THEN
  635. SIGMA = MIN(ISRGHT,GU)
  636. ELSEIF( USEDQD ) THEN
  637. * use Gerschgorin bound as shift to get neg def matrix
  638. * for dqds
  639. SIGMA = ISRGHT
  640. ELSE
  641. * use approximation of the first desired eigenvalue of the
  642. * block as shift
  643. SIGMA = MIN(ISRGHT,VU)
  644. ENDIF
  645. SGNDEF = -ONE
  646. ENDIF
  647. * An initial SIGMA has been chosen that will be used for computing
  648. * T - SIGMA I = L D L^T
  649. * Define the increment TAU of the shift in case the initial shift
  650. * needs to be refined to obtain a factorization with not too much
  651. * element growth.
  652. IF( USEDQD ) THEN
  653. * The initial SIGMA was to the outer end of the spectrum
  654. * the matrix is definite and we need not retreat.
  655. TAU = SPDIAM*EPS*N + TWO*PIVMIN
  656. TAU = MAX( TAU,TWO*EPS*ABS(SIGMA) )
  657. ELSE
  658. IF(MB.GT.1) THEN
  659. CLWDTH = W(WEND) + WERR(WEND) - W(WBEGIN) - WERR(WBEGIN)
  660. AVGAP = ABS(CLWDTH / DBLE(WEND-WBEGIN))
  661. IF( SGNDEF.EQ.ONE ) THEN
  662. TAU = HALF*MAX(WGAP(WBEGIN),AVGAP)
  663. TAU = MAX(TAU,WERR(WBEGIN))
  664. ELSE
  665. TAU = HALF*MAX(WGAP(WEND-1),AVGAP)
  666. TAU = MAX(TAU,WERR(WEND))
  667. ENDIF
  668. ELSE
  669. TAU = WERR(WBEGIN)
  670. ENDIF
  671. ENDIF
  672. *
  673. DO 80 IDUM = 1, MAXTRY
  674. * Compute L D L^T factorization of tridiagonal matrix T - sigma I.
  675. * Store D in WORK(1:IN), L in WORK(IN+1:2*IN), and reciprocals of
  676. * pivots in WORK(2*IN+1:3*IN)
  677. DPIVOT = D( IBEGIN ) - SIGMA
  678. WORK( 1 ) = DPIVOT
  679. DMAX = ABS( WORK(1) )
  680. J = IBEGIN
  681. DO 70 I = 1, IN - 1
  682. WORK( 2*IN+I ) = ONE / WORK( I )
  683. TMP = E( J )*WORK( 2*IN+I )
  684. WORK( IN+I ) = TMP
  685. DPIVOT = ( D( J+1 )-SIGMA ) - TMP*E( J )
  686. WORK( I+1 ) = DPIVOT
  687. DMAX = MAX( DMAX, ABS(DPIVOT) )
  688. J = J + 1
  689. 70 CONTINUE
  690. * check for element growth
  691. IF( DMAX .GT. MAXGROWTH*SPDIAM ) THEN
  692. NOREP = .TRUE.
  693. ELSE
  694. NOREP = .FALSE.
  695. ENDIF
  696. IF( USEDQD .AND. .NOT.NOREP ) THEN
  697. * Ensure the definiteness of the representation
  698. * All entries of D (of L D L^T) must have the same sign
  699. DO 71 I = 1, IN
  700. TMP = SGNDEF*WORK( I )
  701. IF( TMP.LT.ZERO ) NOREP = .TRUE.
  702. 71 CONTINUE
  703. ENDIF
  704. IF(NOREP) THEN
  705. * Note that in the case of IRANGE=ALLRNG, we use the Gerschgorin
  706. * shift which makes the matrix definite. So we should end up
  707. * here really only in the case of IRANGE = VALRNG or INDRNG.
  708. IF( IDUM.EQ.MAXTRY-1 ) THEN
  709. IF( SGNDEF.EQ.ONE ) THEN
  710. * The fudged Gerschgorin shift should succeed
  711. SIGMA =
  712. $ GL - FUDGE*SPDIAM*EPS*N - FUDGE*TWO*PIVMIN
  713. ELSE
  714. SIGMA =
  715. $ GU + FUDGE*SPDIAM*EPS*N + FUDGE*TWO*PIVMIN
  716. END IF
  717. ELSE
  718. SIGMA = SIGMA - SGNDEF * TAU
  719. TAU = TWO * TAU
  720. END IF
  721. ELSE
  722. * an initial RRR is found
  723. GO TO 83
  724. END IF
  725. 80 CONTINUE
  726. * if the program reaches this point, no base representation could be
  727. * found in MAXTRY iterations.
  728. INFO = 2
  729. RETURN
  730. 83 CONTINUE
  731. * At this point, we have found an initial base representation
  732. * T - SIGMA I = L D L^T with not too much element growth.
  733. * Store the shift.
  734. E( IEND ) = SIGMA
  735. * Store D and L.
  736. CALL DCOPY( IN, WORK, 1, D( IBEGIN ), 1 )
  737. CALL DCOPY( IN-1, WORK( IN+1 ), 1, E( IBEGIN ), 1 )
  738. IF(MB.GT.1 ) THEN
  739. *
  740. * Perturb each entry of the base representation by a small
  741. * (but random) relative amount to overcome difficulties with
  742. * glued matrices.
  743. *
  744. DO 122 I = 1, 4
  745. ISEED( I ) = 1
  746. 122 CONTINUE
  747. CALL DLARNV(2, ISEED, 2*IN-1, WORK(1))
  748. DO 125 I = 1,IN-1
  749. D(IBEGIN+I-1) = D(IBEGIN+I-1)*(ONE+EPS*PERT*WORK(I))
  750. E(IBEGIN+I-1) = E(IBEGIN+I-1)*(ONE+EPS*PERT*WORK(IN+I))
  751. 125 CONTINUE
  752. D(IEND) = D(IEND)*(ONE+EPS*FOUR*WORK(IN))
  753. *
  754. ENDIF
  755. *
  756. * Don't update the Gerschgorin intervals because keeping track
  757. * of the updates would be too much work in DLARRV.
  758. * We update W instead and use it to locate the proper Gerschgorin
  759. * intervals.
  760. * Compute the required eigenvalues of L D L' by bisection or dqds
  761. IF ( .NOT.USEDQD ) THEN
  762. * If DLARRD has been used, shift the eigenvalue approximations
  763. * according to their representation. This is necessary for
  764. * a uniform DLARRV since dqds computes eigenvalues of the
  765. * shifted representation. In DLARRV, W will always hold the
  766. * UNshifted eigenvalue approximation.
  767. DO 134 J=WBEGIN,WEND
  768. W(J) = W(J) - SIGMA
  769. WERR(J) = WERR(J) + ABS(W(J)) * EPS
  770. 134 CONTINUE
  771. * call DLARRB to reduce eigenvalue error of the approximations
  772. * from DLARRD
  773. DO 135 I = IBEGIN, IEND-1
  774. WORK( I ) = D( I ) * E( I )**2
  775. 135 CONTINUE
  776. * use bisection to find EV from INDL to INDU
  777. CALL DLARRB(IN, D(IBEGIN), WORK(IBEGIN),
  778. $ INDL, INDU, RTOL1, RTOL2, INDL-1,
  779. $ W(WBEGIN), WGAP(WBEGIN), WERR(WBEGIN),
  780. $ WORK( 2*N+1 ), IWORK, PIVMIN, SPDIAM,
  781. $ IN, IINFO )
  782. IF( IINFO .NE. 0 ) THEN
  783. INFO = -4
  784. RETURN
  785. END IF
  786. * DLARRB computes all gaps correctly except for the last one
  787. * Record distance to VU/GU
  788. WGAP( WEND ) = MAX( ZERO,
  789. $ ( VU-SIGMA ) - ( W( WEND ) + WERR( WEND ) ) )
  790. DO 138 I = INDL, INDU
  791. M = M + 1
  792. IBLOCK(M) = JBLK
  793. INDEXW(M) = I
  794. 138 CONTINUE
  795. ELSE
  796. * Call dqds to get all eigs (and then possibly delete unwanted
  797. * eigenvalues).
  798. * Note that dqds finds the eigenvalues of the L D L^T representation
  799. * of T to high relative accuracy. High relative accuracy
  800. * might be lost when the shift of the RRR is subtracted to obtain
  801. * the eigenvalues of T. However, T is not guaranteed to define its
  802. * eigenvalues to high relative accuracy anyway.
  803. * Set RTOL to the order of the tolerance used in DLASQ2
  804. * This is an ESTIMATED error, the worst case bound is 4*N*EPS
  805. * which is usually too large and requires unnecessary work to be
  806. * done by bisection when computing the eigenvectors
  807. RTOL = LOG(DBLE(IN)) * FOUR * EPS
  808. J = IBEGIN
  809. DO 140 I = 1, IN - 1
  810. WORK( 2*I-1 ) = ABS( D( J ) )
  811. WORK( 2*I ) = E( J )*E( J )*WORK( 2*I-1 )
  812. J = J + 1
  813. 140 CONTINUE
  814. WORK( 2*IN-1 ) = ABS( D( IEND ) )
  815. WORK( 2*IN ) = ZERO
  816. CALL DLASQ2( IN, WORK, IINFO )
  817. IF( IINFO .NE. 0 ) THEN
  818. * If IINFO = -5 then an index is part of a tight cluster
  819. * and should be changed. The index is in IWORK(1) and the
  820. * gap is in WORK(N+1)
  821. INFO = -5
  822. RETURN
  823. ELSE
  824. * Test that all eigenvalues are positive as expected
  825. DO 149 I = 1, IN
  826. IF( WORK( I ).LT.ZERO ) THEN
  827. INFO = -6
  828. RETURN
  829. ENDIF
  830. 149 CONTINUE
  831. END IF
  832. IF( SGNDEF.GT.ZERO ) THEN
  833. DO 150 I = INDL, INDU
  834. M = M + 1
  835. W( M ) = WORK( IN-I+1 )
  836. IBLOCK( M ) = JBLK
  837. INDEXW( M ) = I
  838. 150 CONTINUE
  839. ELSE
  840. DO 160 I = INDL, INDU
  841. M = M + 1
  842. W( M ) = -WORK( I )
  843. IBLOCK( M ) = JBLK
  844. INDEXW( M ) = I
  845. 160 CONTINUE
  846. END IF
  847. DO 165 I = M - MB + 1, M
  848. * the value of RTOL below should be the tolerance in DLASQ2
  849. WERR( I ) = RTOL * ABS( W(I) )
  850. 165 CONTINUE
  851. DO 166 I = M - MB + 1, M - 1
  852. * compute the right gap between the intervals
  853. WGAP( I ) = MAX( ZERO,
  854. $ W(I+1)-WERR(I+1) - (W(I)+WERR(I)) )
  855. 166 CONTINUE
  856. WGAP( M ) = MAX( ZERO,
  857. $ ( VU-SIGMA ) - ( W( M ) + WERR( M ) ) )
  858. END IF
  859. * proceed with next block
  860. IBEGIN = IEND + 1
  861. WBEGIN = WEND + 1
  862. 170 CONTINUE
  863. *
  864. RETURN
  865. *
  866. * End of DLARRE
  867. *
  868. END