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_rk.f 42 kB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231
  1. *> \brief \b ZLAHEF_RK computes a partial factorization of a complex Hermitian indefinite matrix using bounded Bunch-Kaufman (rook) diagonal pivoting method.
  2. *
  3. * =========== DOCUMENTATION ===========
  4. *
  5. * Online html documentation available at
  6. * http://www.netlib.org/lapack/explore-html/
  7. *
  8. *> \htmlonly
  9. *> Download ZLAHEF_RK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef_rk.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef_rk.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef_rk.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW,
  22. * INFO )
  23. *
  24. * .. Scalar Arguments ..
  25. * CHARACTER UPLO
  26. * INTEGER INFO, KB, LDA, LDW, N, NB
  27. * ..
  28. * .. Array Arguments ..
  29. * INTEGER IPIV( * )
  30. * COMPLEX*16 A( LDA, * ), E( * ), W( LDW, * )
  31. * ..
  32. *
  33. *
  34. *> \par Purpose:
  35. * =============
  36. *>
  37. *> \verbatim
  38. *> ZLAHEF_RK computes a partial factorization of a complex Hermitian
  39. *> matrix A using the bounded Bunch-Kaufman (rook) diagonal
  40. *> pivoting method. The 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. *>
  51. *> ZLAHEF_RK is an auxiliary routine called by ZHETRF_RK. It uses
  52. *> blocked code (calling Level 3 BLAS) to update the submatrix
  53. *> A11 (if UPLO = 'U') or A22 (if UPLO = 'L').
  54. *> \endverbatim
  55. *
  56. * Arguments:
  57. * ==========
  58. *
  59. *> \param[in] UPLO
  60. *> \verbatim
  61. *> UPLO is CHARACTER*1
  62. *> Specifies whether the upper or lower triangular part of the
  63. *> Hermitian matrix A is stored:
  64. *> = 'U': Upper triangular
  65. *> = 'L': Lower triangular
  66. *> \endverbatim
  67. *>
  68. *> \param[in] N
  69. *> \verbatim
  70. *> N is INTEGER
  71. *> The order of the matrix A. N >= 0.
  72. *> \endverbatim
  73. *>
  74. *> \param[in] NB
  75. *> \verbatim
  76. *> NB is INTEGER
  77. *> The maximum number of columns of the matrix A that should be
  78. *> factored. NB should be at least 2 to allow for 2-by-2 pivot
  79. *> blocks.
  80. *> \endverbatim
  81. *>
  82. *> \param[out] KB
  83. *> \verbatim
  84. *> KB is INTEGER
  85. *> The number of columns of A that were actually factored.
  86. *> KB is either NB-1 or NB, or N if N <= NB.
  87. *> \endverbatim
  88. *>
  89. *> \param[in,out] A
  90. *> \verbatim
  91. *> A is COMPLEX*16 array, dimension (LDA,N)
  92. *> On entry, the Hermitian matrix A.
  93. *> If UPLO = 'U': the leading N-by-N upper triangular part
  94. *> of A contains the upper triangular part of the matrix A,
  95. *> and the strictly lower triangular part of A is not
  96. *> referenced.
  97. *>
  98. *> If UPLO = 'L': the leading N-by-N lower triangular part
  99. *> of A contains the lower triangular part of the matrix A,
  100. *> and the strictly upper triangular part of A is not
  101. *> referenced.
  102. *>
  103. *> On exit, contains:
  104. *> a) ONLY diagonal elements of the Hermitian block diagonal
  105. *> matrix D on the diagonal of A, i.e. D(k,k) = A(k,k);
  106. *> (superdiagonal (or subdiagonal) elements of D
  107. *> are stored on exit in array E), and
  108. *> b) If UPLO = 'U': factor U in the superdiagonal part of A.
  109. *> If UPLO = 'L': factor L in the subdiagonal part of A.
  110. *> \endverbatim
  111. *>
  112. *> \param[in] LDA
  113. *> \verbatim
  114. *> LDA is INTEGER
  115. *> The leading dimension of the array A. LDA >= max(1,N).
  116. *> \endverbatim
  117. *>
  118. *> \param[out] E
  119. *> \verbatim
  120. *> E is COMPLEX*16 array, dimension (N)
  121. *> On exit, contains the superdiagonal (or subdiagonal)
  122. *> elements of the Hermitian block diagonal matrix D
  123. *> with 1-by-1 or 2-by-2 diagonal blocks, where
  124. *> If UPLO = 'U': E(i) = D(i-1,i), i=2:N, E(1) is set to 0;
  125. *> If UPLO = 'L': E(i) = D(i+1,i), i=1:N-1, E(N) is set to 0.
  126. *>
  127. *> NOTE: For 1-by-1 diagonal block D(k), where
  128. *> 1 <= k <= N, the element E(k) is set to 0 in both
  129. *> UPLO = 'U' or UPLO = 'L' cases.
  130. *> \endverbatim
  131. *>
  132. *> \param[out] IPIV
  133. *> \verbatim
  134. *> IPIV is INTEGER array, dimension (N)
  135. *> IPIV describes the permutation matrix P in the factorization
  136. *> of matrix A as follows. The absolute value of IPIV(k)
  137. *> represents the index of row and column that were
  138. *> interchanged with the k-th row and column. The value of UPLO
  139. *> describes the order in which the interchanges were applied.
  140. *> Also, the sign of IPIV represents the block structure of
  141. *> the Hermitian block diagonal matrix D with 1-by-1 or 2-by-2
  142. *> diagonal blocks which correspond to 1 or 2 interchanges
  143. *> at each factorization step.
  144. *>
  145. *> If UPLO = 'U',
  146. *> ( in factorization order, k decreases from N to 1 ):
  147. *> a) A single positive entry IPIV(k) > 0 means:
  148. *> D(k,k) is a 1-by-1 diagonal block.
  149. *> If IPIV(k) != k, rows and columns k and IPIV(k) were
  150. *> interchanged in the submatrix A(1:N,N-KB+1:N);
  151. *> If IPIV(k) = k, no interchange occurred.
  152. *>
  153. *>
  154. *> b) A pair of consecutive negative entries
  155. *> IPIV(k) < 0 and IPIV(k-1) < 0 means:
  156. *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
  157. *> (NOTE: negative entries in IPIV appear ONLY in pairs).
  158. *> 1) If -IPIV(k) != k, rows and columns
  159. *> k and -IPIV(k) were interchanged
  160. *> in the matrix A(1:N,N-KB+1:N).
  161. *> If -IPIV(k) = k, no interchange occurred.
  162. *> 2) If -IPIV(k-1) != k-1, rows and columns
  163. *> k-1 and -IPIV(k-1) were interchanged
  164. *> in the submatrix A(1:N,N-KB+1:N).
  165. *> If -IPIV(k-1) = k-1, no interchange occurred.
  166. *>
  167. *> c) In both cases a) and b) is always ABS( IPIV(k) ) <= k.
  168. *>
  169. *> d) NOTE: Any entry IPIV(k) is always NONZERO on output.
  170. *>
  171. *> If UPLO = 'L',
  172. *> ( in factorization order, k increases from 1 to N ):
  173. *> a) A single positive entry IPIV(k) > 0 means:
  174. *> D(k,k) is a 1-by-1 diagonal block.
  175. *> If IPIV(k) != k, rows and columns k and IPIV(k) were
  176. *> interchanged in the submatrix A(1:N,1:KB).
  177. *> If IPIV(k) = k, no interchange occurred.
  178. *>
  179. *> b) A pair of consecutive negative entries
  180. *> IPIV(k) < 0 and IPIV(k+1) < 0 means:
  181. *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
  182. *> (NOTE: negative entries in IPIV appear ONLY in pairs).
  183. *> 1) If -IPIV(k) != k, rows and columns
  184. *> k and -IPIV(k) were interchanged
  185. *> in the submatrix A(1:N,1:KB).
  186. *> If -IPIV(k) = k, no interchange occurred.
  187. *> 2) If -IPIV(k+1) != k+1, rows and columns
  188. *> k-1 and -IPIV(k-1) were interchanged
  189. *> in the submatrix A(1:N,1:KB).
  190. *> If -IPIV(k+1) = k+1, no interchange occurred.
  191. *>
  192. *> c) In both cases a) and b) is always ABS( IPIV(k) ) >= k.
  193. *>
  194. *> d) NOTE: Any entry IPIV(k) is always NONZERO on output.
  195. *> \endverbatim
  196. *>
  197. *> \param[out] W
  198. *> \verbatim
  199. *> W is COMPLEX*16 array, dimension (LDW,NB)
  200. *> \endverbatim
  201. *>
  202. *> \param[in] LDW
  203. *> \verbatim
  204. *> LDW is INTEGER
  205. *> The leading dimension of the array W. LDW >= max(1,N).
  206. *> \endverbatim
  207. *>
  208. *> \param[out] INFO
  209. *> \verbatim
  210. *> INFO is INTEGER
  211. *> = 0: successful exit
  212. *>
  213. *> < 0: If INFO = -k, the k-th argument had an illegal value
  214. *>
  215. *> > 0: If INFO = k, the matrix A is singular, because:
  216. *> If UPLO = 'U': column k in the upper
  217. *> triangular part of A contains all zeros.
  218. *> If UPLO = 'L': column k in the lower
  219. *> triangular part of A contains all zeros.
  220. *>
  221. *> Therefore D(k,k) is exactly zero, and superdiagonal
  222. *> elements of column k of U (or subdiagonal elements of
  223. *> column k of L ) are all zeros. The factorization has
  224. *> been completed, but the block diagonal matrix D is
  225. *> exactly singular, and division by zero will occur if
  226. *> it is used to solve a system of equations.
  227. *>
  228. *> NOTE: INFO only stores the first occurrence of
  229. *> a singularity, any subsequent occurrence of singularity
  230. *> is not stored in INFO even though the factorization
  231. *> always completes.
  232. *> \endverbatim
  233. *
  234. * Authors:
  235. * ========
  236. *
  237. *> \author Univ. of Tennessee
  238. *> \author Univ. of California Berkeley
  239. *> \author Univ. of Colorado Denver
  240. *> \author NAG Ltd.
  241. *
  242. *> \ingroup complex16HEcomputational
  243. *
  244. *> \par Contributors:
  245. * ==================
  246. *>
  247. *> \verbatim
  248. *>
  249. *> December 2016, Igor Kozachenko,
  250. *> Computer Science Division,
  251. *> University of California, Berkeley
  252. *>
  253. *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
  254. *> School of Mathematics,
  255. *> University of Manchester
  256. *>
  257. *> \endverbatim
  258. *
  259. * =====================================================================
  260. SUBROUTINE ZLAHEF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW,
  261. $ INFO )
  262. *
  263. * -- LAPACK computational routine --
  264. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  265. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  266. *
  267. * .. Scalar Arguments ..
  268. CHARACTER UPLO
  269. INTEGER INFO, KB, LDA, LDW, N, NB
  270. * ..
  271. * .. Array Arguments ..
  272. INTEGER IPIV( * )
  273. COMPLEX*16 A( LDA, * ), W( LDW, * ), E( * )
  274. * ..
  275. *
  276. * =====================================================================
  277. *
  278. * .. Parameters ..
  279. DOUBLE PRECISION ZERO, ONE
  280. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  281. COMPLEX*16 CONE
  282. PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
  283. DOUBLE PRECISION EIGHT, SEVTEN
  284. PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
  285. COMPLEX*16 CZERO
  286. PARAMETER ( CZERO = ( 0.0D+0, 0.0D+0 ) )
  287. * ..
  288. * .. Local Scalars ..
  289. LOGICAL DONE
  290. INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, K, KK, KKW,
  291. $ KP, KSTEP, KW, P
  292. DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, DTEMP, R1, ROWMAX, T,
  293. $ SFMIN
  294. COMPLEX*16 D11, D21, D22, Z
  295. * ..
  296. * .. External Functions ..
  297. LOGICAL LSAME
  298. INTEGER IZAMAX
  299. DOUBLE PRECISION DLAMCH
  300. EXTERNAL LSAME, IZAMAX, DLAMCH
  301. * ..
  302. * .. External Subroutines ..
  303. EXTERNAL ZCOPY, ZDSCAL, ZGEMM, ZGEMV, ZLACGV, ZSWAP
  304. * ..
  305. * .. Intrinsic Functions ..
  306. INTRINSIC ABS, DBLE, DCONJG, DIMAG, MAX, MIN, SQRT
  307. * ..
  308. * .. Statement Functions ..
  309. DOUBLE PRECISION CABS1
  310. * ..
  311. * .. Statement Function definitions ..
  312. CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
  313. * ..
  314. * .. Executable Statements ..
  315. *
  316. INFO = 0
  317. *
  318. * Initialize ALPHA for use in choosing pivot block size.
  319. *
  320. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  321. *
  322. * Compute machine safe minimum
  323. *
  324. SFMIN = DLAMCH( 'S' )
  325. *
  326. IF( LSAME( UPLO, 'U' ) ) THEN
  327. *
  328. * Factorize the trailing columns of A using the upper triangle
  329. * of A and working backwards, and compute the matrix W = U12*D
  330. * for use in updating A11 (note that conjg(W) is actually stored)
  331. * Initialize the first entry of array E, where superdiagonal
  332. * elements of D are stored
  333. *
  334. E( 1 ) = CZERO
  335. *
  336. * K is the main loop index, decreasing from N in steps of 1 or 2
  337. *
  338. K = N
  339. 10 CONTINUE
  340. *
  341. * KW is the column of W which corresponds to column K of A
  342. *
  343. KW = NB + K - N
  344. *
  345. * Exit from loop
  346. *
  347. IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
  348. $ GO TO 30
  349. *
  350. KSTEP = 1
  351. P = K
  352. *
  353. * Copy column K of A to column KW of W and update it
  354. *
  355. IF( K.GT.1 )
  356. $ CALL ZCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 )
  357. W( K, KW ) = DBLE( A( K, K ) )
  358. IF( K.LT.N ) THEN
  359. CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
  360. $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
  361. W( K, KW ) = DBLE( W( K, KW ) )
  362. END IF
  363. *
  364. * Determine rows and columns to be interchanged and whether
  365. * a 1-by-1 or 2-by-2 pivot block will be used
  366. *
  367. ABSAKK = ABS( DBLE( W( K, KW ) ) )
  368. *
  369. * IMAX is the row-index of the largest off-diagonal element in
  370. * column K, and COLMAX is its absolute value.
  371. * Determine both COLMAX and IMAX.
  372. *
  373. IF( K.GT.1 ) THEN
  374. IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
  375. COLMAX = CABS1( W( IMAX, KW ) )
  376. ELSE
  377. COLMAX = ZERO
  378. END IF
  379. *
  380. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  381. *
  382. * Column K is zero or underflow: set INFO and continue
  383. *
  384. IF( INFO.EQ.0 )
  385. $ INFO = K
  386. KP = K
  387. A( K, K ) = DBLE( W( K, KW ) )
  388. IF( K.GT.1 )
  389. $ CALL ZCOPY( K-1, W( 1, KW ), 1, A( 1, K ), 1 )
  390. *
  391. * Set E( K ) to zero
  392. *
  393. IF( K.GT.1 )
  394. $ E( K ) = CZERO
  395. *
  396. ELSE
  397. *
  398. * ============================================================
  399. *
  400. * BEGIN pivot search
  401. *
  402. * Case(1)
  403. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  404. * (used to handle NaN and Inf)
  405. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  406. *
  407. * no interchange, use 1-by-1 pivot block
  408. *
  409. KP = K
  410. *
  411. ELSE
  412. *
  413. * Lop until pivot found
  414. *
  415. DONE = .FALSE.
  416. *
  417. 12 CONTINUE
  418. *
  419. * BEGIN pivot search loop body
  420. *
  421. *
  422. * Copy column IMAX to column KW-1 of W and update it
  423. *
  424. IF( IMAX.GT.1 )
  425. $ CALL ZCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ),
  426. $ 1 )
  427. W( IMAX, KW-1 ) = DBLE( A( IMAX, IMAX ) )
  428. *
  429. CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
  430. $ W( IMAX+1, KW-1 ), 1 )
  431. CALL ZLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 )
  432. *
  433. IF( K.LT.N ) THEN
  434. CALL ZGEMV( 'No transpose', K, N-K, -CONE,
  435. $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
  436. $ CONE, W( 1, KW-1 ), 1 )
  437. W( IMAX, KW-1 ) = DBLE( W( IMAX, KW-1 ) )
  438. END IF
  439. *
  440. * JMAX is the column-index of the largest off-diagonal
  441. * element in row IMAX, and ROWMAX is its absolute value.
  442. * Determine both ROWMAX and JMAX.
  443. *
  444. IF( IMAX.NE.K ) THEN
  445. JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ),
  446. $ 1 )
  447. ROWMAX = CABS1( W( JMAX, KW-1 ) )
  448. ELSE
  449. ROWMAX = ZERO
  450. END IF
  451. *
  452. IF( IMAX.GT.1 ) THEN
  453. ITEMP = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
  454. DTEMP = CABS1( W( ITEMP, KW-1 ) )
  455. IF( DTEMP.GT.ROWMAX ) THEN
  456. ROWMAX = DTEMP
  457. JMAX = ITEMP
  458. END IF
  459. END IF
  460. *
  461. * Case(2)
  462. * Equivalent to testing for
  463. * ABS( DBLE( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX
  464. * (used to handle NaN and Inf)
  465. *
  466. IF( .NOT.( ABS( DBLE( W( IMAX,KW-1 ) ) )
  467. $ .LT.ALPHA*ROWMAX ) ) THEN
  468. *
  469. * interchange rows and columns K and IMAX,
  470. * use 1-by-1 pivot block
  471. *
  472. KP = IMAX
  473. *
  474. * copy column KW-1 of W to column KW of W
  475. *
  476. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  477. *
  478. DONE = .TRUE.
  479. *
  480. * Case(3)
  481. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  482. * (used to handle NaN and Inf)
  483. *
  484. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  485. $ THEN
  486. *
  487. * interchange rows and columns K-1 and IMAX,
  488. * use 2-by-2 pivot block
  489. *
  490. KP = IMAX
  491. KSTEP = 2
  492. DONE = .TRUE.
  493. *
  494. * Case(4)
  495. ELSE
  496. *
  497. * Pivot not found: set params and repeat
  498. *
  499. P = IMAX
  500. COLMAX = ROWMAX
  501. IMAX = JMAX
  502. *
  503. * Copy updated JMAXth (next IMAXth) column to Kth of W
  504. *
  505. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  506. *
  507. END IF
  508. *
  509. *
  510. * END pivot search loop body
  511. *
  512. IF( .NOT.DONE ) GOTO 12
  513. *
  514. END IF
  515. *
  516. * END pivot search
  517. *
  518. * ============================================================
  519. *
  520. * KK is the column of A where pivoting step stopped
  521. *
  522. KK = K - KSTEP + 1
  523. *
  524. * KKW is the column of W which corresponds to column KK of A
  525. *
  526. KKW = NB + KK - N
  527. *
  528. * Interchange rows and columns P and K.
  529. * Updated column P is already stored in column KW of W.
  530. *
  531. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  532. *
  533. * Copy non-updated column K to column P of submatrix A
  534. * at step K. No need to copy element into columns
  535. * K and K-1 of A for 2-by-2 pivot, since these columns
  536. * will be later overwritten.
  537. *
  538. A( P, P ) = DBLE( A( K, K ) )
  539. CALL ZCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ),
  540. $ LDA )
  541. CALL ZLACGV( K-1-P, A( P, P+1 ), LDA )
  542. IF( P.GT.1 )
  543. $ CALL ZCOPY( P-1, A( 1, K ), 1, A( 1, P ), 1 )
  544. *
  545. * Interchange rows K and P in the last K+1 to N columns of A
  546. * (columns K and K-1 of A for 2-by-2 pivot will be
  547. * later overwritten). Interchange rows K and P
  548. * in last KKW to NB columns of W.
  549. *
  550. IF( K.LT.N )
  551. $ CALL ZSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ),
  552. $ LDA )
  553. CALL ZSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ),
  554. $ LDW )
  555. END IF
  556. *
  557. * Interchange rows and columns KP and KK.
  558. * Updated column KP is already stored in column KKW of W.
  559. *
  560. IF( KP.NE.KK ) THEN
  561. *
  562. * Copy non-updated column KK to column KP of submatrix A
  563. * at step K. No need to copy element into column K
  564. * (or K and K-1 for 2-by-2 pivot) of A, since these columns
  565. * will be later overwritten.
  566. *
  567. A( KP, KP ) = DBLE( A( KK, KK ) )
  568. CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
  569. $ LDA )
  570. CALL ZLACGV( KK-1-KP, A( KP, KP+1 ), LDA )
  571. IF( KP.GT.1 )
  572. $ CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
  573. *
  574. * Interchange rows KK and KP in last K+1 to N columns of A
  575. * (columns K (or K and K-1 for 2-by-2 pivot) of A will be
  576. * later overwritten). Interchange rows KK and KP
  577. * in last KKW to NB columns of W.
  578. *
  579. IF( K.LT.N )
  580. $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
  581. $ LDA )
  582. CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
  583. $ LDW )
  584. END IF
  585. *
  586. IF( KSTEP.EQ.1 ) THEN
  587. *
  588. * 1-by-1 pivot block D(k): column kw of W now holds
  589. *
  590. * W(kw) = U(k)*D(k),
  591. *
  592. * where U(k) is the k-th column of U
  593. *
  594. * (1) Store subdiag. elements of column U(k)
  595. * and 1-by-1 block D(k) in column k of A.
  596. * (NOTE: Diagonal element U(k,k) is a UNIT element
  597. * and not stored)
  598. * A(k,k) := D(k,k) = W(k,kw)
  599. * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
  600. *
  601. * (NOTE: No need to use for Hermitian matrix
  602. * A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal
  603. * element D(k,k) from W (potentially saves only one load))
  604. CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  605. IF( K.GT.1 ) THEN
  606. *
  607. * (NOTE: No need to check if A(k,k) is NOT ZERO,
  608. * since that was ensured earlier in pivot search:
  609. * case A(k,k) = 0 falls into 2x2 pivot case(3))
  610. *
  611. * Handle division by a small number
  612. *
  613. T = DBLE( A( K, K ) )
  614. IF( ABS( T ).GE.SFMIN ) THEN
  615. R1 = ONE / T
  616. CALL ZDSCAL( K-1, R1, A( 1, K ), 1 )
  617. ELSE
  618. DO 14 II = 1, K-1
  619. A( II, K ) = A( II, K ) / T
  620. 14 CONTINUE
  621. END IF
  622. *
  623. * (2) Conjugate column W(kw)
  624. *
  625. CALL ZLACGV( K-1, W( 1, KW ), 1 )
  626. *
  627. * Store the superdiagonal element of D in array E
  628. *
  629. E( K ) = CZERO
  630. *
  631. END IF
  632. *
  633. ELSE
  634. *
  635. * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
  636. *
  637. * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
  638. *
  639. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  640. * of U
  641. *
  642. * (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
  643. * block D(k-1:k,k-1:k) in columns k-1 and k of A.
  644. * (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
  645. * block and not stored)
  646. * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
  647. * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
  648. * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
  649. *
  650. IF( K.GT.2 ) THEN
  651. *
  652. * Factor out the columns of the inverse of 2-by-2 pivot
  653. * block D, so that each column contains 1, to reduce the
  654. * number of FLOPS when we multiply panel
  655. * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
  656. *
  657. * D**(-1) = ( d11 cj(d21) )**(-1) =
  658. * ( d21 d22 )
  659. *
  660. * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
  661. * ( (-d21) ( d11 ) )
  662. *
  663. * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
  664. *
  665. * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
  666. * ( ( -1 ) ( d11/conj(d21) ) )
  667. *
  668. * = 1/(|d21|**2) * 1/(D22*D11-1) *
  669. *
  670. * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  671. * ( ( -1 ) ( D22 ) )
  672. *
  673. * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  674. * ( ( -1 ) ( D22 ) )
  675. *
  676. * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
  677. * ( ( -1 ) ( D22 ) )
  678. *
  679. * Handle division by a small number. (NOTE: order of
  680. * operations is important)
  681. *
  682. * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
  683. * ( (( -1 ) ) (( D22 ) ) ),
  684. *
  685. * where D11 = d22/d21,
  686. * D22 = d11/conj(d21),
  687. * D21 = d21,
  688. * T = 1/(D22*D11-1).
  689. *
  690. * (NOTE: No need to check for division by ZERO,
  691. * since that was ensured earlier in pivot search:
  692. * (a) d21 != 0 in 2x2 pivot case(4),
  693. * since |d21| should be larger than |d11| and |d22|;
  694. * (b) (D22*D11 - 1) != 0, since from (a),
  695. * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
  696. *
  697. D21 = W( K-1, KW )
  698. D11 = W( K, KW ) / DCONJG( D21 )
  699. D22 = W( K-1, KW-1 ) / D21
  700. T = ONE / ( DBLE( D11*D22 )-ONE )
  701. *
  702. * Update elements in columns A(k-1) and A(k) as
  703. * dot products of rows of ( W(kw-1) W(kw) ) and columns
  704. * of D**(-1)
  705. *
  706. DO 20 J = 1, K - 2
  707. A( J, K-1 ) = T*( ( D11*W( J, KW-1 )-W( J, KW ) ) /
  708. $ D21 )
  709. A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
  710. $ DCONJG( D21 ) )
  711. 20 CONTINUE
  712. END IF
  713. *
  714. * Copy diagonal elements of D(K) to A,
  715. * copy superdiagonal element of D(K) to E(K) and
  716. * ZERO out superdiagonal entry of A
  717. *
  718. A( K-1, K-1 ) = W( K-1, KW-1 )
  719. A( K-1, K ) = CZERO
  720. A( K, K ) = W( K, KW )
  721. E( K ) = W( K-1, KW )
  722. E( K-1 ) = CZERO
  723. *
  724. * (2) Conjugate columns W(kw) and W(kw-1)
  725. *
  726. CALL ZLACGV( K-1, W( 1, KW ), 1 )
  727. CALL ZLACGV( K-2, W( 1, KW-1 ), 1 )
  728. *
  729. END IF
  730. *
  731. * End column K is nonsingular
  732. *
  733. END IF
  734. *
  735. * Store details of the interchanges in IPIV
  736. *
  737. IF( KSTEP.EQ.1 ) THEN
  738. IPIV( K ) = KP
  739. ELSE
  740. IPIV( K ) = -P
  741. IPIV( K-1 ) = -KP
  742. END IF
  743. *
  744. * Decrease K and return to the start of the main loop
  745. *
  746. K = K - KSTEP
  747. GO TO 10
  748. *
  749. 30 CONTINUE
  750. *
  751. * Update the upper triangle of A11 (= A(1:k,1:k)) as
  752. *
  753. * A11 := A11 - U12*D*U12**H = A11 - U12*W**H
  754. *
  755. * computing blocks of NB columns at a time (note that conjg(W) is
  756. * actually stored)
  757. *
  758. DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
  759. JB = MIN( NB, K-J+1 )
  760. *
  761. * Update the upper triangle of the diagonal block
  762. *
  763. DO 40 JJ = J, J + JB - 1
  764. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  765. CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
  766. $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
  767. $ A( J, JJ ), 1 )
  768. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  769. 40 CONTINUE
  770. *
  771. * Update the rectangular superdiagonal block
  772. *
  773. IF( J.GE.2 )
  774. $ CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
  775. $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
  776. $ CONE, A( 1, J ), LDA )
  777. 50 CONTINUE
  778. *
  779. * Set KB to the number of columns factorized
  780. *
  781. KB = N - K
  782. *
  783. ELSE
  784. *
  785. * Factorize the leading columns of A using the lower triangle
  786. * of A and working forwards, and compute the matrix W = L21*D
  787. * for use in updating A22 (note that conjg(W) is actually stored)
  788. *
  789. * Initialize the unused last entry of the subdiagonal array E.
  790. *
  791. E( N ) = CZERO
  792. *
  793. * K is the main loop index, increasing from 1 in steps of 1 or 2
  794. *
  795. K = 1
  796. 70 CONTINUE
  797. *
  798. * Exit from loop
  799. *
  800. IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
  801. $ GO TO 90
  802. *
  803. KSTEP = 1
  804. P = K
  805. *
  806. * Copy column K of A to column K of W and update column K of W
  807. *
  808. W( K, K ) = DBLE( A( K, K ) )
  809. IF( K.LT.N )
  810. $ CALL ZCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
  811. IF( K.GT.1 ) THEN
  812. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
  813. $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 )
  814. W( K, K ) = DBLE( W( K, K ) )
  815. END IF
  816. *
  817. * Determine rows and columns to be interchanged and whether
  818. * a 1-by-1 or 2-by-2 pivot block will be used
  819. *
  820. ABSAKK = ABS( DBLE( W( K, K ) ) )
  821. *
  822. * IMAX is the row-index of the largest off-diagonal element in
  823. * column K, and COLMAX is its absolute value.
  824. * Determine both COLMAX and IMAX.
  825. *
  826. IF( K.LT.N ) THEN
  827. IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
  828. COLMAX = CABS1( W( IMAX, K ) )
  829. ELSE
  830. COLMAX = ZERO
  831. END IF
  832. *
  833. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  834. *
  835. * Column K is zero or underflow: set INFO and continue
  836. *
  837. IF( INFO.EQ.0 )
  838. $ INFO = K
  839. KP = K
  840. A( K, K ) = DBLE( W( K, K ) )
  841. IF( K.LT.N )
  842. $ CALL ZCOPY( N-K, W( K+1, K ), 1, A( K+1, K ), 1 )
  843. *
  844. * Set E( K ) to zero
  845. *
  846. IF( K.LT.N )
  847. $ E( K ) = CZERO
  848. *
  849. ELSE
  850. *
  851. * ============================================================
  852. *
  853. * BEGIN pivot search
  854. *
  855. * Case(1)
  856. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  857. * (used to handle NaN and Inf)
  858. *
  859. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  860. *
  861. * no interchange, use 1-by-1 pivot block
  862. *
  863. KP = K
  864. *
  865. ELSE
  866. *
  867. DONE = .FALSE.
  868. *
  869. * Loop until pivot found
  870. *
  871. 72 CONTINUE
  872. *
  873. * BEGIN pivot search loop body
  874. *
  875. *
  876. * Copy column IMAX to column k+1 of W and update it
  877. *
  878. CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
  879. CALL ZLACGV( IMAX-K, W( K, K+1 ), 1 )
  880. W( IMAX, K+1 ) = DBLE( A( IMAX, IMAX ) )
  881. *
  882. IF( IMAX.LT.N )
  883. $ CALL ZCOPY( N-IMAX, A( IMAX+1, IMAX ), 1,
  884. $ W( IMAX+1, K+1 ), 1 )
  885. *
  886. IF( K.GT.1 ) THEN
  887. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE,
  888. $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
  889. $ CONE, W( K, K+1 ), 1 )
  890. W( IMAX, K+1 ) = DBLE( W( IMAX, K+1 ) )
  891. END IF
  892. *
  893. * JMAX is the column-index of the largest off-diagonal
  894. * element in row IMAX, and ROWMAX is its absolute value.
  895. * Determine both ROWMAX and JMAX.
  896. *
  897. IF( IMAX.NE.K ) THEN
  898. JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
  899. ROWMAX = CABS1( W( JMAX, K+1 ) )
  900. ELSE
  901. ROWMAX = ZERO
  902. END IF
  903. *
  904. IF( IMAX.LT.N ) THEN
  905. ITEMP = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
  906. DTEMP = CABS1( W( ITEMP, K+1 ) )
  907. IF( DTEMP.GT.ROWMAX ) THEN
  908. ROWMAX = DTEMP
  909. JMAX = ITEMP
  910. END IF
  911. END IF
  912. *
  913. * Case(2)
  914. * Equivalent to testing for
  915. * ABS( DBLE( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX
  916. * (used to handle NaN and Inf)
  917. *
  918. IF( .NOT.( ABS( DBLE( W( IMAX,K+1 ) ) )
  919. $ .LT.ALPHA*ROWMAX ) ) THEN
  920. *
  921. * interchange rows and columns K and IMAX,
  922. * use 1-by-1 pivot block
  923. *
  924. KP = IMAX
  925. *
  926. * copy column K+1 of W to column K of W
  927. *
  928. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  929. *
  930. DONE = .TRUE.
  931. *
  932. * Case(3)
  933. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  934. * (used to handle NaN and Inf)
  935. *
  936. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  937. $ THEN
  938. *
  939. * interchange rows and columns K+1 and IMAX,
  940. * use 2-by-2 pivot block
  941. *
  942. KP = IMAX
  943. KSTEP = 2
  944. DONE = .TRUE.
  945. *
  946. * Case(4)
  947. ELSE
  948. *
  949. * Pivot not found: set params and repeat
  950. *
  951. P = IMAX
  952. COLMAX = ROWMAX
  953. IMAX = JMAX
  954. *
  955. * Copy updated JMAXth (next IMAXth) column to Kth of W
  956. *
  957. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  958. *
  959. END IF
  960. *
  961. *
  962. * End pivot search loop body
  963. *
  964. IF( .NOT.DONE ) GOTO 72
  965. *
  966. END IF
  967. *
  968. * END pivot search
  969. *
  970. * ============================================================
  971. *
  972. * KK is the column of A where pivoting step stopped
  973. *
  974. KK = K + KSTEP - 1
  975. *
  976. * Interchange rows and columns P and K (only for 2-by-2 pivot).
  977. * Updated column P is already stored in column K of W.
  978. *
  979. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  980. *
  981. * Copy non-updated column KK-1 to column P of submatrix A
  982. * at step K. No need to copy element into columns
  983. * K and K+1 of A for 2-by-2 pivot, since these columns
  984. * will be later overwritten.
  985. *
  986. A( P, P ) = DBLE( A( K, K ) )
  987. CALL ZCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA )
  988. CALL ZLACGV( P-K-1, A( P, K+1 ), LDA )
  989. IF( P.LT.N )
  990. $ CALL ZCOPY( N-P, A( P+1, K ), 1, A( P+1, P ), 1 )
  991. *
  992. * Interchange rows K and P in first K-1 columns of A
  993. * (columns K and K+1 of A for 2-by-2 pivot will be
  994. * later overwritten). Interchange rows K and P
  995. * in first KK columns of W.
  996. *
  997. IF( K.GT.1 )
  998. $ CALL ZSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA )
  999. CALL ZSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
  1000. END IF
  1001. *
  1002. * Interchange rows and columns KP and KK.
  1003. * Updated column KP is already stored in column KK of W.
  1004. *
  1005. IF( KP.NE.KK ) THEN
  1006. *
  1007. * Copy non-updated column KK to column KP of submatrix A
  1008. * at step K. No need to copy element into column K
  1009. * (or K and K+1 for 2-by-2 pivot) of A, since these columns
  1010. * will be later overwritten.
  1011. *
  1012. A( KP, KP ) = DBLE( A( KK, KK ) )
  1013. CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
  1014. $ LDA )
  1015. CALL ZLACGV( KP-KK-1, A( KP, KK+1 ), LDA )
  1016. IF( KP.LT.N )
  1017. $ CALL ZCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
  1018. *
  1019. * Interchange rows KK and KP in first K-1 columns of A
  1020. * (column K (or K and K+1 for 2-by-2 pivot) of A will be
  1021. * later overwritten). Interchange rows KK and KP
  1022. * in first KK columns of W.
  1023. *
  1024. IF( K.GT.1 )
  1025. $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
  1026. CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
  1027. END IF
  1028. *
  1029. IF( KSTEP.EQ.1 ) THEN
  1030. *
  1031. * 1-by-1 pivot block D(k): column k of W now holds
  1032. *
  1033. * W(k) = L(k)*D(k),
  1034. *
  1035. * where L(k) is the k-th column of L
  1036. *
  1037. * (1) Store subdiag. elements of column L(k)
  1038. * and 1-by-1 block D(k) in column k of A.
  1039. * (NOTE: Diagonal element L(k,k) is a UNIT element
  1040. * and not stored)
  1041. * A(k,k) := D(k,k) = W(k,k)
  1042. * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
  1043. *
  1044. * (NOTE: No need to use for Hermitian matrix
  1045. * A( K, K ) = DBLE( W( K, K) ) to separately copy diagonal
  1046. * element D(k,k) from W (potentially saves only one load))
  1047. CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  1048. IF( K.LT.N ) THEN
  1049. *
  1050. * (NOTE: No need to check if A(k,k) is NOT ZERO,
  1051. * since that was ensured earlier in pivot search:
  1052. * case A(k,k) = 0 falls into 2x2 pivot case(3))
  1053. *
  1054. * Handle division by a small number
  1055. *
  1056. T = DBLE( A( K, K ) )
  1057. IF( ABS( T ).GE.SFMIN ) THEN
  1058. R1 = ONE / T
  1059. CALL ZDSCAL( N-K, R1, A( K+1, K ), 1 )
  1060. ELSE
  1061. DO 74 II = K + 1, N
  1062. A( II, K ) = A( II, K ) / T
  1063. 74 CONTINUE
  1064. END IF
  1065. *
  1066. * (2) Conjugate column W(k)
  1067. *
  1068. CALL ZLACGV( N-K, W( K+1, K ), 1 )
  1069. *
  1070. * Store the subdiagonal element of D in array E
  1071. *
  1072. E( K ) = CZERO
  1073. *
  1074. END IF
  1075. *
  1076. ELSE
  1077. *
  1078. * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
  1079. *
  1080. * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
  1081. *
  1082. * where L(k) and L(k+1) are the k-th and (k+1)-th columns
  1083. * of L
  1084. *
  1085. * (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
  1086. * block D(k:k+1,k:k+1) in columns k and k+1 of A.
  1087. * NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
  1088. * block and not stored.
  1089. * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
  1090. * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
  1091. * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
  1092. *
  1093. IF( K.LT.N-1 ) THEN
  1094. *
  1095. * Factor out the columns of the inverse of 2-by-2 pivot
  1096. * block D, so that each column contains 1, to reduce the
  1097. * number of FLOPS when we multiply panel
  1098. * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
  1099. *
  1100. * D**(-1) = ( d11 cj(d21) )**(-1) =
  1101. * ( d21 d22 )
  1102. *
  1103. * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
  1104. * ( (-d21) ( d11 ) )
  1105. *
  1106. * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
  1107. *
  1108. * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
  1109. * ( ( -1 ) ( d11/conj(d21) ) )
  1110. *
  1111. * = 1/(|d21|**2) * 1/(D22*D11-1) *
  1112. *
  1113. * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  1114. * ( ( -1 ) ( D22 ) )
  1115. *
  1116. * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
  1117. * ( ( -1 ) ( D22 ) )
  1118. *
  1119. * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
  1120. * ( ( -1 ) ( D22 ) )
  1121. *
  1122. * Handle division by a small number. (NOTE: order of
  1123. * operations is important)
  1124. *
  1125. * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
  1126. * ( (( -1 ) ) (( D22 ) ) ),
  1127. *
  1128. * where D11 = d22/d21,
  1129. * D22 = d11/conj(d21),
  1130. * D21 = d21,
  1131. * T = 1/(D22*D11-1).
  1132. *
  1133. * (NOTE: No need to check for division by ZERO,
  1134. * since that was ensured earlier in pivot search:
  1135. * (a) d21 != 0 in 2x2 pivot case(4),
  1136. * since |d21| should be larger than |d11| and |d22|;
  1137. * (b) (D22*D11 - 1) != 0, since from (a),
  1138. * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
  1139. *
  1140. D21 = W( K+1, K )
  1141. D11 = W( K+1, K+1 ) / D21
  1142. D22 = W( K, K ) / DCONJG( D21 )
  1143. T = ONE / ( DBLE( D11*D22 )-ONE )
  1144. *
  1145. * Update elements in columns A(k) and A(k+1) as
  1146. * dot products of rows of ( W(k) W(k+1) ) and columns
  1147. * of D**(-1)
  1148. *
  1149. DO 80 J = K + 2, N
  1150. A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
  1151. $ DCONJG( D21 ) )
  1152. A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
  1153. $ D21 )
  1154. 80 CONTINUE
  1155. END IF
  1156. *
  1157. * Copy diagonal elements of D(K) to A,
  1158. * copy subdiagonal element of D(K) to E(K) and
  1159. * ZERO out subdiagonal entry of A
  1160. *
  1161. A( K, K ) = W( K, K )
  1162. A( K+1, K ) = CZERO
  1163. A( K+1, K+1 ) = W( K+1, K+1 )
  1164. E( K ) = W( K+1, K )
  1165. E( K+1 ) = CZERO
  1166. *
  1167. * (2) Conjugate columns W(k) and W(k+1)
  1168. *
  1169. CALL ZLACGV( N-K, W( K+1, K ), 1 )
  1170. CALL ZLACGV( N-K-1, W( K+2, K+1 ), 1 )
  1171. *
  1172. END IF
  1173. *
  1174. * End column K is nonsingular
  1175. *
  1176. END IF
  1177. *
  1178. * Store details of the interchanges in IPIV
  1179. *
  1180. IF( KSTEP.EQ.1 ) THEN
  1181. IPIV( K ) = KP
  1182. ELSE
  1183. IPIV( K ) = -P
  1184. IPIV( K+1 ) = -KP
  1185. END IF
  1186. *
  1187. * Increase K and return to the start of the main loop
  1188. *
  1189. K = K + KSTEP
  1190. GO TO 70
  1191. *
  1192. 90 CONTINUE
  1193. *
  1194. * Update the lower triangle of A22 (= A(k:n,k:n)) as
  1195. *
  1196. * A22 := A22 - L21*D*L21**H = A22 - L21*W**H
  1197. *
  1198. * computing blocks of NB columns at a time (note that conjg(W) is
  1199. * actually stored)
  1200. *
  1201. DO 110 J = K, N, NB
  1202. JB = MIN( NB, N-J+1 )
  1203. *
  1204. * Update the lower triangle of the diagonal block
  1205. *
  1206. DO 100 JJ = J, J + JB - 1
  1207. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  1208. CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
  1209. $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
  1210. $ A( JJ, JJ ), 1 )
  1211. A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
  1212. 100 CONTINUE
  1213. *
  1214. * Update the rectangular subdiagonal block
  1215. *
  1216. IF( J+JB.LE.N )
  1217. $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
  1218. $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
  1219. $ LDW, CONE, A( J+JB, J ), LDA )
  1220. 110 CONTINUE
  1221. *
  1222. * Set KB to the number of columns factorized
  1223. *
  1224. KB = K - 1
  1225. *
  1226. END IF
  1227. RETURN
  1228. *
  1229. * End of ZLAHEF_RK
  1230. *
  1231. END