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.

zhetrf_aa.f 14 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476
  1. *> \brief \b ZHETRF_AA
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZHETRF_AA + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zhetrf_aa.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zhetrf_aa.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zhetrf_aa.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZHETRF_AA( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER N, LDA, LWORK, INFO
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IPIV( * )
  29. * COMPLEX*16 A( LDA, * ), WORK( * )
  30. * ..
  31. *
  32. *> \par Purpose:
  33. * =============
  34. *>
  35. *> \verbatim
  36. *>
  37. *> ZHETRF_AA computes the factorization of a complex hermitian matrix A
  38. *> using the Aasen's algorithm. The form of the factorization is
  39. *>
  40. *> A = U**H*T*U or A = L*T*L**H
  41. *>
  42. *> where U (or L) is a product of permutation and unit upper (lower)
  43. *> triangular matrices, and T is a hermitian tridiagonal matrix.
  44. *>
  45. *> This is the blocked version of the algorithm, calling Level 3 BLAS.
  46. *> \endverbatim
  47. *
  48. * Arguments:
  49. * ==========
  50. *
  51. *> \param[in] UPLO
  52. *> \verbatim
  53. *> UPLO is CHARACTER*1
  54. *> = 'U': Upper triangle of A is stored;
  55. *> = 'L': Lower triangle of A is stored.
  56. *> \endverbatim
  57. *>
  58. *> \param[in] N
  59. *> \verbatim
  60. *> N is INTEGER
  61. *> The order of the matrix A. N >= 0.
  62. *> \endverbatim
  63. *>
  64. *> \param[in,out] A
  65. *> \verbatim
  66. *> A is COMPLEX*16 array, dimension (LDA,N)
  67. *> On entry, the hermitian matrix A. If UPLO = 'U', the leading
  68. *> N-by-N upper triangular part of A contains the upper
  69. *> triangular part of the matrix A, and the strictly lower
  70. *> triangular part of A is not referenced. If UPLO = 'L', the
  71. *> leading N-by-N lower triangular part of A contains the lower
  72. *> triangular part of the matrix A, and the strictly upper
  73. *> triangular part of A is not referenced.
  74. *>
  75. *> On exit, the tridiagonal matrix is stored in the diagonals
  76. *> and the subdiagonals of A just below (or above) the diagonals,
  77. *> and L is stored below (or above) the subdiagonals, when UPLO
  78. *> is 'L' (or 'U').
  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] IPIV
  88. *> \verbatim
  89. *> IPIV is INTEGER array, dimension (N)
  90. *> On exit, it contains the details of the interchanges, i.e.,
  91. *> the row and column k of A were interchanged with the
  92. *> row and column IPIV(k).
  93. *> \endverbatim
  94. *>
  95. *> \param[out] WORK
  96. *> \verbatim
  97. *> WORK is COMPLEX*16 array, dimension (MAX(1,LWORK))
  98. *> On exit, if INFO = 0, WORK(1) returns the optimal LWORK.
  99. *> \endverbatim
  100. *>
  101. *> \param[in] LWORK
  102. *> \verbatim
  103. *> LWORK is INTEGER
  104. *> The length of WORK.
  105. *> LWORK >= 1, if N >= 1, and LWORK >= 2*N, otherwise.
  106. *> For optimum performance LWORK >= N*(1+NB), where NB is
  107. *> the optimal blocksize, returned by ILAENV.
  108. *>
  109. *> If LWORK = -1, then a workspace query is assumed; the routine
  110. *> only calculates the optimal size of the WORK array, returns
  111. *> this value as the first entry of the WORK array, and no error
  112. *> message related to LWORK is issued by XERBLA.
  113. *> \endverbatim
  114. *>
  115. *> \param[out] INFO
  116. *> \verbatim
  117. *> INFO is INTEGER
  118. *> = 0: successful exit
  119. *> < 0: if INFO = -i, the i-th argument had an illegal value.
  120. *> \endverbatim
  121. *
  122. * Authors:
  123. * ========
  124. *
  125. *> \author Univ. of Tennessee
  126. *> \author Univ. of California Berkeley
  127. *> \author Univ. of Colorado Denver
  128. *> \author NAG Ltd.
  129. *
  130. *> \ingroup hetrf_aa
  131. *
  132. * =====================================================================
  133. SUBROUTINE ZHETRF_AA( UPLO, N, A, LDA, IPIV, WORK, LWORK, INFO )
  134. *
  135. * -- LAPACK computational routine --
  136. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  137. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  138. *
  139. IMPLICIT NONE
  140. *
  141. * .. Scalar Arguments ..
  142. CHARACTER UPLO
  143. INTEGER N, LDA, LWORK, INFO
  144. * ..
  145. * .. Array Arguments ..
  146. INTEGER IPIV( * )
  147. COMPLEX*16 A( LDA, * ), WORK( * )
  148. * ..
  149. *
  150. * =====================================================================
  151. * .. Parameters ..
  152. COMPLEX*16 ZERO, ONE
  153. PARAMETER ( ZERO = (0.0D+0, 0.0D+0), ONE = (1.0D+0, 0.0D+0) )
  154. *
  155. * .. Local Scalars ..
  156. LOGICAL LQUERY, UPPER
  157. INTEGER J, LWKMIN, LWKOPT
  158. INTEGER NB, MJ, NJ, K1, K2, J1, J2, J3, JB
  159. COMPLEX*16 ALPHA
  160. * ..
  161. * .. External Functions ..
  162. LOGICAL LSAME
  163. INTEGER ILAENV
  164. EXTERNAL LSAME, ILAENV
  165. * ..
  166. * .. External Subroutines ..
  167. EXTERNAL ZLAHEF_AA, ZGEMM, ZGEMV, ZCOPY, ZSCAL, ZSWAP, XERBLA
  168. * ..
  169. * .. Intrinsic Functions ..
  170. INTRINSIC DBLE, DCONJG, MAX
  171. * ..
  172. * .. Executable Statements ..
  173. *
  174. * Determine the block size
  175. *
  176. NB = ILAENV( 1, 'ZHETRF_AA', UPLO, N, -1, -1, -1 )
  177. *
  178. * Test the input parameters.
  179. *
  180. INFO = 0
  181. UPPER = LSAME( UPLO, 'U' )
  182. LQUERY = ( LWORK.EQ.-1 )
  183. IF( N.LE.1 ) THEN
  184. LWKMIN = 1
  185. LWKOPT = 1
  186. ELSE
  187. LWKMIN = 2*N
  188. LWKOPT = (NB+1)*N
  189. END IF
  190. *
  191. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  192. INFO = -1
  193. ELSE IF( N.LT.0 ) THEN
  194. INFO = -2
  195. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  196. INFO = -4
  197. ELSE IF( LWORK.LT.LWKMIN .AND. .NOT.LQUERY ) THEN
  198. INFO = -7
  199. END IF
  200. *
  201. IF( INFO.EQ.0 ) THEN
  202. WORK( 1 ) = LWKOPT
  203. END IF
  204. *
  205. IF( INFO.NE.0 ) THEN
  206. CALL XERBLA( 'ZHETRF_AA', -INFO )
  207. RETURN
  208. ELSE IF( LQUERY ) THEN
  209. RETURN
  210. END IF
  211. *
  212. * Quick return
  213. *
  214. IF( N.EQ.0 ) THEN
  215. RETURN
  216. ENDIF
  217. IPIV( 1 ) = 1
  218. IF( N.EQ.1 ) THEN
  219. A( 1, 1 ) = DBLE( A( 1, 1 ) )
  220. RETURN
  221. END IF
  222. *
  223. * Adjust block size based on the workspace size
  224. *
  225. IF( LWORK.LT.((1+NB)*N) ) THEN
  226. NB = ( LWORK-N ) / N
  227. END IF
  228. *
  229. IF( UPPER ) THEN
  230. *
  231. * .....................................................
  232. * Factorize A as U**H*D*U using the upper triangle of A
  233. * .....................................................
  234. *
  235. * copy first row A(1, 1:N) into H(1:n) (stored in WORK(1:N))
  236. *
  237. CALL ZCOPY( N, A( 1, 1 ), LDA, WORK( 1 ), 1 )
  238. *
  239. * J is the main loop index, increasing from 1 to N in steps of
  240. * JB, where JB is the number of columns factorized by ZLAHEF;
  241. * JB is either NB, or N-J+1 for the last block
  242. *
  243. J = 0
  244. 10 CONTINUE
  245. IF( J.GE.N )
  246. $ GO TO 20
  247. *
  248. * each step of the main loop
  249. * J is the last column of the previous panel
  250. * J1 is the first column of the current panel
  251. * K1 identifies if the previous column of the panel has been
  252. * explicitly stored, e.g., K1=1 for the first panel, and
  253. * K1=0 for the rest
  254. *
  255. J1 = J + 1
  256. JB = MIN( N-J1+1, NB )
  257. K1 = MAX(1, J)-J
  258. *
  259. * Panel factorization
  260. *
  261. CALL ZLAHEF_AA( UPLO, 2-K1, N-J, JB,
  262. $ A( MAX(1, J), J+1 ), LDA,
  263. $ IPIV( J+1 ), WORK, N, WORK( N*NB+1 ) )
  264. *
  265. * Adjust IPIV and apply it back (J-th step picks (J+1)-th pivot)
  266. *
  267. DO J2 = J+2, MIN(N, J+JB+1)
  268. IPIV( J2 ) = IPIV( J2 ) + J
  269. IF( (J2.NE.IPIV(J2)) .AND. ((J1-K1).GT.2) ) THEN
  270. CALL ZSWAP( J1-K1-2, A( 1, J2 ), 1,
  271. $ A( 1, IPIV(J2) ), 1 )
  272. END IF
  273. END DO
  274. J = J + JB
  275. *
  276. * Trailing submatrix update, where
  277. * the row A(J1-1, J2-1:N) stores U(J1, J2+1:N) and
  278. * WORK stores the current block of the auxiriarly matrix H
  279. *
  280. IF( J.LT.N ) THEN
  281. *
  282. * if the first panel and JB=1 (NB=1), then nothing to do
  283. *
  284. IF( J1.GT.1 .OR. JB.GT.1 ) THEN
  285. *
  286. * Merge rank-1 update with BLAS-3 update
  287. *
  288. ALPHA = DCONJG( A( J, J+1 ) )
  289. A( J, J+1 ) = ONE
  290. CALL ZCOPY( N-J, A( J-1, J+1 ), LDA,
  291. $ WORK( (J+1-J1+1)+JB*N ), 1 )
  292. CALL ZSCAL( N-J, ALPHA, WORK( (J+1-J1+1)+JB*N ), 1 )
  293. *
  294. * K1 identifies if the previous column of the panel has been
  295. * explicitly stored, e.g., K1=0 and K2=1 for the first panel,
  296. * and K1=1 and K2=0 for the rest
  297. *
  298. IF( J1.GT.1 ) THEN
  299. *
  300. * Not first panel
  301. *
  302. K2 = 1
  303. ELSE
  304. *
  305. * First panel
  306. *
  307. K2 = 0
  308. *
  309. * First update skips the first column
  310. *
  311. JB = JB - 1
  312. END IF
  313. *
  314. DO J2 = J+1, N, NB
  315. NJ = MIN( NB, N-J2+1 )
  316. *
  317. * Update (J2, J2) diagonal block with ZGEMV
  318. *
  319. J3 = J2
  320. DO MJ = NJ-1, 1, -1
  321. CALL ZGEMM( 'Conjugate transpose', 'Transpose',
  322. $ 1, MJ, JB+1,
  323. $ -ONE, A( J1-K2, J3 ), LDA,
  324. $ WORK( (J3-J1+1)+K1*N ), N,
  325. $ ONE, A( J3, J3 ), LDA )
  326. J3 = J3 + 1
  327. END DO
  328. *
  329. * Update off-diagonal block of J2-th block row with ZGEMM
  330. *
  331. CALL ZGEMM( 'Conjugate transpose', 'Transpose',
  332. $ NJ, N-J3+1, JB+1,
  333. $ -ONE, A( J1-K2, J2 ), LDA,
  334. $ WORK( (J3-J1+1)+K1*N ), N,
  335. $ ONE, A( J2, J3 ), LDA )
  336. END DO
  337. *
  338. * Recover T( J, J+1 )
  339. *
  340. A( J, J+1 ) = DCONJG( ALPHA )
  341. END IF
  342. *
  343. * WORK(J+1, 1) stores H(J+1, 1)
  344. *
  345. CALL ZCOPY( N-J, A( J+1, J+1 ), LDA, WORK( 1 ), 1 )
  346. END IF
  347. GO TO 10
  348. ELSE
  349. *
  350. * .....................................................
  351. * Factorize A as L*D*L**H using the lower triangle of A
  352. * .....................................................
  353. *
  354. * copy first column A(1:N, 1) into H(1:N, 1)
  355. * (stored in WORK(1:N))
  356. *
  357. CALL ZCOPY( N, A( 1, 1 ), 1, WORK( 1 ), 1 )
  358. *
  359. * J is the main loop index, increasing from 1 to N in steps of
  360. * JB, where JB is the number of columns factorized by ZLAHEF;
  361. * JB is either NB, or N-J+1 for the last block
  362. *
  363. J = 0
  364. 11 CONTINUE
  365. IF( J.GE.N )
  366. $ GO TO 20
  367. *
  368. * each step of the main loop
  369. * J is the last column of the previous panel
  370. * J1 is the first column of the current panel
  371. * K1 identifies if the previous column of the panel has been
  372. * explicitly stored, e.g., K1=1 for the first panel, and
  373. * K1=0 for the rest
  374. *
  375. J1 = J+1
  376. JB = MIN( N-J1+1, NB )
  377. K1 = MAX(1, J)-J
  378. *
  379. * Panel factorization
  380. *
  381. CALL ZLAHEF_AA( UPLO, 2-K1, N-J, JB,
  382. $ A( J+1, MAX(1, J) ), LDA,
  383. $ IPIV( J+1 ), WORK, N, WORK( N*NB+1 ) )
  384. *
  385. * Adjust IPIV and apply it back (J-th step picks (J+1)-th pivot)
  386. *
  387. DO J2 = J+2, MIN(N, J+JB+1)
  388. IPIV( J2 ) = IPIV( J2 ) + J
  389. IF( (J2.NE.IPIV(J2)) .AND. ((J1-K1).GT.2) ) THEN
  390. CALL ZSWAP( J1-K1-2, A( J2, 1 ), LDA,
  391. $ A( IPIV(J2), 1 ), LDA )
  392. END IF
  393. END DO
  394. J = J + JB
  395. *
  396. * Trailing submatrix update, where
  397. * A(J2+1, J1-1) stores L(J2+1, J1) and
  398. * WORK(J2+1, 1) stores H(J2+1, 1)
  399. *
  400. IF( J.LT.N ) THEN
  401. *
  402. * if the first panel and JB=1 (NB=1), then nothing to do
  403. *
  404. IF( J1.GT.1 .OR. JB.GT.1 ) THEN
  405. *
  406. * Merge rank-1 update with BLAS-3 update
  407. *
  408. ALPHA = DCONJG( A( J+1, J ) )
  409. A( J+1, J ) = ONE
  410. CALL ZCOPY( N-J, A( J+1, J-1 ), 1,
  411. $ WORK( (J+1-J1+1)+JB*N ), 1 )
  412. CALL ZSCAL( N-J, ALPHA, WORK( (J+1-J1+1)+JB*N ), 1 )
  413. *
  414. * K1 identifies if the previous column of the panel has been
  415. * explicitly stored, e.g., K1=0 and K2=1 for the first panel,
  416. * and K1=1 and K2=0 for the rest
  417. *
  418. IF( J1.GT.1 ) THEN
  419. *
  420. * Not first panel
  421. *
  422. K2 = 1
  423. ELSE
  424. *
  425. * First panel
  426. *
  427. K2 = 0
  428. *
  429. * First update skips the first column
  430. *
  431. JB = JB - 1
  432. END IF
  433. *
  434. DO J2 = J+1, N, NB
  435. NJ = MIN( NB, N-J2+1 )
  436. *
  437. * Update (J2, J2) diagonal block with ZGEMV
  438. *
  439. J3 = J2
  440. DO MJ = NJ-1, 1, -1
  441. CALL ZGEMM( 'No transpose', 'Conjugate transpose',
  442. $ MJ, 1, JB+1,
  443. $ -ONE, WORK( (J3-J1+1)+K1*N ), N,
  444. $ A( J3, J1-K2 ), LDA,
  445. $ ONE, A( J3, J3 ), LDA )
  446. J3 = J3 + 1
  447. END DO
  448. *
  449. * Update off-diagonal block of J2-th block column with ZGEMM
  450. *
  451. CALL ZGEMM( 'No transpose', 'Conjugate transpose',
  452. $ N-J3+1, NJ, JB+1,
  453. $ -ONE, WORK( (J3-J1+1)+K1*N ), N,
  454. $ A( J2, J1-K2 ), LDA,
  455. $ ONE, A( J3, J2 ), LDA )
  456. END DO
  457. *
  458. * Recover T( J+1, J )
  459. *
  460. A( J+1, J ) = DCONJG( ALPHA )
  461. END IF
  462. *
  463. * WORK(J+1, 1) stores H(J+1, 1)
  464. *
  465. CALL ZCOPY( N-J, A( J+1, J+1 ), 1, WORK( 1 ), 1 )
  466. END IF
  467. GO TO 11
  468. END IF
  469. *
  470. 20 CONTINUE
  471. WORK( 1 ) = LWKOPT
  472. RETURN
  473. *
  474. * End of ZHETRF_AA
  475. *
  476. END