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.

chetrd.f 12 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377
  1. *> \brief \b CHETRD
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download CHETRD + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/chetrd.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/chetrd.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/chetrd.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE CHETRD( UPLO, N, A, LDA, D, E, TAU, WORK, LWORK, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, LDA, LWORK, N
  26. * ..
  27. * .. Array Arguments ..
  28. * REAL D( * ), E( * )
  29. * COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> CHETRD reduces a complex Hermitian matrix A to real symmetric
  39. *> tridiagonal form T by a unitary similarity transformation:
  40. *> Q**H * A * Q = T.
  41. *> \endverbatim
  42. *
  43. * Arguments:
  44. * ==========
  45. *
  46. *> \param[in] UPLO
  47. *> \verbatim
  48. *> UPLO is CHARACTER*1
  49. *> = 'U': Upper triangle of A is stored;
  50. *> = 'L': Lower triangle of A is stored.
  51. *> \endverbatim
  52. *>
  53. *> \param[in] N
  54. *> \verbatim
  55. *> N is INTEGER
  56. *> The order of the matrix A. N >= 0.
  57. *> \endverbatim
  58. *>
  59. *> \param[in,out] A
  60. *> \verbatim
  61. *> A is COMPLEX array, dimension (LDA,N)
  62. *> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
  63. *> N-by-N upper triangular part of A contains the upper
  64. *> triangular part of the matrix A, and the strictly lower
  65. *> triangular part of A is not referenced. If UPLO = 'L', the
  66. *> leading N-by-N lower triangular part of A contains the lower
  67. *> triangular part of the matrix A, and the strictly upper
  68. *> triangular part of A is not referenced.
  69. *> On exit, if UPLO = 'U', the diagonal and first superdiagonal
  70. *> of A are overwritten by the corresponding elements of the
  71. *> tridiagonal matrix T, and the elements above the first
  72. *> superdiagonal, with the array TAU, represent the unitary
  73. *> matrix Q as a product of elementary reflectors; if UPLO
  74. *> = 'L', the diagonal and first subdiagonal of A are over-
  75. *> written by the corresponding elements of the tridiagonal
  76. *> matrix T, and the elements below the first subdiagonal, with
  77. *> the array TAU, represent the unitary matrix Q as a product
  78. *> of elementary reflectors. See Further Details.
  79. *> \endverbatim
  80. *>
  81. *> \param[in] LDA
  82. *> \verbatim
  83. *> LDA is INTEGER
  84. *> The leading dimension of the array A. LDA >= max(1,N).
  85. *> \endverbatim
  86. *>
  87. *> \param[out] D
  88. *> \verbatim
  89. *> D is REAL array, dimension (N)
  90. *> The diagonal elements of the tridiagonal matrix T:
  91. *> D(i) = A(i,i).
  92. *> \endverbatim
  93. *>
  94. *> \param[out] E
  95. *> \verbatim
  96. *> E is REAL array, dimension (N-1)
  97. *> The off-diagonal elements of the tridiagonal matrix T:
  98. *> E(i) = A(i,i+1) if UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'.
  99. *> \endverbatim
  100. *>
  101. *> \param[out] TAU
  102. *> \verbatim
  103. *> TAU is COMPLEX array, dimension (N-1)
  104. *> The scalar factors of the elementary reflectors (see Further
  105. *> Details).
  106. *> \endverbatim
  107. *>
  108. *> \param[out] WORK
  109. *> \verbatim
  110. *> WORK is COMPLEX array, dimension (MAX(1,LWORK))
  111. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  112. *> \endverbatim
  113. *>
  114. *> \param[in] LWORK
  115. *> \verbatim
  116. *> LWORK is INTEGER
  117. *> The dimension of the array WORK. LWORK >= 1.
  118. *> For optimum performance LWORK >= N*NB, where NB is the
  119. *> optimal blocksize.
  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] INFO
  128. *> \verbatim
  129. *> INFO is INTEGER
  130. *> = 0: successful exit
  131. *> < 0: if INFO = -i, the i-th argument had an illegal value
  132. *> \endverbatim
  133. *
  134. * Authors:
  135. * ========
  136. *
  137. *> \author Univ. of Tennessee
  138. *> \author Univ. of California Berkeley
  139. *> \author Univ. of Colorado Denver
  140. *> \author NAG Ltd.
  141. *
  142. *> \ingroup hetrd
  143. *
  144. *> \par Further Details:
  145. * =====================
  146. *>
  147. *> \verbatim
  148. *>
  149. *> If UPLO = 'U', the matrix Q is represented as a product of elementary
  150. *> reflectors
  151. *>
  152. *> Q = H(n-1) . . . H(2) H(1).
  153. *>
  154. *> Each H(i) has the form
  155. *>
  156. *> H(i) = I - tau * v * v**H
  157. *>
  158. *> where tau is a complex scalar, and v is a complex vector with
  159. *> v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
  160. *> A(1:i-1,i+1), and tau in TAU(i).
  161. *>
  162. *> If UPLO = 'L', the matrix Q is represented as a product of elementary
  163. *> reflectors
  164. *>
  165. *> Q = H(1) H(2) . . . H(n-1).
  166. *>
  167. *> Each H(i) has the form
  168. *>
  169. *> H(i) = I - tau * v * v**H
  170. *>
  171. *> where tau is a complex scalar, and v is a complex vector with
  172. *> v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in A(i+2:n,i),
  173. *> and tau in TAU(i).
  174. *>
  175. *> The contents of A on exit are illustrated by the following examples
  176. *> with n = 5:
  177. *>
  178. *> if UPLO = 'U': if UPLO = 'L':
  179. *>
  180. *> ( d e v2 v3 v4 ) ( d )
  181. *> ( d e v3 v4 ) ( e d )
  182. *> ( d e v4 ) ( v1 e d )
  183. *> ( d e ) ( v1 v2 e d )
  184. *> ( d ) ( v1 v2 v3 e d )
  185. *>
  186. *> where d and e denote diagonal and off-diagonal elements of T, and vi
  187. *> denotes an element of the vector defining H(i).
  188. *> \endverbatim
  189. *>
  190. * =====================================================================
  191. SUBROUTINE CHETRD( UPLO, N, A, LDA, D, E, TAU, WORK, LWORK,
  192. $ INFO )
  193. *
  194. * -- LAPACK computational routine --
  195. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  196. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  197. *
  198. * .. Scalar Arguments ..
  199. CHARACTER UPLO
  200. INTEGER INFO, LDA, LWORK, N
  201. * ..
  202. * .. Array Arguments ..
  203. REAL D( * ), E( * )
  204. COMPLEX A( LDA, * ), TAU( * ), WORK( * )
  205. * ..
  206. *
  207. * =====================================================================
  208. *
  209. * .. Parameters ..
  210. REAL ONE
  211. PARAMETER ( ONE = 1.0E+0 )
  212. COMPLEX CONE
  213. PARAMETER ( CONE = ( 1.0E+0, 0.0E+0 ) )
  214. * ..
  215. * .. Local Scalars ..
  216. LOGICAL LQUERY, UPPER
  217. INTEGER I, IINFO, IWS, J, KK, LDWORK, LWKOPT, NB,
  218. $ NBMIN, NX
  219. * ..
  220. * .. External Subroutines ..
  221. EXTERNAL CHER2K, CHETD2, CLATRD, XERBLA
  222. * ..
  223. * .. Intrinsic Functions ..
  224. INTRINSIC MAX
  225. * ..
  226. * .. External Functions ..
  227. LOGICAL LSAME
  228. INTEGER ILAENV
  229. REAL SROUNDUP_LWORK
  230. EXTERNAL LSAME, ILAENV, SROUNDUP_LWORK
  231. * ..
  232. * .. Executable Statements ..
  233. *
  234. * Test the input parameters
  235. *
  236. INFO = 0
  237. UPPER = LSAME( UPLO, 'U' )
  238. LQUERY = ( LWORK.EQ.-1 )
  239. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  240. INFO = -1
  241. ELSE IF( N.LT.0 ) THEN
  242. INFO = -2
  243. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  244. INFO = -4
  245. ELSE IF( LWORK.LT.1 .AND. .NOT.LQUERY ) THEN
  246. INFO = -9
  247. END IF
  248. *
  249. IF( INFO.EQ.0 ) THEN
  250. *
  251. * Determine the block size.
  252. *
  253. NB = ILAENV( 1, 'CHETRD', UPLO, N, -1, -1, -1 )
  254. LWKOPT = MAX( 1, N*NB )
  255. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  256. END IF
  257. *
  258. IF( INFO.NE.0 ) THEN
  259. CALL XERBLA( 'CHETRD', -INFO )
  260. RETURN
  261. ELSE IF( LQUERY ) THEN
  262. RETURN
  263. END IF
  264. *
  265. * Quick return if possible
  266. *
  267. IF( N.EQ.0 ) THEN
  268. WORK( 1 ) = 1
  269. RETURN
  270. END IF
  271. *
  272. NX = N
  273. IWS = 1
  274. IF( NB.GT.1 .AND. NB.LT.N ) THEN
  275. *
  276. * Determine when to cross over from blocked to unblocked code
  277. * (last block is always handled by unblocked code).
  278. *
  279. NX = MAX( NB, ILAENV( 3, 'CHETRD', UPLO, N, -1, -1, -1 ) )
  280. IF( NX.LT.N ) THEN
  281. *
  282. * Determine if workspace is large enough for blocked code.
  283. *
  284. LDWORK = N
  285. IWS = LDWORK*NB
  286. IF( LWORK.LT.IWS ) THEN
  287. *
  288. * Not enough workspace to use optimal NB: determine the
  289. * minimum value of NB, and reduce NB or force use of
  290. * unblocked code by setting NX = N.
  291. *
  292. NB = MAX( LWORK / LDWORK, 1 )
  293. NBMIN = ILAENV( 2, 'CHETRD', UPLO, N, -1, -1, -1 )
  294. IF( NB.LT.NBMIN )
  295. $ NX = N
  296. END IF
  297. ELSE
  298. NX = N
  299. END IF
  300. ELSE
  301. NB = 1
  302. END IF
  303. *
  304. IF( UPPER ) THEN
  305. *
  306. * Reduce the upper triangle of A.
  307. * Columns 1:kk are handled by the unblocked method.
  308. *
  309. KK = N - ( ( N-NX+NB-1 ) / NB )*NB
  310. DO 20 I = N - NB + 1, KK + 1, -NB
  311. *
  312. * Reduce columns i:i+nb-1 to tridiagonal form and form the
  313. * matrix W which is needed to update the unreduced part of
  314. * the matrix
  315. *
  316. CALL CLATRD( UPLO, I+NB-1, NB, A, LDA, E, TAU, WORK,
  317. $ LDWORK )
  318. *
  319. * Update the unreduced submatrix A(1:i-1,1:i-1), using an
  320. * update of the form: A := A - V*W**H - W*V**H
  321. *
  322. CALL CHER2K( UPLO, 'No transpose', I-1, NB, -CONE,
  323. $ A( 1, I ), LDA, WORK, LDWORK, ONE, A, LDA )
  324. *
  325. * Copy superdiagonal elements back into A, and diagonal
  326. * elements into D
  327. *
  328. DO 10 J = I, I + NB - 1
  329. A( J-1, J ) = E( J-1 )
  330. D( J ) = REAL( A( J, J ) )
  331. 10 CONTINUE
  332. 20 CONTINUE
  333. *
  334. * Use unblocked code to reduce the last or only block
  335. *
  336. CALL CHETD2( UPLO, KK, A, LDA, D, E, TAU, IINFO )
  337. ELSE
  338. *
  339. * Reduce the lower triangle of A
  340. *
  341. DO 40 I = 1, N - NX, NB
  342. *
  343. * Reduce columns i:i+nb-1 to tridiagonal form and form the
  344. * matrix W which is needed to update the unreduced part of
  345. * the matrix
  346. *
  347. CALL CLATRD( UPLO, N-I+1, NB, A( I, I ), LDA, E( I ),
  348. $ TAU( I ), WORK, LDWORK )
  349. *
  350. * Update the unreduced submatrix A(i+nb:n,i+nb:n), using
  351. * an update of the form: A := A - V*W**H - W*V**H
  352. *
  353. CALL CHER2K( UPLO, 'No transpose', N-I-NB+1, NB, -CONE,
  354. $ A( I+NB, I ), LDA, WORK( NB+1 ), LDWORK, ONE,
  355. $ A( I+NB, I+NB ), LDA )
  356. *
  357. * Copy subdiagonal elements back into A, and diagonal
  358. * elements into D
  359. *
  360. DO 30 J = I, I + NB - 1
  361. A( J+1, J ) = E( J )
  362. D( J ) = REAL( A( J, J ) )
  363. 30 CONTINUE
  364. 40 CONTINUE
  365. *
  366. * Use unblocked code to reduce the last or only block
  367. *
  368. CALL CHETD2( UPLO, N-I+1, A( I, I ), LDA, D( I ), E( I ),
  369. $ TAU( I ), IINFO )
  370. END IF
  371. *
  372. WORK( 1 ) = SROUNDUP_LWORK(LWKOPT)
  373. RETURN
  374. *
  375. * End of CHETRD
  376. *
  377. END