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.

zlasyf.f 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830
  1. *> \brief \b ZLASYF computes a partial factorization of a complex symmetric matrix using the Bunch-Kaufman 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 ZLASYF + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlasyf.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlasyf.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlasyf.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZLASYF( 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. *> ZLASYF computes a partial factorization of a complex symmetric matrix
  39. *> A using the Bunch-Kaufman diagonal pivoting method. The partial
  40. *> factorization has the form:
  41. *>
  42. *> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or:
  43. *> ( 0 U22 ) ( 0 D ) ( U12**T U22**T )
  44. *>
  45. *> A = ( L11 0 ) ( D 0 ) ( L11**T L21**T ) 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**T denotes the transpose of U.
  51. *>
  52. *> ZLASYF is an auxiliary routine called by ZSYTRF. 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. *> symmetric 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 symmetric 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. *> \date November 2013
  164. *
  165. *> \ingroup complex16SYcomputational
  166. *
  167. *> \par Contributors:
  168. * ==================
  169. *>
  170. *> \verbatim
  171. *>
  172. *> November 2013, Igor Kozachenko,
  173. *> Computer Science Division,
  174. *> University of California, Berkeley
  175. *> \endverbatim
  176. *
  177. * =====================================================================
  178. SUBROUTINE ZLASYF( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
  179. *
  180. * -- LAPACK computational routine (version 3.5.0) --
  181. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  182. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  183. * November 2013
  184. *
  185. * .. Scalar Arguments ..
  186. CHARACTER UPLO
  187. INTEGER INFO, KB, LDA, LDW, N, NB
  188. * ..
  189. * .. Array Arguments ..
  190. INTEGER IPIV( * )
  191. COMPLEX*16 A( LDA, * ), W( LDW, * )
  192. * ..
  193. *
  194. * =====================================================================
  195. *
  196. * .. Parameters ..
  197. DOUBLE PRECISION ZERO, ONE
  198. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  199. DOUBLE PRECISION EIGHT, SEVTEN
  200. PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
  201. COMPLEX*16 CONE
  202. PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
  203. * ..
  204. * .. Local Scalars ..
  205. INTEGER IMAX, J, JB, JJ, JMAX, JP, K, KK, KKW, KP,
  206. $ KSTEP, KW
  207. DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, ROWMAX
  208. COMPLEX*16 D11, D21, D22, R1, T, Z
  209. * ..
  210. * .. External Functions ..
  211. LOGICAL LSAME
  212. INTEGER IZAMAX
  213. EXTERNAL LSAME, IZAMAX
  214. * ..
  215. * .. External Subroutines ..
  216. EXTERNAL ZCOPY, ZGEMM, ZGEMV, ZSCAL, ZSWAP
  217. * ..
  218. * .. Intrinsic Functions ..
  219. INTRINSIC ABS, DBLE, DIMAG, MAX, MIN, SQRT
  220. * ..
  221. * .. Statement Functions ..
  222. DOUBLE PRECISION CABS1
  223. * ..
  224. * .. Statement Function definitions ..
  225. CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
  226. * ..
  227. * .. Executable Statements ..
  228. *
  229. INFO = 0
  230. *
  231. * Initialize ALPHA for use in choosing pivot block size.
  232. *
  233. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  234. *
  235. IF( LSAME( UPLO, 'U' ) ) THEN
  236. *
  237. * Factorize the trailing columns of A using the upper triangle
  238. * of A and working backwards, and compute the matrix W = U12*D
  239. * for use in updating A11
  240. *
  241. * K is the main loop index, decreasing from N in steps of 1 or 2
  242. *
  243. * KW is the column of W which corresponds to column K of A
  244. *
  245. K = N
  246. 10 CONTINUE
  247. KW = NB + K - N
  248. *
  249. * Exit from loop
  250. *
  251. IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
  252. $ GO TO 30
  253. *
  254. * Copy column K of A to column KW of W and update it
  255. *
  256. CALL ZCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 )
  257. IF( K.LT.N )
  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. *
  261. KSTEP = 1
  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 = CABS1( W( K, KW ) )
  267. *
  268. * IMAX is the row-index of the largest off-diagonal element in
  269. *
  270. IF( K.GT.1 ) THEN
  271. IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
  272. COLMAX = CABS1( W( IMAX, KW ) )
  273. ELSE
  274. COLMAX = ZERO
  275. END IF
  276. *
  277. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  278. *
  279. * Column K is zero or underflow: set INFO and continue
  280. *
  281. IF( INFO.EQ.0 )
  282. $ INFO = K
  283. KP = K
  284. ELSE
  285. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  286. *
  287. * no interchange, use 1-by-1 pivot block
  288. *
  289. KP = K
  290. ELSE
  291. *
  292. * Copy column IMAX to column KW-1 of W and update it
  293. *
  294. CALL ZCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
  295. CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
  296. $ W( IMAX+1, KW-1 ), 1 )
  297. IF( K.LT.N )
  298. $ CALL ZGEMV( 'No transpose', K, N-K, -CONE,
  299. $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
  300. $ CONE, W( 1, KW-1 ), 1 )
  301. *
  302. * JMAX is the column-index of the largest off-diagonal
  303. * element in row IMAX, and ROWMAX is its absolute value
  304. *
  305. JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ), 1 )
  306. ROWMAX = CABS1( W( JMAX, KW-1 ) )
  307. IF( IMAX.GT.1 ) THEN
  308. JMAX = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
  309. ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, KW-1 ) ) )
  310. END IF
  311. *
  312. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  313. *
  314. * no interchange, use 1-by-1 pivot block
  315. *
  316. KP = K
  317. ELSE IF( CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX ) THEN
  318. *
  319. * interchange rows and columns K and IMAX, use 1-by-1
  320. * pivot block
  321. *
  322. KP = IMAX
  323. *
  324. * copy column KW-1 of W to column KW of W
  325. *
  326. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  327. ELSE
  328. *
  329. * interchange rows and columns K-1 and IMAX, use 2-by-2
  330. * pivot block
  331. *
  332. KP = IMAX
  333. KSTEP = 2
  334. END IF
  335. END IF
  336. *
  337. * ============================================================
  338. *
  339. * KK is the column of A where pivoting step stopped
  340. *
  341. KK = K - KSTEP + 1
  342. *
  343. * KKW is the column of W which corresponds to column KK of A
  344. *
  345. KKW = NB + KK - N
  346. *
  347. * Interchange rows and columns KP and KK.
  348. * Updated column KP is already stored in column KKW of W.
  349. *
  350. IF( KP.NE.KK ) THEN
  351. *
  352. * Copy non-updated column KK to column KP of submatrix A
  353. * at step K. No need to copy element into column K
  354. * (or K and K-1 for 2-by-2 pivot) of A, since these columns
  355. * will be later overwritten.
  356. *
  357. A( KP, KP ) = A( KK, KK )
  358. CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
  359. $ LDA )
  360. IF( KP.GT.1 )
  361. $ CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
  362. *
  363. * Interchange rows KK and KP in last K+1 to N columns of A
  364. * (columns K (or K and K-1 for 2-by-2 pivot) of A will be
  365. * later overwritten). Interchange rows KK and KP
  366. * in last KKW to NB columns of W.
  367. *
  368. IF( K.LT.N )
  369. $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
  370. $ LDA )
  371. CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
  372. $ LDW )
  373. END IF
  374. *
  375. IF( KSTEP.EQ.1 ) THEN
  376. *
  377. * 1-by-1 pivot block D(k): column kw of W now holds
  378. *
  379. * W(kw) = U(k)*D(k),
  380. *
  381. * where U(k) is the k-th column of U
  382. *
  383. * Store subdiag. elements of column U(k)
  384. * and 1-by-1 block D(k) in column k of A.
  385. * NOTE: Diagonal element U(k,k) is a UNIT element
  386. * and not stored.
  387. * A(k,k) := D(k,k) = W(k,kw)
  388. * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
  389. *
  390. CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  391. R1 = CONE / A( K, K )
  392. CALL ZSCAL( K-1, R1, A( 1, K ), 1 )
  393. *
  394. ELSE
  395. *
  396. * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
  397. *
  398. * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
  399. *
  400. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  401. * of U
  402. *
  403. * Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
  404. * block D(k-1:k,k-1:k) in columns k-1 and k of A.
  405. * NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
  406. * block and not stored.
  407. * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
  408. * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
  409. * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
  410. *
  411. IF( K.GT.2 ) THEN
  412. *
  413. * Compose the columns of the inverse of 2-by-2 pivot
  414. * block D in the following way to reduce the number
  415. * of FLOPS when we myltiply panel ( W(kw-1) W(kw) ) by
  416. * this inverse
  417. *
  418. * D**(-1) = ( d11 d21 )**(-1) =
  419. * ( d21 d22 )
  420. *
  421. * = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) =
  422. * ( (-d21 ) ( d11 ) )
  423. *
  424. * = 1/d21 * 1/((d11/d21)*(d22/d21)-1) *
  425. *
  426. * * ( ( d22/d21 ) ( -1 ) ) =
  427. * ( ( -1 ) ( d11/d21 ) )
  428. *
  429. * = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) ( -1 ) ) =
  430. * ( ( -1 ) ( D22 ) )
  431. *
  432. * = 1/d21 * T * ( ( D11 ) ( -1 ) )
  433. * ( ( -1 ) ( D22 ) )
  434. *
  435. * = D21 * ( ( D11 ) ( -1 ) )
  436. * ( ( -1 ) ( D22 ) )
  437. *
  438. D21 = W( K-1, KW )
  439. D11 = W( K, KW ) / D21
  440. D22 = W( K-1, KW-1 ) / D21
  441. T = CONE / ( D11*D22-CONE )
  442. D21 = T / D21
  443. *
  444. * Update elements in columns A(k-1) and A(k) as
  445. * dot products of rows of ( W(kw-1) W(kw) ) and columns
  446. * of D**(-1)
  447. *
  448. DO 20 J = 1, K - 2
  449. A( J, K-1 ) = D21*( D11*W( J, KW-1 )-W( J, KW ) )
  450. A( J, K ) = D21*( D22*W( J, KW )-W( J, KW-1 ) )
  451. 20 CONTINUE
  452. END IF
  453. *
  454. * Copy D(k) to A
  455. *
  456. A( K-1, K-1 ) = W( K-1, KW-1 )
  457. A( K-1, K ) = W( K-1, KW )
  458. A( K, K ) = W( K, KW )
  459. *
  460. END IF
  461. *
  462. END IF
  463. *
  464. * Store details of the interchanges in IPIV
  465. *
  466. IF( KSTEP.EQ.1 ) THEN
  467. IPIV( K ) = KP
  468. ELSE
  469. IPIV( K ) = -KP
  470. IPIV( K-1 ) = -KP
  471. END IF
  472. *
  473. * Decrease K and return to the start of the main loop
  474. *
  475. K = K - KSTEP
  476. GO TO 10
  477. *
  478. 30 CONTINUE
  479. *
  480. * Update the upper triangle of A11 (= A(1:k,1:k)) as
  481. *
  482. * A11 := A11 - U12*D*U12**T = A11 - U12*W**T
  483. *
  484. * computing blocks of NB columns at a time
  485. *
  486. DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
  487. JB = MIN( NB, K-J+1 )
  488. *
  489. * Update the upper triangle of the diagonal block
  490. *
  491. DO 40 JJ = J, J + JB - 1
  492. CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
  493. $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
  494. $ A( J, JJ ), 1 )
  495. 40 CONTINUE
  496. *
  497. * Update the rectangular superdiagonal block
  498. *
  499. CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
  500. $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
  501. $ CONE, A( 1, J ), LDA )
  502. 50 CONTINUE
  503. *
  504. * Put U12 in standard form by partially undoing the interchanges
  505. * in columns k+1:n looping backwards from k+1 to n
  506. *
  507. J = K + 1
  508. 60 CONTINUE
  509. *
  510. * Undo the interchanges (if any) of rows JJ and JP at each
  511. * step J
  512. *
  513. * (Here, J is a diagonal index)
  514. JJ = J
  515. JP = IPIV( J )
  516. IF( JP.LT.0 ) THEN
  517. JP = -JP
  518. * (Here, J is a diagonal index)
  519. J = J + 1
  520. END IF
  521. * (NOTE: Here, J is used to determine row length. Length N-J+1
  522. * of the rows to swap back doesn't include diagonal element)
  523. J = J + 1
  524. IF( JP.NE.JJ .AND. J.LE.N )
  525. $ CALL ZSWAP( N-J+1, A( JP, J ), LDA, A( JJ, J ), LDA )
  526. IF( J.LT.N )
  527. $ GO TO 60
  528. *
  529. * Set KB to the number of columns factorized
  530. *
  531. KB = N - K
  532. *
  533. ELSE
  534. *
  535. * Factorize the leading columns of A using the lower triangle
  536. * of A and working forwards, and compute the matrix W = L21*D
  537. * for use in updating A22
  538. *
  539. * K is the main loop index, increasing from 1 in steps of 1 or 2
  540. *
  541. K = 1
  542. 70 CONTINUE
  543. *
  544. * Exit from loop
  545. *
  546. IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
  547. $ GO TO 90
  548. *
  549. * Copy column K of A to column K of W and update it
  550. *
  551. CALL ZCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 )
  552. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ), LDA,
  553. $ W( K, 1 ), LDW, CONE, W( K, K ), 1 )
  554. *
  555. KSTEP = 1
  556. *
  557. * Determine rows and columns to be interchanged and whether
  558. * a 1-by-1 or 2-by-2 pivot block will be used
  559. *
  560. ABSAKK = CABS1( W( K, K ) )
  561. *
  562. * IMAX is the row-index of the largest off-diagonal element in
  563. *
  564. IF( K.LT.N ) THEN
  565. IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
  566. COLMAX = CABS1( W( IMAX, K ) )
  567. ELSE
  568. COLMAX = ZERO
  569. END IF
  570. *
  571. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  572. *
  573. * Column K is zero or underflow: set INFO and continue
  574. *
  575. IF( INFO.EQ.0 )
  576. $ INFO = K
  577. KP = K
  578. ELSE
  579. IF( ABSAKK.GE.ALPHA*COLMAX ) THEN
  580. *
  581. * no interchange, use 1-by-1 pivot block
  582. *
  583. KP = K
  584. ELSE
  585. *
  586. * Copy column IMAX to column K+1 of W and update it
  587. *
  588. CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1 )
  589. CALL ZCOPY( N-IMAX+1, A( IMAX, IMAX ), 1, W( IMAX, K+1 ),
  590. $ 1 )
  591. CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
  592. $ LDA, W( IMAX, 1 ), LDW, CONE, W( K, K+1 ),
  593. $ 1 )
  594. *
  595. * JMAX is the column-index of the largest off-diagonal
  596. * element in row IMAX, and ROWMAX is its absolute value
  597. *
  598. JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
  599. ROWMAX = CABS1( W( JMAX, K+1 ) )
  600. IF( IMAX.LT.N ) THEN
  601. JMAX = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1 )
  602. ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, K+1 ) ) )
  603. END IF
  604. *
  605. IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
  606. *
  607. * no interchange, use 1-by-1 pivot block
  608. *
  609. KP = K
  610. ELSE IF( CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX ) THEN
  611. *
  612. * interchange rows and columns K and IMAX, use 1-by-1
  613. * pivot block
  614. *
  615. KP = IMAX
  616. *
  617. * copy column K+1 of W to column K of W
  618. *
  619. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  620. ELSE
  621. *
  622. * interchange rows and columns K+1 and IMAX, use 2-by-2
  623. * pivot block
  624. *
  625. KP = IMAX
  626. KSTEP = 2
  627. END IF
  628. END IF
  629. *
  630. * ============================================================
  631. *
  632. * KK is the column of A where pivoting step stopped
  633. *
  634. KK = K + KSTEP - 1
  635. *
  636. * Interchange rows and columns KP and KK.
  637. * Updated column KP is already stored in column KK of W.
  638. *
  639. IF( KP.NE.KK ) THEN
  640. *
  641. * Copy non-updated column KK to column KP of submatrix A
  642. * at step K. No need to copy element into column K
  643. * (or K and K+1 for 2-by-2 pivot) of A, since these columns
  644. * will be later overwritten.
  645. *
  646. A( KP, KP ) = A( KK, KK )
  647. CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
  648. $ LDA )
  649. IF( KP.LT.N )
  650. $ CALL ZCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
  651. *
  652. * Interchange rows KK and KP in first K-1 columns of A
  653. * (columns K (or K and K+1 for 2-by-2 pivot) of A will be
  654. * later overwritten). Interchange rows KK and KP
  655. * in first KK columns of W.
  656. *
  657. IF( K.GT.1 )
  658. $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
  659. CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
  660. END IF
  661. *
  662. IF( KSTEP.EQ.1 ) THEN
  663. *
  664. * 1-by-1 pivot block D(k): column k of W now holds
  665. *
  666. * W(k) = L(k)*D(k),
  667. *
  668. * where L(k) is the k-th column of L
  669. *
  670. * Store subdiag. elements of column L(k)
  671. * and 1-by-1 block D(k) in column k of A.
  672. * (NOTE: Diagonal element L(k,k) is a UNIT element
  673. * and not stored)
  674. * A(k,k) := D(k,k) = W(k,k)
  675. * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
  676. *
  677. CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  678. IF( K.LT.N ) THEN
  679. R1 = CONE / A( K, K )
  680. CALL ZSCAL( N-K, R1, A( K+1, K ), 1 )
  681. END IF
  682. *
  683. ELSE
  684. *
  685. * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
  686. *
  687. * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
  688. *
  689. * where L(k) and L(k+1) are the k-th and (k+1)-th columns
  690. * of L
  691. *
  692. * Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
  693. * block D(k:k+1,k:k+1) in columns k and k+1 of A.
  694. * (NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
  695. * block and not stored)
  696. * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
  697. * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
  698. * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
  699. *
  700. IF( K.LT.N-1 ) THEN
  701. *
  702. * Compose the columns of the inverse of 2-by-2 pivot
  703. * block D in the following way to reduce the number
  704. * of FLOPS when we myltiply panel ( W(k) W(k+1) ) by
  705. * this inverse
  706. *
  707. * D**(-1) = ( d11 d21 )**(-1) =
  708. * ( d21 d22 )
  709. *
  710. * = 1/(d11*d22-d21**2) * ( ( d22 ) (-d21 ) ) =
  711. * ( (-d21 ) ( d11 ) )
  712. *
  713. * = 1/d21 * 1/((d11/d21)*(d22/d21)-1) *
  714. *
  715. * * ( ( d22/d21 ) ( -1 ) ) =
  716. * ( ( -1 ) ( d11/d21 ) )
  717. *
  718. * = 1/d21 * 1/(D22*D11-1) * ( ( D11 ) ( -1 ) ) =
  719. * ( ( -1 ) ( D22 ) )
  720. *
  721. * = 1/d21 * T * ( ( D11 ) ( -1 ) )
  722. * ( ( -1 ) ( D22 ) )
  723. *
  724. * = D21 * ( ( D11 ) ( -1 ) )
  725. * ( ( -1 ) ( D22 ) )
  726. *
  727. D21 = W( K+1, K )
  728. D11 = W( K+1, K+1 ) / D21
  729. D22 = W( K, K ) / D21
  730. T = CONE / ( D11*D22-CONE )
  731. D21 = T / D21
  732. *
  733. * Update elements in columns A(k) and A(k+1) as
  734. * dot products of rows of ( W(k) W(k+1) ) and columns
  735. * of D**(-1)
  736. *
  737. DO 80 J = K + 2, N
  738. A( J, K ) = D21*( D11*W( J, K )-W( J, K+1 ) )
  739. A( J, K+1 ) = D21*( D22*W( J, K+1 )-W( J, K ) )
  740. 80 CONTINUE
  741. END IF
  742. *
  743. * Copy D(k) to A
  744. *
  745. A( K, K ) = W( K, K )
  746. A( K+1, K ) = W( K+1, K )
  747. A( K+1, K+1 ) = W( K+1, K+1 )
  748. *
  749. END IF
  750. *
  751. END IF
  752. *
  753. * Store details of the interchanges in IPIV
  754. *
  755. IF( KSTEP.EQ.1 ) THEN
  756. IPIV( K ) = KP
  757. ELSE
  758. IPIV( K ) = -KP
  759. IPIV( K+1 ) = -KP
  760. END IF
  761. *
  762. * Increase K and return to the start of the main loop
  763. *
  764. K = K + KSTEP
  765. GO TO 70
  766. *
  767. 90 CONTINUE
  768. *
  769. * Update the lower triangle of A22 (= A(k:n,k:n)) as
  770. *
  771. * A22 := A22 - L21*D*L21**T = A22 - L21*W**T
  772. *
  773. * computing blocks of NB columns at a time
  774. *
  775. DO 110 J = K, N, NB
  776. JB = MIN( NB, N-J+1 )
  777. *
  778. * Update the lower triangle of the diagonal block
  779. *
  780. DO 100 JJ = J, J + JB - 1
  781. CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
  782. $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
  783. $ A( JJ, JJ ), 1 )
  784. 100 CONTINUE
  785. *
  786. * Update the rectangular subdiagonal block
  787. *
  788. IF( J+JB.LE.N )
  789. $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
  790. $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
  791. $ LDW, CONE, A( J+JB, J ), LDA )
  792. 110 CONTINUE
  793. *
  794. * Put L21 in standard form by partially undoing the interchanges
  795. * of rows in columns 1:k-1 looping backwards from k-1 to 1
  796. *
  797. J = K - 1
  798. 120 CONTINUE
  799. *
  800. * Undo the interchanges (if any) of rows JJ and JP at each
  801. * step J
  802. *
  803. * (Here, J is a diagonal index)
  804. JJ = J
  805. JP = IPIV( J )
  806. IF( JP.LT.0 ) THEN
  807. JP = -JP
  808. * (Here, J is a diagonal index)
  809. J = J - 1
  810. END IF
  811. * (NOTE: Here, J is used to determine row length. Length J
  812. * of the rows to swap back doesn't include diagonal element)
  813. J = J - 1
  814. IF( JP.NE.JJ .AND. J.GE.1 )
  815. $ CALL ZSWAP( J, A( JP, 1 ), LDA, A( JJ, 1 ), LDA )
  816. IF( J.GT.1 )
  817. $ GO TO 120
  818. *
  819. * Set KB to the number of columns factorized
  820. *
  821. KB = K - 1
  822. *
  823. END IF
  824. RETURN
  825. *
  826. * End of ZLASYF
  827. *
  828. END