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.

chetrf_aa.f 14 kB

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