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.

dstedc.f 15 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. *> \brief \b DSTEDC
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download DSTEDC + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dstedc.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dstedc.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dstedc.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DSTEDC( COMPZ, N, D, E, Z, LDZ, WORK, LWORK, IWORK,
  22. * LIWORK, INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER COMPZ
  26. * INTEGER INFO, LDZ, LIWORK, LWORK, N
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IWORK( * )
  30. * DOUBLE PRECISION D( * ), E( * ), WORK( * ), Z( LDZ, * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *>
  39. *> DSTEDC computes all eigenvalues and, optionally, eigenvectors of a
  40. *> symmetric tridiagonal matrix using the divide and conquer method.
  41. *> The eigenvectors of a full or band real symmetric matrix can also be
  42. *> found if DSYTRD or DSPTRD or DSBTRD has been used to reduce this
  43. *> matrix to tridiagonal form.
  44. *>
  45. *> \endverbatim
  46. *
  47. * Arguments:
  48. * ==========
  49. *
  50. *> \param[in] COMPZ
  51. *> \verbatim
  52. *> COMPZ is CHARACTER*1
  53. *> = 'N': Compute eigenvalues only.
  54. *> = 'I': Compute eigenvectors of tridiagonal matrix also.
  55. *> = 'V': Compute eigenvectors of original dense symmetric
  56. *> matrix also. On entry, Z contains the orthogonal
  57. *> matrix used to reduce the original matrix to
  58. *> tridiagonal form.
  59. *> \endverbatim
  60. *>
  61. *> \param[in] N
  62. *> \verbatim
  63. *> N is INTEGER
  64. *> The dimension of the symmetric tridiagonal matrix. N >= 0.
  65. *> \endverbatim
  66. *>
  67. *> \param[in,out] D
  68. *> \verbatim
  69. *> D is DOUBLE PRECISION array, dimension (N)
  70. *> On entry, the diagonal elements of the tridiagonal matrix.
  71. *> On exit, if INFO = 0, the eigenvalues in ascending order.
  72. *> \endverbatim
  73. *>
  74. *> \param[in,out] E
  75. *> \verbatim
  76. *> E is DOUBLE PRECISION array, dimension (N-1)
  77. *> On entry, the subdiagonal elements of the tridiagonal matrix.
  78. *> On exit, E has been destroyed.
  79. *> \endverbatim
  80. *>
  81. *> \param[in,out] Z
  82. *> \verbatim
  83. *> Z is DOUBLE PRECISION array, dimension (LDZ,N)
  84. *> On entry, if COMPZ = 'V', then Z contains the orthogonal
  85. *> matrix used in the reduction to tridiagonal form.
  86. *> On exit, if INFO = 0, then if COMPZ = 'V', Z contains the
  87. *> orthonormal eigenvectors of the original symmetric matrix,
  88. *> and if COMPZ = 'I', Z contains the orthonormal eigenvectors
  89. *> of the symmetric tridiagonal matrix.
  90. *> If COMPZ = 'N', then Z is not referenced.
  91. *> \endverbatim
  92. *>
  93. *> \param[in] LDZ
  94. *> \verbatim
  95. *> LDZ is INTEGER
  96. *> The leading dimension of the array Z. LDZ >= 1.
  97. *> If eigenvectors are desired, then LDZ >= max(1,N).
  98. *> \endverbatim
  99. *>
  100. *> \param[out] WORK
  101. *> \verbatim
  102. *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK))
  103. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  104. *> \endverbatim
  105. *>
  106. *> \param[in] LWORK
  107. *> \verbatim
  108. *> LWORK is INTEGER
  109. *> The dimension of the array WORK.
  110. *> If COMPZ = 'N' or N <= 1 then LWORK must be at least 1.
  111. *> If COMPZ = 'V' and N > 1 then LWORK must be at least
  112. *> ( 1 + 3*N + 2*N*lg N + 4*N**2 ),
  113. *> where lg( N ) = smallest integer k such
  114. *> that 2**k >= N.
  115. *> If COMPZ = 'I' and N > 1 then LWORK must be at least
  116. *> ( 1 + 4*N + N**2 ).
  117. *> Note that for COMPZ = 'I' or 'V', then if N is less than or
  118. *> equal to the minimum divide size, usually 25, then LWORK need
  119. *> only be max(1,2*(N-1)).
  120. *>
  121. *> If LWORK = -1, then a workspace query is assumed; the routine
  122. *> only calculates the optimal size of the WORK array, returns
  123. *> this value as the first entry of the WORK array, and no error
  124. *> message related to LWORK is issued by XERBLA.
  125. *> \endverbatim
  126. *>
  127. *> \param[out] IWORK
  128. *> \verbatim
  129. *> IWORK is INTEGER array, dimension (MAX(1,LIWORK))
  130. *> On exit, if INFO = 0, IWORK(1) returns the optimal LIWORK.
  131. *> \endverbatim
  132. *>
  133. *> \param[in] LIWORK
  134. *> \verbatim
  135. *> LIWORK is INTEGER
  136. *> The dimension of the array IWORK.
  137. *> If COMPZ = 'N' or N <= 1 then LIWORK must be at least 1.
  138. *> If COMPZ = 'V' and N > 1 then LIWORK must be at least
  139. *> ( 6 + 6*N + 5*N*lg N ).
  140. *> If COMPZ = 'I' and N > 1 then LIWORK must be at least
  141. *> ( 3 + 5*N ).
  142. *> Note that for COMPZ = 'I' or 'V', then if N is less than or
  143. *> equal to the minimum divide size, usually 25, then LIWORK
  144. *> need only be 1.
  145. *>
  146. *> If LIWORK = -1, then a workspace query is assumed; the
  147. *> routine only calculates the optimal size of the IWORK array,
  148. *> returns this value as the first entry of the IWORK array, and
  149. *> no error message related to LIWORK is issued by XERBLA.
  150. *> \endverbatim
  151. *>
  152. *> \param[out] INFO
  153. *> \verbatim
  154. *> INFO is INTEGER
  155. *> = 0: successful exit.
  156. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  157. *> > 0: The algorithm failed to compute an eigenvalue while
  158. *> working on the submatrix lying in rows and columns
  159. *> INFO/(N+1) through mod(INFO,N+1).
  160. *> \endverbatim
  161. *
  162. * Authors:
  163. * ========
  164. *
  165. *> \author Univ. of Tennessee
  166. *> \author Univ. of California Berkeley
  167. *> \author Univ. of Colorado Denver
  168. *> \author NAG Ltd.
  169. *
  170. *> \ingroup auxOTHERcomputational
  171. *
  172. *> \par Contributors:
  173. * ==================
  174. *>
  175. *> Jeff Rutter, Computer Science Division, University of California
  176. *> at Berkeley, USA \n
  177. *> Modified by Francoise Tisseur, University of Tennessee
  178. *>
  179. * =====================================================================
  180. SUBROUTINE DSTEDC( COMPZ, N, D, E, Z, LDZ, WORK, LWORK, IWORK,
  181. $ LIWORK, INFO )
  182. *
  183. * -- LAPACK computational routine --
  184. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  185. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  186. *
  187. * .. Scalar Arguments ..
  188. CHARACTER COMPZ
  189. INTEGER INFO, LDZ, LIWORK, LWORK, N
  190. * ..
  191. * .. Array Arguments ..
  192. INTEGER IWORK( * )
  193. DOUBLE PRECISION D( * ), E( * ), WORK( * ), Z( LDZ, * )
  194. * ..
  195. *
  196. * =====================================================================
  197. *
  198. * .. Parameters ..
  199. DOUBLE PRECISION ZERO, ONE, TWO
  200. PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )
  201. * ..
  202. * .. Local Scalars ..
  203. LOGICAL LQUERY
  204. INTEGER FINISH, I, ICOMPZ, II, J, K, LGN, LIWMIN,
  205. $ LWMIN, M, SMLSIZ, START, STOREZ, STRTRW
  206. DOUBLE PRECISION EPS, ORGNRM, P, TINY
  207. * ..
  208. * .. External Functions ..
  209. LOGICAL LSAME
  210. INTEGER ILAENV
  211. DOUBLE PRECISION DLAMCH, DLANST
  212. EXTERNAL LSAME, ILAENV, DLAMCH, DLANST
  213. * ..
  214. * .. External Subroutines ..
  215. EXTERNAL DGEMM, DLACPY, DLAED0, DLASCL, DLASET, DLASRT,
  216. $ DSTEQR, DSTERF, DSWAP, XERBLA
  217. * ..
  218. * .. Intrinsic Functions ..
  219. INTRINSIC ABS, DBLE, INT, LOG, MAX, MOD, SQRT
  220. * ..
  221. * .. Executable Statements ..
  222. *
  223. * Test the input parameters.
  224. *
  225. INFO = 0
  226. LQUERY = ( LWORK.EQ.-1 .OR. LIWORK.EQ.-1 )
  227. *
  228. IF( LSAME( COMPZ, 'N' ) ) THEN
  229. ICOMPZ = 0
  230. ELSE IF( LSAME( COMPZ, 'V' ) ) THEN
  231. ICOMPZ = 1
  232. ELSE IF( LSAME( COMPZ, 'I' ) ) THEN
  233. ICOMPZ = 2
  234. ELSE
  235. ICOMPZ = -1
  236. END IF
  237. IF( ICOMPZ.LT.0 ) THEN
  238. INFO = -1
  239. ELSE IF( N.LT.0 ) THEN
  240. INFO = -2
  241. ELSE IF( ( LDZ.LT.1 ) .OR.
  242. $ ( ICOMPZ.GT.0 .AND. LDZ.LT.MAX( 1, N ) ) ) THEN
  243. INFO = -6
  244. END IF
  245. *
  246. IF( INFO.EQ.0 ) THEN
  247. *
  248. * Compute the workspace requirements
  249. *
  250. SMLSIZ = ILAENV( 9, 'DSTEDC', ' ', 0, 0, 0, 0 )
  251. IF( N.LE.1 .OR. ICOMPZ.EQ.0 ) THEN
  252. LIWMIN = 1
  253. LWMIN = 1
  254. ELSE IF( N.LE.SMLSIZ ) THEN
  255. LIWMIN = 1
  256. LWMIN = 2*( N - 1 )
  257. ELSE
  258. LGN = INT( LOG( DBLE( N ) )/LOG( TWO ) )
  259. IF( 2**LGN.LT.N )
  260. $ LGN = LGN + 1
  261. IF( 2**LGN.LT.N )
  262. $ LGN = LGN + 1
  263. IF( ICOMPZ.EQ.1 ) THEN
  264. LWMIN = 1 + 3*N + 2*N*LGN + 4*N**2
  265. LIWMIN = 6 + 6*N + 5*N*LGN
  266. ELSE IF( ICOMPZ.EQ.2 ) THEN
  267. LWMIN = 1 + 4*N + N**2
  268. LIWMIN = 3 + 5*N
  269. END IF
  270. END IF
  271. WORK( 1 ) = LWMIN
  272. IWORK( 1 ) = LIWMIN
  273. *
  274. IF( LWORK.LT.LWMIN .AND. .NOT. LQUERY ) THEN
  275. INFO = -8
  276. ELSE IF( LIWORK.LT.LIWMIN .AND. .NOT. LQUERY ) THEN
  277. INFO = -10
  278. END IF
  279. END IF
  280. *
  281. IF( INFO.NE.0 ) THEN
  282. CALL XERBLA( 'DSTEDC', -INFO )
  283. RETURN
  284. ELSE IF (LQUERY) THEN
  285. RETURN
  286. END IF
  287. *
  288. * Quick return if possible
  289. *
  290. IF( N.EQ.0 )
  291. $ RETURN
  292. IF( N.EQ.1 ) THEN
  293. IF( ICOMPZ.NE.0 )
  294. $ Z( 1, 1 ) = ONE
  295. RETURN
  296. END IF
  297. *
  298. * If the following conditional clause is removed, then the routine
  299. * will use the Divide and Conquer routine to compute only the
  300. * eigenvalues, which requires (3N + 3N**2) real workspace and
  301. * (2 + 5N + 2N lg(N)) integer workspace.
  302. * Since on many architectures DSTERF is much faster than any other
  303. * algorithm for finding eigenvalues only, it is used here
  304. * as the default. If the conditional clause is removed, then
  305. * information on the size of workspace needs to be changed.
  306. *
  307. * If COMPZ = 'N', use DSTERF to compute the eigenvalues.
  308. *
  309. IF( ICOMPZ.EQ.0 ) THEN
  310. CALL DSTERF( N, D, E, INFO )
  311. GO TO 50
  312. END IF
  313. *
  314. * If N is smaller than the minimum divide size (SMLSIZ+1), then
  315. * solve the problem with another solver.
  316. *
  317. IF( N.LE.SMLSIZ ) THEN
  318. *
  319. CALL DSTEQR( COMPZ, N, D, E, Z, LDZ, WORK, INFO )
  320. *
  321. ELSE
  322. *
  323. * If COMPZ = 'V', the Z matrix must be stored elsewhere for later
  324. * use.
  325. *
  326. IF( ICOMPZ.EQ.1 ) THEN
  327. STOREZ = 1 + N*N
  328. ELSE
  329. STOREZ = 1
  330. END IF
  331. *
  332. IF( ICOMPZ.EQ.2 ) THEN
  333. CALL DLASET( 'Full', N, N, ZERO, ONE, Z, LDZ )
  334. END IF
  335. *
  336. * Scale.
  337. *
  338. ORGNRM = DLANST( 'M', N, D, E )
  339. IF( ORGNRM.EQ.ZERO )
  340. $ GO TO 50
  341. *
  342. EPS = DLAMCH( 'Epsilon' )
  343. *
  344. START = 1
  345. *
  346. * while ( START <= N )
  347. *
  348. 10 CONTINUE
  349. IF( START.LE.N ) THEN
  350. *
  351. * Let FINISH be the position of the next subdiagonal entry
  352. * such that E( FINISH ) <= TINY or FINISH = N if no such
  353. * subdiagonal exists. The matrix identified by the elements
  354. * between START and FINISH constitutes an independent
  355. * sub-problem.
  356. *
  357. FINISH = START
  358. 20 CONTINUE
  359. IF( FINISH.LT.N ) THEN
  360. TINY = EPS*SQRT( ABS( D( FINISH ) ) )*
  361. $ SQRT( ABS( D( FINISH+1 ) ) )
  362. IF( ABS( E( FINISH ) ).GT.TINY ) THEN
  363. FINISH = FINISH + 1
  364. GO TO 20
  365. END IF
  366. END IF
  367. *
  368. * (Sub) Problem determined. Compute its size and solve it.
  369. *
  370. M = FINISH - START + 1
  371. IF( M.EQ.1 ) THEN
  372. START = FINISH + 1
  373. GO TO 10
  374. END IF
  375. IF( M.GT.SMLSIZ ) THEN
  376. *
  377. * Scale.
  378. *
  379. ORGNRM = DLANST( 'M', M, D( START ), E( START ) )
  380. CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, M, 1, D( START ), M,
  381. $ INFO )
  382. CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, M-1, 1, E( START ),
  383. $ M-1, INFO )
  384. *
  385. IF( ICOMPZ.EQ.1 ) THEN
  386. STRTRW = 1
  387. ELSE
  388. STRTRW = START
  389. END IF
  390. CALL DLAED0( ICOMPZ, N, M, D( START ), E( START ),
  391. $ Z( STRTRW, START ), LDZ, WORK( 1 ), N,
  392. $ WORK( STOREZ ), IWORK, INFO )
  393. IF( INFO.NE.0 ) THEN
  394. INFO = ( INFO / ( M+1 )+START-1 )*( N+1 ) +
  395. $ MOD( INFO, ( M+1 ) ) + START - 1
  396. GO TO 50
  397. END IF
  398. *
  399. * Scale back.
  400. *
  401. CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, M, 1, D( START ), M,
  402. $ INFO )
  403. *
  404. ELSE
  405. IF( ICOMPZ.EQ.1 ) THEN
  406. *
  407. * Since QR won't update a Z matrix which is larger than
  408. * the length of D, we must solve the sub-problem in a
  409. * workspace and then multiply back into Z.
  410. *
  411. CALL DSTEQR( 'I', M, D( START ), E( START ), WORK, M,
  412. $ WORK( M*M+1 ), INFO )
  413. CALL DLACPY( 'A', N, M, Z( 1, START ), LDZ,
  414. $ WORK( STOREZ ), N )
  415. CALL DGEMM( 'N', 'N', N, M, M, ONE,
  416. $ WORK( STOREZ ), N, WORK, M, ZERO,
  417. $ Z( 1, START ), LDZ )
  418. ELSE IF( ICOMPZ.EQ.2 ) THEN
  419. CALL DSTEQR( 'I', M, D( START ), E( START ),
  420. $ Z( START, START ), LDZ, WORK, INFO )
  421. ELSE
  422. CALL DSTERF( M, D( START ), E( START ), INFO )
  423. END IF
  424. IF( INFO.NE.0 ) THEN
  425. INFO = START*( N+1 ) + FINISH
  426. GO TO 50
  427. END IF
  428. END IF
  429. *
  430. START = FINISH + 1
  431. GO TO 10
  432. END IF
  433. *
  434. * endwhile
  435. *
  436. IF( ICOMPZ.EQ.0 ) THEN
  437. *
  438. * Use Quick Sort
  439. *
  440. CALL DLASRT( 'I', N, D, INFO )
  441. *
  442. ELSE
  443. *
  444. * Use Selection Sort to minimize swaps of eigenvectors
  445. *
  446. DO 40 II = 2, N
  447. I = II - 1
  448. K = I
  449. P = D( I )
  450. DO 30 J = II, N
  451. IF( D( J ).LT.P ) THEN
  452. K = J
  453. P = D( J )
  454. END IF
  455. 30 CONTINUE
  456. IF( K.NE.I ) THEN
  457. D( K ) = D( I )
  458. D( I ) = P
  459. CALL DSWAP( N, Z( 1, I ), 1, Z( 1, K ), 1 )
  460. END IF
  461. 40 CONTINUE
  462. END IF
  463. END IF
  464. *
  465. 50 CONTINUE
  466. WORK( 1 ) = LWMIN
  467. IWORK( 1 ) = LIWMIN
  468. *
  469. RETURN
  470. *
  471. * End of DSTEDC
  472. *
  473. END