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.

zlahef.f 32 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969
  1. *> \brief \b ZLAHEF computes a partial factorization of a complex Hermitian indefinite matrix using the Bunch-Kaufman diagonal pivoting method (blocked algorithm, calling Level 3 BLAS).
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZLAHEF + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZLAHEF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
  22. *
  23. * .. Scalar Arguments ..
  24. * CHARACTER UPLO
  25. * INTEGER INFO, KB, LDA, LDW, N, NB
  26. * ..
  27. * .. Array Arguments ..
  28. * INTEGER IPIV( * )
  29. * COMPLEX*16 A( LDA, * ), W( LDW, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> ZLAHEF computes a partial factorization of a complex Hermitian
  39. *> matrix A using the Bunch-Kaufman diagonal pivoting method. The
  40. *> partial factorization has the form:
  41. *>
  42. *> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or:
  43. *> ( 0 U22 ) ( 0 D ) ( U12**H U22**H )
  44. *>
  45. *> A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) if UPLO = 'L'
  46. *> ( L21 I ) ( 0 A22 ) ( 0 I )
  47. *>
  48. *> where the order of D is at most NB. The actual order is returned in
  49. *> the argument KB, and is either NB or NB-1, or N if N <= NB.
  50. *> Note that U**H denotes the conjugate transpose of U.
  51. *>
  52. *> ZLAHEF is an auxiliary routine called by ZHETRF. It uses blocked code
  53. *> (calling Level 3 BLAS) to update the submatrix A11 (if UPLO = 'U') or
  54. *> A22 (if UPLO = 'L').
  55. *> \endverbatim
  56. *
  57. * Arguments:
  58. * ==========
  59. *
  60. *> \param[in] UPLO
  61. *> \verbatim
  62. *> UPLO is CHARACTER*1
  63. *> Specifies whether the upper or lower triangular part of the
  64. *> Hermitian matrix A is stored:
  65. *> = 'U': Upper triangular
  66. *> = 'L': Lower triangular
  67. *> \endverbatim
  68. *>
  69. *> \param[in] N
  70. *> \verbatim
  71. *> N is INTEGER
  72. *> The order of the matrix A. N >= 0.
  73. *> \endverbatim
  74. *>
  75. *> \param[in] NB
  76. *> \verbatim
  77. *> NB is INTEGER
  78. *> The maximum number of columns of the matrix A that should be
  79. *> factored. NB should be at least 2 to allow for 2-by-2 pivot
  80. *> blocks.
  81. *> \endverbatim
  82. *>
  83. *> \param[out] KB
  84. *> \verbatim
  85. *> KB is INTEGER
  86. *> The number of columns of A that were actually factored.
  87. *> KB is either NB-1 or NB, or N if N <= NB.
  88. *> \endverbatim
  89. *>
  90. *> \param[in,out] A
  91. *> \verbatim
  92. *> A is COMPLEX*16 array, dimension (LDA,N)
  93. *> On entry, the Hermitian matrix A. If UPLO = 'U', the leading
  94. *> n-by-n upper triangular part of A contains the upper
  95. *> triangular part of the matrix A, and the strictly lower
  96. *> triangular part of A is not referenced. If UPLO = 'L', the
  97. *> leading n-by-n lower triangular part of A contains the lower
  98. *> triangular part of the matrix A, and the strictly upper
  99. *> triangular part of A is not referenced.
  100. *> On exit, A contains details of the partial factorization.
  101. *> \endverbatim
  102. *>
  103. *> \param[in] LDA
  104. *> \verbatim
  105. *> LDA is INTEGER
  106. *> The leading dimension of the array A. LDA >= max(1,N).
  107. *> \endverbatim
  108. *>
  109. *> \param[out] IPIV
  110. *> \verbatim
  111. *> IPIV is INTEGER array, dimension (N)
  112. *> Details of the interchanges and the block structure of D.
  113. *>
  114. *> If UPLO = 'U':
  115. *> Only the last KB elements of IPIV are set.
  116. *>
  117. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  118. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  119. *>
  120. *> If IPIV(k) = IPIV(k-1) < 0, then rows and columns
  121. *> k-1 and -IPIV(k) were interchanged and D(k-1:k,k-1:k)
  122. *> is a 2-by-2 diagonal block.
  123. *>
  124. *> If UPLO = 'L':
  125. *> Only the first KB elements of IPIV are set.
  126. *>
  127. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  128. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  129. *>
  130. *> If IPIV(k) = IPIV(k+1) < 0, then rows and columns
  131. *> k+1 and -IPIV(k) were interchanged and D(k:k+1,k:k+1)
  132. *> is a 2-by-2 diagonal block.
  133. *> \endverbatim
  134. *>
  135. *> \param[out] W
  136. *> \verbatim
  137. *> W is COMPLEX*16 array, dimension (LDW,NB)
  138. *> \endverbatim
  139. *>
  140. *> \param[in] LDW
  141. *> \verbatim
  142. *> LDW is INTEGER
  143. *> The leading dimension of the array W. LDW >= max(1,N).
  144. *> \endverbatim
  145. *>
  146. *> \param[out] INFO
  147. *> \verbatim
  148. *> INFO is INTEGER
  149. *> = 0: successful exit
  150. *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
  151. *> has been completed, but the block diagonal matrix D is
  152. *> exactly singular.
  153. *> \endverbatim
  154. *
  155. * Authors:
  156. * ========
  157. *
  158. *> \author Univ. of Tennessee
  159. *> \author Univ. of California Berkeley
  160. *> \author Univ. of Colorado Denver
  161. *> \author NAG Ltd.
  162. *
  163. *> \ingroup complex16HEcomputational
  164. *
  165. *> \par Contributors:
  166. * ==================
  167. *>
  168. *> \verbatim
  169. *>
  170. *> December 2016, Igor Kozachenko,
  171. *> Computer Science Division,
  172. *> University of California, Berkeley
  173. *> \endverbatim
  174. *
  175. * =====================================================================
  176. SUBROUTINE ZLAHEF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
  177. *
  178. * -- LAPACK computational routine --
  179. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  180. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  181. *
  182. * .. Scalar Arguments ..
  183. CHARACTER UPLO
  184. INTEGER INFO, KB, LDA, LDW, N, NB
  185. * ..
  186. * .. Array Arguments ..
  187. INTEGER IPIV( * )
  188. COMPLEX*16 A( LDA, * ), W( LDW, * )
  189. * ..
  190. *
  191. * =====================================================================
  192. *
  193. * .. Parameters ..
  194. DOUBLE PRECISION ZERO, ONE
  195. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  196. COMPLEX*16 CONE
  197. PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
  198. DOUBLE PRECISION EIGHT, SEVTEN
  199. PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
  200. * ..
  201. * .. Local Scalars ..
  202. INTEGER IMAX, J, JB, JJ, JMAX, JP, K, KK, KKW, KP,
  203. $ KSTEP, KW
  204. DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, R1, ROWMAX, T
  205. COMPLEX*16 D11, D21, D22, Z
  206. * ..
  207. * .. External Functions ..
  208. LOGICAL LSAME
  209. INTEGER IZAMAX
  210. EXTERNAL LSAME, IZAMAX
  211. * ..
  212. * .. External Subroutines ..
  213. EXTERNAL ZCOPY, ZDSCAL, ZGEMM, ZGEMV, ZLACGV, ZSWAP
  214. * ..
  215. * .. Intrinsic Functions ..
  216. INTRINSIC ABS, DBLE, DCONJG, DIMAG, MAX, MIN, SQRT
  217. * ..
  218. * .. Statement Functions ..
  219. DOUBLE PRECISION CABS1
  220. * ..
  221. * .. Statement Function definitions ..
  222. CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
  223. * ..
  224. * .. Executable Statements ..
  225. *
  226. INFO = 0
  227. *
  228. * Initialize ALPHA for use in choosing pivot block size.
  229. *
  230. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  231. *
  232. IF( LSAME( UPLO, 'U' ) ) THEN
  233. *
  234. * Factorize the trailing columns of A using the upper triangle
  235. * of A and working backwards, and compute the matrix W = U12*D
  236. * for use in updating A11 (note that conjg(W) is actually stored)
  237. *
  238. * K is the main loop index, decreasing from N in steps of 1 or 2
  239. *
  240. * KW is the column of W which corresponds to column K of A
  241. *
  242. K = N
  243. 10 CONTINUE
  244. KW = NB + K - N
  245. *
  246. * Exit from loop
  247. *
  248. IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
  249. $ GO TO 30
  250. *
  251. KSTEP = 1
  252. *
  253. * Copy column K of A to column KW of W and update it
  254. *
  255. CALL ZCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 )
  256. W( K, KW ) = DBLE( A( K, K ) )
  257. IF( K.LT.N ) THEN
  258. CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
  259. $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
  260. W( K, KW ) = DBLE( W( K, KW ) )
  261. END IF
  262. *
  263. * Determine rows and columns to be interchanged and whether
  264. * a 1-by-1 or 2-by-2 pivot block will be used
  265. *
  266. ABSAKK = ABS( DBLE( W( K, KW ) ) )
  267. *
  268. * IMAX is the row-index of the largest off-diagonal element in
  269. * column K, and COLMAX is its absolute value.
  270. * Determine both COLMAX and IMAX.
  271. *
  272. IF( K.GT.1 ) THEN
  273. IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
  274. COLMAX = CABS1( W( IMAX, KW ) )
  275. ELSE
  276. COLMAX = ZERO
  277. END IF
  278. *
  279. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  280. *
  281. * Column K is zero or underflow: set INFO and continue
  282. *
  283. IF( INFO.EQ.0 )
  284. $ INFO = K
  285. KP = K
  286. A( K, K ) = DBLE( A( K, K ) )
  287. ELSE
  288. *
  289. * ============================================================
  290. *
  291. * BEGIN pivot search
  292. *
  293. * Case(1)
  294. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  295. *
  296. * no interchange, use 1-by-1 pivot block
  297. *
  298. KP = K
  299. ELSE
  300. *
  301. * BEGIN pivot search along IMAX row
  302. *
  303. *
  304. * Copy column IMAX to column KW-1 of W and update it
  305. *
  306. CALL ZCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
  307. W( IMAX, KW-1 ) = DBLE( A( IMAX, IMAX ) )
  308. CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
  309. $ W( IMAX+1, KW-1 ), 1 )
  310. CALL ZLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 )
  311. IF( K.LT.N ) THEN
  312. CALL ZGEMV( 'No transpose', K, N-K, -CONE,
  313. $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
  314. $ CONE, W( 1, KW-1 ), 1 )
  315. W( IMAX, KW-1 ) = DBLE( W( IMAX, KW-1 ) )
  316. END IF
  317. *
  318. * JMAX is the column-index of the largest off-diagonal
  319. * element in row IMAX, and ROWMAX is its absolute value.
  320. * Determine only ROWMAX.
  321. *
  322. JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ), 1 )
  323. ROWMAX = CABS1( W( JMAX, KW-1 ) )
  324. IF( IMAX.GT.1 ) THEN
  325. JMAX = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
  326. ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, KW-1 ) ) )
  327. END IF
  328. *
  329. * Case(2)
  330. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  331. *
  332. * no interchange, use 1-by-1 pivot block
  333. *
  334. KP = K
  335. *
  336. * Case(3)
  337. ELSE IF( ABS( DBLE( W( IMAX, KW-1 ) ) ).GE.ALPHA*ROWMAX )
  338. $ THEN
  339. *
  340. * interchange rows and columns K and IMAX, use 1-by-1
  341. * pivot block
  342. *
  343. KP = IMAX
  344. *
  345. * copy column KW-1 of W to column KW of W
  346. *
  347. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  348. *
  349. * Case(4)
  350. ELSE
  351. *
  352. * interchange rows and columns K-1 and IMAX, use 2-by-2
  353. * pivot block
  354. *
  355. KP = IMAX
  356. KSTEP = 2
  357. END IF
  358. *
  359. *
  360. * END pivot search along IMAX row
  361. *
  362. END IF
  363. *
  364. * END pivot search
  365. *
  366. * ============================================================
  367. *
  368. * KK is the column of A where pivoting step stopped
  369. *
  370. KK = K - KSTEP + 1
  371. *
  372. * KKW is the column of W which corresponds to column KK of A
  373. *
  374. KKW = NB + KK - N
  375. *
  376. * Interchange rows and columns KP and KK.
  377. * Updated column KP is already stored in column KKW of W.
  378. *
  379. IF( KP.NE.KK ) THEN
  380. *
  381. * Copy non-updated column KK to column KP of submatrix A
  382. * at step K. No need to copy element into column K
  383. * (or K and K-1 for 2-by-2 pivot) of A, since these columns
  384. * will be later overwritten.
  385. *
  386. A( KP, KP ) = DBLE( A( KK, KK ) )
  387. CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
  388. $ LDA )
  389. CALL ZLACGV( KK-1-KP, A( KP, KP+1 ), LDA )
  390. IF( KP.GT.1 )
  391. $ CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
  392. *
  393. * Interchange rows KK and KP in last K+1 to N columns of A
  394. * (columns K (or K and K-1 for 2-by-2 pivot) of A will be
  395. * later overwritten). Interchange rows KK and KP
  396. * in last KKW to NB columns of W.
  397. *
  398. IF( K.LT.N )
  399. $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
  400. $ LDA )
  401. CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
  402. $ LDW )
  403. END IF
  404. *
  405. IF( KSTEP.EQ.1 ) THEN
  406. *
  407. * 1-by-1 pivot block D(k): column kw of W now holds
  408. *
  409. * W(kw) = U(k)*D(k),
  410. *
  411. * where U(k) is the k-th column of U
  412. *
  413. * (1) Store subdiag. elements of column U(k)
  414. * and 1-by-1 block D(k) in column k of A.
  415. * (NOTE: Diagonal element U(k,k) is a UNIT element
  416. * and not stored)
  417. * A(k,k) := D(k,k) = W(k,kw)
  418. * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
  419. *
  420. * (NOTE: No need to use for Hermitian matrix
  421. * A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal
  422. * element D(k,k) from W (potentially saves only one load))
  423. CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  424. IF( K.GT.1 ) THEN
  425. *
  426. * (NOTE: No need to check if A(k,k) is NOT ZERO,
  427. * since that was ensured earlier in pivot search:
  428. * case A(k,k) = 0 falls into 2x2 pivot case(4))
  429. *
  430. R1 = ONE / DBLE( A( K, K ) )
  431. CALL ZDSCAL( K-1, R1, A( 1, K ), 1 )
  432. *
  433. * (2) Conjugate column W(kw)
  434. *
  435. CALL ZLACGV( K-1, W( 1, KW ), 1 )
  436. END IF
  437. *
  438. ELSE
  439. *
  440. * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
  441. *
  442. * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
  443. *
  444. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  445. * of U
  446. *
  447. * (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
  448. * block D(k-1:k,k-1:k) in columns k-1 and k of A.
  449. * (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
  450. * block and not stored)
  451. * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
  452. * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
  453. * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
  454. *
  455. IF( K.GT.2 ) THEN
  456. *
  457. * Factor out the columns of the inverse of 2-by-2 pivot
  458. * block D, so that each column contains 1, to reduce the
  459. * number of FLOPS when we multiply panel
  460. * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
  461. *
  462. * D**(-1) = ( d11 cj(d21) )**(-1) =
  463. * ( d21 d22 )
  464. *
  465. * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
  466. * ( (-d21) ( d11 ) )
  467. *
  468. * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
  469. *
  470. * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
  471. * ( ( -1 ) ( d11/conj(d21) ) )
  472. *
  473. * = 1/(|d21|**2) * 1/(D22*D11-1) *
  474. *
  475. * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  476. * ( ( -1 ) ( D22 ) )
  477. *
  478. * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  479. * ( ( -1 ) ( D22 ) )
  480. *
  481. * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
  482. * ( ( -1 ) ( D22 ) )
  483. *
  484. * = ( conj(D21)*( D11 ) D21*( -1 ) )
  485. * ( ( -1 ) ( D22 ) ),
  486. *
  487. * where D11 = d22/d21,
  488. * D22 = d11/conj(d21),
  489. * D21 = T/d21,
  490. * T = 1/(D22*D11-1).
  491. *
  492. * (NOTE: No need to check for division by ZERO,
  493. * since that was ensured earlier in pivot search:
  494. * (a) d21 != 0, since in 2x2 pivot case(4)
  495. * |d21| should be larger than |d11| and |d22|;
  496. * (b) (D22*D11 - 1) != 0, since from (a),
  497. * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
  498. *
  499. D21 = W( K-1, KW )
  500. D11 = W( K, KW ) / DCONJG( D21 )
  501. D22 = W( K-1, KW-1 ) / D21
  502. T = ONE / ( DBLE( D11*D22 )-ONE )
  503. D21 = T / D21
  504. *
  505. * Update elements in columns A(k-1) and A(k) as
  506. * dot products of rows of ( W(kw-1) W(kw) ) and columns
  507. * of D**(-1)
  508. *
  509. DO 20 J = 1, K - 2
  510. A( J, K-1 ) = D21*( D11*W( J, KW-1 )-W( J, KW ) )
  511. A( J, K ) = DCONJG( D21 )*
  512. $ ( D22*W( J, KW )-W( J, KW-1 ) )
  513. 20 CONTINUE
  514. END IF
  515. *
  516. * Copy D(k) to A
  517. *
  518. A( K-1, K-1 ) = W( K-1, KW-1 )
  519. A( K-1, K ) = W( K-1, KW )
  520. A( K, K ) = W( K, KW )
  521. *
  522. * (2) Conjugate columns W(kw) and W(kw-1)
  523. *
  524. CALL ZLACGV( K-1, W( 1, KW ), 1 )
  525. CALL ZLACGV( K-2, W( 1, KW-1 ), 1 )
  526. *
  527. END IF
  528. *
  529. END IF
  530. *
  531. * Store details of the interchanges in IPIV
  532. *
  533. IF( KSTEP.EQ.1 ) THEN
  534. IPIV( K ) = KP
  535. ELSE
  536. IPIV( K ) = -KP
  537. IPIV( K-1 ) = -KP
  538. END IF
  539. *
  540. * Decrease K and return to the start of the main loop
  541. *
  542. K = K - KSTEP
  543. GO TO 10
  544. *
  545. 30 CONTINUE
  546. *
  547. * Update the upper triangle of A11 (= A(1:k,1:k)) as
  548. *
  549. * A11 := A11 - U12*D*U12**H = A11 - U12*W**H
  550. *
  551. * computing blocks of NB columns at a time (note that conjg(W) is
  552. * actually stored)
  553. *
  554. DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
  555. JB = MIN( NB, K-J+1 )
  556. *
  557. * Update the upper triangle of the diagonal block
  558. *
  559. DO 40 JJ = J, J + JB - 1
  560. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  561. CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
  562. $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
  563. $ A( J, JJ ), 1 )
  564. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  565. 40 CONTINUE
  566. *
  567. * Update the rectangular superdiagonal block
  568. *
  569. CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
  570. $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
  571. $ CONE, A( 1, J ), LDA )
  572. 50 CONTINUE
  573. *
  574. * Put U12 in standard form by partially undoing the interchanges
  575. * in columns k+1:n looping backwards from k+1 to n
  576. *
  577. J = K + 1
  578. 60 CONTINUE
  579. *
  580. * Undo the interchanges (if any) of rows JJ and JP at each
  581. * step J
  582. *
  583. * (Here, J is a diagonal index)
  584. JJ = J
  585. JP = IPIV( J )
  586. IF( JP.LT.0 ) THEN
  587. JP = -JP
  588. * (Here, J is a diagonal index)
  589. J = J + 1
  590. END IF
  591. * (NOTE: Here, J is used to determine row length. Length N-J+1
  592. * of the rows to swap back doesn't include diagonal element)
  593. J = J + 1
  594. IF( JP.NE.JJ .AND. J.LE.N )
  595. $ CALL ZSWAP( N-J+1, A( JP, J ), LDA, A( JJ, J ), LDA )
  596. IF( J.LT.N )
  597. $ GO TO 60
  598. *
  599. * Set KB to the number of columns factorized
  600. *
  601. KB = N - K
  602. *
  603. ELSE
  604. *
  605. * Factorize the leading columns of A using the lower triangle
  606. * of A and working forwards, and compute the matrix W = L21*D
  607. * for use in updating A22 (note that conjg(W) is actually stored)
  608. *
  609. * K is the main loop index, increasing from 1 in steps of 1 or 2
  610. *
  611. K = 1
  612. 70 CONTINUE
  613. *
  614. * Exit from loop
  615. *
  616. IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
  617. $ GO TO 90
  618. *
  619. KSTEP = 1
  620. *
  621. * Copy column K of A to column K of W and update it
  622. *
  623. W( K, K ) = DBLE( A( K, K ) )
  624. IF( K.LT.N )
  625. $ CALL ZCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
  626. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), LDA,
  627. $ W( K, 1 ), LDW, CONE, W( K, K ), 1 )
  628. W( K, K ) = DBLE( W( K, K ) )
  629. *
  630. * Determine rows and columns to be interchanged and whether
  631. * a 1-by-1 or 2-by-2 pivot block will be used
  632. *
  633. ABSAKK = ABS( DBLE( W( K, K ) ) )
  634. *
  635. * IMAX is the row-index of the largest off-diagonal element in
  636. * column K, and COLMAX is its absolute value.
  637. * Determine both COLMAX and IMAX.
  638. *
  639. IF( K.LT.N ) THEN
  640. IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
  641. COLMAX = CABS1( W( IMAX, K ) )
  642. ELSE
  643. COLMAX = ZERO
  644. END IF
  645. *
  646. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  647. *
  648. * Column K is zero or underflow: set INFO and continue
  649. *
  650. IF( INFO.EQ.0 )
  651. $ INFO = K
  652. KP = K
  653. A( K, K ) = DBLE( A( K, K ) )
  654. ELSE
  655. *
  656. * ============================================================
  657. *
  658. * BEGIN pivot search
  659. *
  660. * Case(1)
  661. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  662. *
  663. * no interchange, use 1-by-1 pivot block
  664. *
  665. KP = K
  666. ELSE
  667. *
  668. * BEGIN pivot search along IMAX row
  669. *
  670. *
  671. * Copy column IMAX to column K+1 of W and update it
  672. *
  673. CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1 )
  674. CALL ZLACGV( IMAX-K, W( K, K+1 ), 1 )
  675. W( IMAX, K+1 ) = DBLE( A( IMAX, IMAX ) )
  676. IF( IMAX.LT.N )
  677. $ CALL ZCOPY( N-IMAX, A( IMAX+1, IMAX ), 1,
  678. $ W( IMAX+1, K+1 ), 1 )
  679. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
  680. $ LDA, W( IMAX, 1 ), LDW, CONE, W( K, K+1 ),
  681. $ 1 )
  682. W( IMAX, K+1 ) = DBLE( W( IMAX, K+1 ) )
  683. *
  684. * JMAX is the column-index of the largest off-diagonal
  685. * element in row IMAX, and ROWMAX is its absolute value.
  686. * Determine only ROWMAX.
  687. *
  688. JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
  689. ROWMAX = CABS1( W( JMAX, K+1 ) )
  690. IF( IMAX.LT.N ) THEN
  691. JMAX = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1 )
  692. ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, K+1 ) ) )
  693. END IF
  694. *
  695. * Case(2)
  696. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  697. *
  698. * no interchange, use 1-by-1 pivot block
  699. *
  700. KP = K
  701. *
  702. * Case(3)
  703. ELSE IF( ABS( DBLE( W( IMAX, K+1 ) ) ).GE.ALPHA*ROWMAX )
  704. $ THEN
  705. *
  706. * interchange rows and columns K and IMAX, use 1-by-1
  707. * pivot block
  708. *
  709. KP = IMAX
  710. *
  711. * copy column K+1 of W to column K of W
  712. *
  713. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  714. *
  715. * Case(4)
  716. ELSE
  717. *
  718. * interchange rows and columns K+1 and IMAX, use 2-by-2
  719. * pivot block
  720. *
  721. KP = IMAX
  722. KSTEP = 2
  723. END IF
  724. *
  725. *
  726. * END pivot search along IMAX row
  727. *
  728. END IF
  729. *
  730. * END pivot search
  731. *
  732. * ============================================================
  733. *
  734. * KK is the column of A where pivoting step stopped
  735. *
  736. KK = K + KSTEP - 1
  737. *
  738. * Interchange rows and columns KP and KK.
  739. * Updated column KP is already stored in column KK of W.
  740. *
  741. IF( KP.NE.KK ) THEN
  742. *
  743. * Copy non-updated column KK to column KP of submatrix A
  744. * at step K. No need to copy element into column K
  745. * (or K and K+1 for 2-by-2 pivot) of A, since these columns
  746. * will be later overwritten.
  747. *
  748. A( KP, KP ) = DBLE( A( KK, KK ) )
  749. CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
  750. $ LDA )
  751. CALL ZLACGV( KP-KK-1, A( KP, KK+1 ), LDA )
  752. IF( KP.LT.N )
  753. $ CALL ZCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
  754. *
  755. * Interchange rows KK and KP in first K-1 columns of A
  756. * (columns K (or K and K+1 for 2-by-2 pivot) of A will be
  757. * later overwritten). Interchange rows KK and KP
  758. * in first KK columns of W.
  759. *
  760. IF( K.GT.1 )
  761. $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
  762. CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
  763. END IF
  764. *
  765. IF( KSTEP.EQ.1 ) THEN
  766. *
  767. * 1-by-1 pivot block D(k): column k of W now holds
  768. *
  769. * W(k) = L(k)*D(k),
  770. *
  771. * where L(k) is the k-th column of L
  772. *
  773. * (1) Store subdiag. elements of column L(k)
  774. * and 1-by-1 block D(k) in column k of A.
  775. * (NOTE: Diagonal element L(k,k) is a UNIT element
  776. * and not stored)
  777. * A(k,k) := D(k,k) = W(k,k)
  778. * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
  779. *
  780. * (NOTE: No need to use for Hermitian matrix
  781. * A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal
  782. * element D(k,k) from W (potentially saves only one load))
  783. CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  784. IF( K.LT.N ) THEN
  785. *
  786. * (NOTE: No need to check if A(k,k) is NOT ZERO,
  787. * since that was ensured earlier in pivot search:
  788. * case A(k,k) = 0 falls into 2x2 pivot case(4))
  789. *
  790. R1 = ONE / DBLE( A( K, K ) )
  791. CALL ZDSCAL( N-K, R1, A( K+1, K ), 1 )
  792. *
  793. * (2) Conjugate column W(k)
  794. *
  795. CALL ZLACGV( N-K, W( K+1, K ), 1 )
  796. END IF
  797. *
  798. ELSE
  799. *
  800. * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
  801. *
  802. * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
  803. *
  804. * where L(k) and L(k+1) are the k-th and (k+1)-th columns
  805. * of L
  806. *
  807. * (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
  808. * block D(k:k+1,k:k+1) in columns k and k+1 of A.
  809. * (NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
  810. * block and not stored)
  811. * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
  812. * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
  813. * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
  814. *
  815. IF( K.LT.N-1 ) THEN
  816. *
  817. * Factor out the columns of the inverse of 2-by-2 pivot
  818. * block D, so that each column contains 1, to reduce the
  819. * number of FLOPS when we multiply panel
  820. * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
  821. *
  822. * D**(-1) = ( d11 cj(d21) )**(-1) =
  823. * ( d21 d22 )
  824. *
  825. * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
  826. * ( (-d21) ( d11 ) )
  827. *
  828. * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
  829. *
  830. * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
  831. * ( ( -1 ) ( d11/conj(d21) ) )
  832. *
  833. * = 1/(|d21|**2) * 1/(D22*D11-1) *
  834. *
  835. * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  836. * ( ( -1 ) ( D22 ) )
  837. *
  838. * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  839. * ( ( -1 ) ( D22 ) )
  840. *
  841. * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
  842. * ( ( -1 ) ( D22 ) )
  843. *
  844. * = ( conj(D21)*( D11 ) D21*( -1 ) )
  845. * ( ( -1 ) ( D22 ) ),
  846. *
  847. * where D11 = d22/d21,
  848. * D22 = d11/conj(d21),
  849. * D21 = T/d21,
  850. * T = 1/(D22*D11-1).
  851. *
  852. * (NOTE: No need to check for division by ZERO,
  853. * since that was ensured earlier in pivot search:
  854. * (a) d21 != 0, since in 2x2 pivot case(4)
  855. * |d21| should be larger than |d11| and |d22|;
  856. * (b) (D22*D11 - 1) != 0, since from (a),
  857. * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
  858. *
  859. D21 = W( K+1, K )
  860. D11 = W( K+1, K+1 ) / D21
  861. D22 = W( K, K ) / DCONJG( D21 )
  862. T = ONE / ( DBLE( D11*D22 )-ONE )
  863. D21 = T / D21
  864. *
  865. * Update elements in columns A(k) and A(k+1) as
  866. * dot products of rows of ( W(k) W(k+1) ) and columns
  867. * of D**(-1)
  868. *
  869. DO 80 J = K + 2, N
  870. A( J, K ) = DCONJG( D21 )*
  871. $ ( D11*W( J, K )-W( J, K+1 ) )
  872. A( J, K+1 ) = D21*( D22*W( J, K+1 )-W( J, K ) )
  873. 80 CONTINUE
  874. END IF
  875. *
  876. * Copy D(k) to A
  877. *
  878. A( K, K ) = W( K, K )
  879. A( K+1, K ) = W( K+1, K )
  880. A( K+1, K+1 ) = W( K+1, K+1 )
  881. *
  882. * (2) Conjugate columns W(k) and W(k+1)
  883. *
  884. CALL ZLACGV( N-K, W( K+1, K ), 1 )
  885. CALL ZLACGV( N-K-1, W( K+2, K+1 ), 1 )
  886. *
  887. END IF
  888. *
  889. END IF
  890. *
  891. * Store details of the interchanges in IPIV
  892. *
  893. IF( KSTEP.EQ.1 ) THEN
  894. IPIV( K ) = KP
  895. ELSE
  896. IPIV( K ) = -KP
  897. IPIV( K+1 ) = -KP
  898. END IF
  899. *
  900. * Increase K and return to the start of the main loop
  901. *
  902. K = K + KSTEP
  903. GO TO 70
  904. *
  905. 90 CONTINUE
  906. *
  907. * Update the lower triangle of A22 (= A(k:n,k:n)) as
  908. *
  909. * A22 := A22 - L21*D*L21**H = A22 - L21*W**H
  910. *
  911. * computing blocks of NB columns at a time (note that conjg(W) is
  912. * actually stored)
  913. *
  914. DO 110 J = K, N, NB
  915. JB = MIN( NB, N-J+1 )
  916. *
  917. * Update the lower triangle of the diagonal block
  918. *
  919. DO 100 JJ = J, J + JB - 1
  920. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  921. CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
  922. $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
  923. $ A( JJ, JJ ), 1 )
  924. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  925. 100 CONTINUE
  926. *
  927. * Update the rectangular subdiagonal block
  928. *
  929. IF( J+JB.LE.N )
  930. $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
  931. $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
  932. $ LDW, CONE, A( J+JB, J ), LDA )
  933. 110 CONTINUE
  934. *
  935. * Put L21 in standard form by partially undoing the interchanges
  936. * of rows in columns 1:k-1 looping backwards from k-1 to 1
  937. *
  938. J = K - 1
  939. 120 CONTINUE
  940. *
  941. * Undo the interchanges (if any) of rows JJ and JP at each
  942. * step J
  943. *
  944. * (Here, J is a diagonal index)
  945. JJ = J
  946. JP = IPIV( J )
  947. IF( JP.LT.0 ) THEN
  948. JP = -JP
  949. * (Here, J is a diagonal index)
  950. J = J - 1
  951. END IF
  952. * (NOTE: Here, J is used to determine row length. Length J
  953. * of the rows to swap back doesn't include diagonal element)
  954. J = J - 1
  955. IF( JP.NE.JJ .AND. J.GE.1 )
  956. $ CALL ZSWAP( J, A( JP, 1 ), LDA, A( JJ, 1 ), LDA )
  957. IF( J.GT.1 )
  958. $ GO TO 120
  959. *
  960. * Set KB to the number of columns factorized
  961. *
  962. KB = K - 1
  963. *
  964. END IF
  965. RETURN
  966. *
  967. * End of ZLAHEF
  968. *
  969. END