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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974
  1. *> \brief \b ZLASYF_RK computes a partial factorization of a complex symmetric 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 ZLASYF_RK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlasyf_rk.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlasyf_rk.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlasyf_rk.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE ZLASYF_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. *> ZLASYF_RK computes a partial factorization of a complex symmetric
  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**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. *>
  51. *> ZLASYF_RK is an auxiliary routine called by ZSYTRF_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. *> symmetric 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 symmetric 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 symmetric 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 symmetric 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 symmetric 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. *> \date December 2016
  243. *
  244. *> \ingroup complex16SYcomputational
  245. *
  246. *> \par Contributors:
  247. * ==================
  248. *>
  249. *> \verbatim
  250. *>
  251. *> December 2016, Igor Kozachenko,
  252. *> Computer Science Division,
  253. *> University of California, Berkeley
  254. *>
  255. *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
  256. *> School of Mathematics,
  257. *> University of Manchester
  258. *>
  259. *> \endverbatim
  260. *
  261. * =====================================================================
  262. SUBROUTINE ZLASYF_RK( UPLO, N, NB, KB, A, LDA, E, IPIV, W, LDW,
  263. $ INFO )
  264. *
  265. * -- LAPACK computational routine (version 3.7.0) --
  266. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  267. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  268. * December 2016
  269. *
  270. * .. Scalar Arguments ..
  271. CHARACTER UPLO
  272. INTEGER INFO, KB, LDA, LDW, N, NB
  273. * ..
  274. * .. Array Arguments ..
  275. INTEGER IPIV( * )
  276. COMPLEX*16 A( LDA, * ), E( * ), W( LDW, * )
  277. * ..
  278. *
  279. * =====================================================================
  280. *
  281. * .. Parameters ..
  282. DOUBLE PRECISION ZERO, ONE
  283. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  284. DOUBLE PRECISION EIGHT, SEVTEN
  285. PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
  286. COMPLEX*16 CONE, CZERO
  287. PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ),
  288. $ CZERO = ( 0.0D+0, 0.0D+0 ) )
  289. * ..
  290. * .. Local Scalars ..
  291. LOGICAL DONE
  292. INTEGER IMAX, ITEMP, J, JB, JJ, JMAX, K, KK, KW, KKW,
  293. $ KP, KSTEP, P, II
  294. DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, ROWMAX, SFMIN, DTEMP
  295. COMPLEX*16 D11, D12, D21, D22, R1, T, Z
  296. * ..
  297. * .. External Functions ..
  298. LOGICAL LSAME
  299. INTEGER IZAMAX
  300. DOUBLE PRECISION DLAMCH
  301. EXTERNAL LSAME, IZAMAX, DLAMCH
  302. * ..
  303. * .. External Subroutines ..
  304. EXTERNAL ZCOPY, ZGEMM, ZGEMV, ZSCAL, ZSWAP
  305. * ..
  306. * .. Intrinsic Functions ..
  307. INTRINSIC ABS, DBLE, DIMAG, MAX, MIN, SQRT
  308. * ..
  309. * .. Statement Functions ..
  310. DOUBLE PRECISION CABS1
  311. * ..
  312. * .. Statement Function definitions ..
  313. CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
  314. * ..
  315. * .. Executable Statements ..
  316. *
  317. INFO = 0
  318. *
  319. * Initialize ALPHA for use in choosing pivot block size.
  320. *
  321. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  322. *
  323. * Compute machine safe minimum
  324. *
  325. SFMIN = DLAMCH( 'S' )
  326. *
  327. IF( LSAME( UPLO, 'U' ) ) THEN
  328. *
  329. * Factorize the trailing columns of A using the upper triangle
  330. * of A and working backwards, and compute the matrix W = U12*D
  331. * for use in updating A11
  332. *
  333. * Initialize the first entry of array E, where superdiagonal
  334. * elements of D are stored
  335. *
  336. E( 1 ) = CZERO
  337. *
  338. * K is the main loop index, decreasing from N in steps of 1 or 2
  339. *
  340. K = N
  341. 10 CONTINUE
  342. *
  343. * KW is the column of W which corresponds to column K of A
  344. *
  345. KW = NB + K - N
  346. *
  347. * Exit from loop
  348. *
  349. IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
  350. $ GO TO 30
  351. *
  352. KSTEP = 1
  353. P = K
  354. *
  355. * Copy column K of A to column KW of W and update it
  356. *
  357. CALL ZCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 )
  358. IF( K.LT.N )
  359. $ CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ),
  360. $ LDA, W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
  361. *
  362. * Determine rows and columns to be interchanged and whether
  363. * a 1-by-1 or 2-by-2 pivot block will be used
  364. *
  365. ABSAKK = CABS1( W( K, KW ) )
  366. *
  367. * IMAX is the row-index of the largest off-diagonal element in
  368. * column K, and COLMAX is its absolute value.
  369. * Determine both COLMAX and IMAX.
  370. *
  371. IF( K.GT.1 ) THEN
  372. IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
  373. COLMAX = CABS1( W( IMAX, KW ) )
  374. ELSE
  375. COLMAX = ZERO
  376. END IF
  377. *
  378. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  379. *
  380. * Column K is zero or underflow: set INFO and continue
  381. *
  382. IF( INFO.EQ.0 )
  383. $ INFO = K
  384. KP = K
  385. CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  386. *
  387. * Set E( K ) to zero
  388. *
  389. IF( K.GT.1 )
  390. $ E( K ) = CZERO
  391. *
  392. ELSE
  393. *
  394. * ============================================================
  395. *
  396. * Test for interchange
  397. *
  398. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  399. * (used to handle NaN and Inf)
  400. *
  401. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  402. *
  403. * no interchange, use 1-by-1 pivot block
  404. *
  405. KP = K
  406. *
  407. ELSE
  408. *
  409. DONE = .FALSE.
  410. *
  411. * Loop until pivot found
  412. *
  413. 12 CONTINUE
  414. *
  415. * Begin pivot search loop body
  416. *
  417. *
  418. * Copy column IMAX to column KW-1 of W and update it
  419. *
  420. CALL ZCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
  421. CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
  422. $ W( IMAX+1, KW-1 ), 1 )
  423. *
  424. IF( K.LT.N )
  425. $ CALL ZGEMV( 'No transpose', K, N-K, -CONE,
  426. $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
  427. $ CONE, W( 1, KW-1 ), 1 )
  428. *
  429. * JMAX is the column-index of the largest off-diagonal
  430. * element in row IMAX, and ROWMAX is its absolute value.
  431. * Determine both ROWMAX and JMAX.
  432. *
  433. IF( IMAX.NE.K ) THEN
  434. JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ),
  435. $ 1 )
  436. ROWMAX = CABS1( W( JMAX, KW-1 ) )
  437. ELSE
  438. ROWMAX = ZERO
  439. END IF
  440. *
  441. IF( IMAX.GT.1 ) THEN
  442. ITEMP = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
  443. DTEMP = CABS1( W( ITEMP, KW-1 ) )
  444. IF( DTEMP.GT.ROWMAX ) THEN
  445. ROWMAX = DTEMP
  446. JMAX = ITEMP
  447. END IF
  448. END IF
  449. *
  450. * Equivalent to testing for
  451. * CABS1( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX
  452. * (used to handle NaN and Inf)
  453. *
  454. IF( .NOT.(CABS1( W( IMAX, KW-1 ) ).LT.ALPHA*ROWMAX ) )
  455. $ THEN
  456. *
  457. * interchange rows and columns K and IMAX,
  458. * use 1-by-1 pivot block
  459. *
  460. KP = IMAX
  461. *
  462. * copy column KW-1 of W to column KW of W
  463. *
  464. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  465. *
  466. DONE = .TRUE.
  467. *
  468. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  469. * (used to handle NaN and Inf)
  470. *
  471. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  472. $ THEN
  473. *
  474. * interchange rows and columns K-1 and IMAX,
  475. * use 2-by-2 pivot block
  476. *
  477. KP = IMAX
  478. KSTEP = 2
  479. DONE = .TRUE.
  480. ELSE
  481. *
  482. * Pivot not found: set params and repeat
  483. *
  484. P = IMAX
  485. COLMAX = ROWMAX
  486. IMAX = JMAX
  487. *
  488. * Copy updated JMAXth (next IMAXth) column to Kth of W
  489. *
  490. CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  491. *
  492. END IF
  493. *
  494. * End pivot search loop body
  495. *
  496. IF( .NOT. DONE ) GOTO 12
  497. *
  498. END IF
  499. *
  500. * ============================================================
  501. *
  502. KK = K - KSTEP + 1
  503. *
  504. * KKW is the column of W which corresponds to column KK of A
  505. *
  506. KKW = NB + KK - N
  507. *
  508. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  509. *
  510. * Copy non-updated column K to column P
  511. *
  512. CALL ZCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA )
  513. CALL ZCOPY( P, A( 1, K ), 1, A( 1, P ), 1 )
  514. *
  515. * Interchange rows K and P in last N-K+1 columns of A
  516. * and last N-K+2 columns of W
  517. *
  518. CALL ZSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA )
  519. CALL ZSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW )
  520. END IF
  521. *
  522. * Updated column KP is already stored in column KKW of W
  523. *
  524. IF( KP.NE.KK ) THEN
  525. *
  526. * Copy non-updated column KK to column KP
  527. *
  528. A( KP, K ) = A( KK, K )
  529. CALL ZCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
  530. $ LDA )
  531. CALL ZCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 )
  532. *
  533. * Interchange rows KK and KP in last N-KK+1 columns
  534. * of A and W
  535. *
  536. CALL ZSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA )
  537. CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
  538. $ LDW )
  539. END IF
  540. *
  541. IF( KSTEP.EQ.1 ) THEN
  542. *
  543. * 1-by-1 pivot block D(k): column KW of W now holds
  544. *
  545. * W(k) = U(k)*D(k)
  546. *
  547. * where U(k) is the k-th column of U
  548. *
  549. * Store U(k) in column k of A
  550. *
  551. CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  552. IF( K.GT.1 ) THEN
  553. IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN
  554. R1 = CONE / A( K, K )
  555. CALL ZSCAL( K-1, R1, A( 1, K ), 1 )
  556. ELSE IF( A( K, K ).NE.CZERO ) THEN
  557. DO 14 II = 1, K - 1
  558. A( II, K ) = A( II, K ) / A( K, K )
  559. 14 CONTINUE
  560. END IF
  561. *
  562. * Store the superdiagonal element of D in array E
  563. *
  564. E( K ) = CZERO
  565. *
  566. END IF
  567. *
  568. ELSE
  569. *
  570. * 2-by-2 pivot block D(k): columns KW and KW-1 of W now
  571. * hold
  572. *
  573. * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
  574. *
  575. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  576. * of U
  577. *
  578. IF( K.GT.2 ) THEN
  579. *
  580. * Store U(k) and U(k-1) in columns k and k-1 of A
  581. *
  582. D12 = W( K-1, KW )
  583. D11 = W( K, KW ) / D12
  584. D22 = W( K-1, KW-1 ) / D12
  585. T = CONE / ( D11*D22-CONE )
  586. DO 20 J = 1, K - 2
  587. A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) /
  588. $ D12 )
  589. A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
  590. $ D12 )
  591. 20 CONTINUE
  592. END IF
  593. *
  594. * Copy diagonal elements of D(K) to A,
  595. * copy superdiagonal element of D(K) to E(K) and
  596. * ZERO out superdiagonal entry of A
  597. *
  598. A( K-1, K-1 ) = W( K-1, KW-1 )
  599. A( K-1, K ) = CZERO
  600. A( K, K ) = W( K, KW )
  601. E( K ) = W( K-1, KW )
  602. E( K-1 ) = CZERO
  603. *
  604. END IF
  605. *
  606. * End column K is nonsingular
  607. *
  608. END IF
  609. *
  610. * Store details of the interchanges in IPIV
  611. *
  612. IF( KSTEP.EQ.1 ) THEN
  613. IPIV( K ) = KP
  614. ELSE
  615. IPIV( K ) = -P
  616. IPIV( K-1 ) = -KP
  617. END IF
  618. *
  619. * Decrease K and return to the start of the main loop
  620. *
  621. K = K - KSTEP
  622. GO TO 10
  623. *
  624. 30 CONTINUE
  625. *
  626. * Update the upper triangle of A11 (= A(1:k,1:k)) as
  627. *
  628. * A11 := A11 - U12*D*U12**T = A11 - U12*W**T
  629. *
  630. * computing blocks of NB columns at a time
  631. *
  632. DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
  633. JB = MIN( NB, K-J+1 )
  634. *
  635. * Update the upper triangle of the diagonal block
  636. *
  637. DO 40 JJ = J, J + JB - 1
  638. CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
  639. $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
  640. $ A( J, JJ ), 1 )
  641. 40 CONTINUE
  642. *
  643. * Update the rectangular superdiagonal block
  644. *
  645. IF( J.GE.2 )
  646. $ CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB,
  647. $ N-K, -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ),
  648. $ LDW, CONE, A( 1, J ), LDA )
  649. 50 CONTINUE
  650. *
  651. * Set KB to the number of columns factorized
  652. *
  653. KB = N - K
  654. *
  655. ELSE
  656. *
  657. * Factorize the leading columns of A using the lower triangle
  658. * of A and working forwards, and compute the matrix W = L21*D
  659. * for use in updating A22
  660. *
  661. * Initialize the unused last entry of the subdiagonal array E.
  662. *
  663. E( N ) = CZERO
  664. *
  665. * K is the main loop index, increasing from 1 in steps of 1 or 2
  666. *
  667. K = 1
  668. 70 CONTINUE
  669. *
  670. * Exit from loop
  671. *
  672. IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
  673. $ GO TO 90
  674. *
  675. KSTEP = 1
  676. P = K
  677. *
  678. * Copy column K of A to column K of W and update it
  679. *
  680. CALL ZCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 )
  681. IF( K.GT.1 )
  682. $ CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
  683. $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 )
  684. *
  685. * Determine rows and columns to be interchanged and whether
  686. * a 1-by-1 or 2-by-2 pivot block will be used
  687. *
  688. ABSAKK = CABS1( W( K, K ) )
  689. *
  690. * IMAX is the row-index of the largest off-diagonal element in
  691. * column K, and COLMAX is its absolute value.
  692. * Determine both COLMAX and IMAX.
  693. *
  694. IF( K.LT.N ) THEN
  695. IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
  696. COLMAX = CABS1( W( IMAX, K ) )
  697. ELSE
  698. COLMAX = ZERO
  699. END IF
  700. *
  701. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  702. *
  703. * Column K is zero or underflow: set INFO and continue
  704. *
  705. IF( INFO.EQ.0 )
  706. $ INFO = K
  707. KP = K
  708. CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  709. *
  710. * Set E( K ) to zero
  711. *
  712. IF( K.LT.N )
  713. $ E( K ) = CZERO
  714. *
  715. ELSE
  716. *
  717. * ============================================================
  718. *
  719. * Test for interchange
  720. *
  721. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  722. * (used to handle NaN and Inf)
  723. *
  724. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  725. *
  726. * no interchange, use 1-by-1 pivot block
  727. *
  728. KP = K
  729. *
  730. ELSE
  731. *
  732. DONE = .FALSE.
  733. *
  734. * Loop until pivot found
  735. *
  736. 72 CONTINUE
  737. *
  738. * Begin pivot search loop body
  739. *
  740. *
  741. * Copy column IMAX to column K+1 of W and update it
  742. *
  743. CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
  744. CALL ZCOPY( N-IMAX+1, A( IMAX, IMAX ), 1,
  745. $ W( IMAX, K+1 ), 1 )
  746. IF( K.GT.1 )
  747. $ CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE,
  748. $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
  749. $ CONE, W( K, K+1 ), 1 )
  750. *
  751. * JMAX is the column-index of the largest off-diagonal
  752. * element in row IMAX, and ROWMAX is its absolute value.
  753. * Determine both ROWMAX and JMAX.
  754. *
  755. IF( IMAX.NE.K ) THEN
  756. JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
  757. ROWMAX = CABS1( W( JMAX, K+1 ) )
  758. ELSE
  759. ROWMAX = ZERO
  760. END IF
  761. *
  762. IF( IMAX.LT.N ) THEN
  763. ITEMP = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
  764. DTEMP = CABS1( W( ITEMP, K+1 ) )
  765. IF( DTEMP.GT.ROWMAX ) THEN
  766. ROWMAX = DTEMP
  767. JMAX = ITEMP
  768. END IF
  769. END IF
  770. *
  771. * Equivalent to testing for
  772. * CABS1( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX
  773. * (used to handle NaN and Inf)
  774. *
  775. IF( .NOT.( CABS1( W( IMAX, K+1 ) ).LT.ALPHA*ROWMAX ) )
  776. $ THEN
  777. *
  778. * interchange rows and columns K and IMAX,
  779. * use 1-by-1 pivot block
  780. *
  781. KP = IMAX
  782. *
  783. * copy column K+1 of W to column K of W
  784. *
  785. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  786. *
  787. DONE = .TRUE.
  788. *
  789. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  790. * (used to handle NaN and Inf)
  791. *
  792. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  793. $ THEN
  794. *
  795. * interchange rows and columns K+1 and IMAX,
  796. * use 2-by-2 pivot block
  797. *
  798. KP = IMAX
  799. KSTEP = 2
  800. DONE = .TRUE.
  801. ELSE
  802. *
  803. * Pivot not found: set params and repeat
  804. *
  805. P = IMAX
  806. COLMAX = ROWMAX
  807. IMAX = JMAX
  808. *
  809. * Copy updated JMAXth (next IMAXth) column to Kth of W
  810. *
  811. CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  812. *
  813. END IF
  814. *
  815. * End pivot search loop body
  816. *
  817. IF( .NOT. DONE ) GOTO 72
  818. *
  819. END IF
  820. *
  821. * ============================================================
  822. *
  823. KK = K + KSTEP - 1
  824. *
  825. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  826. *
  827. * Copy non-updated column K to column P
  828. *
  829. CALL ZCOPY( P-K, A( K, K ), 1, A( P, K ), LDA )
  830. CALL ZCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 )
  831. *
  832. * Interchange rows K and P in first K columns of A
  833. * and first K+1 columns of W
  834. *
  835. CALL ZSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA )
  836. CALL ZSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
  837. END IF
  838. *
  839. * Updated column KP is already stored in column KK of W
  840. *
  841. IF( KP.NE.KK ) THEN
  842. *
  843. * Copy non-updated column KK to column KP
  844. *
  845. A( KP, K ) = A( KK, K )
  846. CALL ZCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA )
  847. CALL ZCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 )
  848. *
  849. * Interchange rows KK and KP in first KK columns of A and W
  850. *
  851. CALL ZSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
  852. CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
  853. END IF
  854. *
  855. IF( KSTEP.EQ.1 ) THEN
  856. *
  857. * 1-by-1 pivot block D(k): column k of W now holds
  858. *
  859. * W(k) = L(k)*D(k)
  860. *
  861. * where L(k) is the k-th column of L
  862. *
  863. * Store L(k) in column k of A
  864. *
  865. CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  866. IF( K.LT.N ) THEN
  867. IF( CABS1( A( K, K ) ).GE.SFMIN ) THEN
  868. R1 = CONE / A( K, K )
  869. CALL ZSCAL( N-K, R1, A( K+1, K ), 1 )
  870. ELSE IF( A( K, K ).NE.CZERO ) THEN
  871. DO 74 II = K + 1, N
  872. A( II, K ) = A( II, K ) / A( K, K )
  873. 74 CONTINUE
  874. END IF
  875. *
  876. * Store the subdiagonal element of D in array E
  877. *
  878. E( K ) = CZERO
  879. *
  880. END IF
  881. *
  882. ELSE
  883. *
  884. * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
  885. *
  886. * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
  887. *
  888. * where L(k) and L(k+1) are the k-th and (k+1)-th columns
  889. * of L
  890. *
  891. IF( K.LT.N-1 ) THEN
  892. *
  893. * Store L(k) and L(k+1) in columns k and k+1 of A
  894. *
  895. D21 = W( K+1, K )
  896. D11 = W( K+1, K+1 ) / D21
  897. D22 = W( K, K ) / D21
  898. T = CONE / ( D11*D22-CONE )
  899. DO 80 J = K + 2, N
  900. A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
  901. $ D21 )
  902. A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
  903. $ D21 )
  904. 80 CONTINUE
  905. END IF
  906. *
  907. * Copy diagonal elements of D(K) to A,
  908. * copy subdiagonal element of D(K) to E(K) and
  909. * ZERO out subdiagonal entry of A
  910. *
  911. A( K, K ) = W( K, K )
  912. A( K+1, K ) = CZERO
  913. A( K+1, K+1 ) = W( K+1, K+1 )
  914. E( K ) = W( K+1, K )
  915. E( K+1 ) = CZERO
  916. *
  917. END IF
  918. *
  919. * End column K is nonsingular
  920. *
  921. END IF
  922. *
  923. * Store details of the interchanges in IPIV
  924. *
  925. IF( KSTEP.EQ.1 ) THEN
  926. IPIV( K ) = KP
  927. ELSE
  928. IPIV( K ) = -P
  929. IPIV( K+1 ) = -KP
  930. END IF
  931. *
  932. * Increase K and return to the start of the main loop
  933. *
  934. K = K + KSTEP
  935. GO TO 70
  936. *
  937. 90 CONTINUE
  938. *
  939. * Update the lower triangle of A22 (= A(k:n,k:n)) as
  940. *
  941. * A22 := A22 - L21*D*L21**T = A22 - L21*W**T
  942. *
  943. * computing blocks of NB columns at a time
  944. *
  945. DO 110 J = K, N, NB
  946. JB = MIN( NB, N-J+1 )
  947. *
  948. * Update the lower triangle of the diagonal block
  949. *
  950. DO 100 JJ = J, J + JB - 1
  951. CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
  952. $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
  953. $ A( JJ, JJ ), 1 )
  954. 100 CONTINUE
  955. *
  956. * Update the rectangular subdiagonal block
  957. *
  958. IF( J+JB.LE.N )
  959. $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
  960. $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
  961. $ LDW, CONE, A( J+JB, J ), LDA )
  962. 110 CONTINUE
  963. *
  964. * Set KB to the number of columns factorized
  965. *
  966. KB = K - 1
  967. *
  968. END IF
  969. *
  970. RETURN
  971. *
  972. * End of ZLASYF_RK
  973. *
  974. END