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.

cstedc.f 16 kB

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