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.

dlasyf_rook.f 27 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892
  1. *> \brief \b DLASYF_ROOK *> DLASYF_ROOK computes a partial factorization of a real symmetric matrix using the 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 DLASYF_ROOK + dependencies
  10. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/dlasyf_rook.f">
  11. *> [TGZ]</a>
  12. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/dlasyf_rook.f">
  13. *> [ZIP]</a>
  14. *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/dlasyf_rook.f">
  15. *> [TXT]</a>
  16. *> \endhtmlonly
  17. *
  18. * Definition:
  19. * ===========
  20. *
  21. * SUBROUTINE DLASYF_ROOK( 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. * DOUBLE PRECISION A( LDA, * ), W( LDW, * )
  30. * ..
  31. *
  32. *
  33. *> \par Purpose:
  34. * =============
  35. *>
  36. *> \verbatim
  37. *>
  38. *> DLASYF_ROOK computes a partial factorization of a real 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. *> DLASYF_ROOK is an auxiliary routine called by DSYTRF_ROOK. 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 DOUBLE PRECISION array, dimension (LDA,N)
  92. *> On entry, the symmetric matrix A. If UPLO = 'U', the leading
  93. *> n-by-n upper triangular part of A contains the upper
  94. *> triangular part of the matrix A, and the strictly lower
  95. *> triangular part of A is not referenced. If UPLO = 'L', the
  96. *> leading n-by-n lower triangular part of A contains the lower
  97. *> triangular part of the matrix A, and the strictly upper
  98. *> triangular part of A is not referenced.
  99. *> On exit, A contains details of the partial factorization.
  100. *> \endverbatim
  101. *>
  102. *> \param[in] LDA
  103. *> \verbatim
  104. *> LDA is INTEGER
  105. *> The leading dimension of the array A. LDA >= max(1,N).
  106. *> \endverbatim
  107. *>
  108. *> \param[out] IPIV
  109. *> \verbatim
  110. *> IPIV is INTEGER array, dimension (N)
  111. *> Details of the interchanges and the block structure of D.
  112. *>
  113. *> If UPLO = 'U':
  114. *> Only the last KB elements of IPIV are set.
  115. *>
  116. *> If IPIV(k) > 0, then rows and columns k and IPIV(k) were
  117. *> interchanged and D(k,k) is a 1-by-1 diagonal block.
  118. *>
  119. *> If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
  120. *> columns k and -IPIV(k) were interchanged and rows and
  121. *> columns k-1 and -IPIV(k-1) were inerchaged,
  122. *> D(k-1:k,k-1:k) 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)
  128. *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
  129. *>
  130. *> If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
  131. *> columns k and -IPIV(k) were interchanged and rows and
  132. *> columns k+1 and -IPIV(k+1) were inerchaged,
  133. *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
  134. *> \endverbatim
  135. *>
  136. *> \param[out] W
  137. *> \verbatim
  138. *> W is DOUBLE PRECISION array, dimension (LDW,NB)
  139. *> \endverbatim
  140. *>
  141. *> \param[in] LDW
  142. *> \verbatim
  143. *> LDW is INTEGER
  144. *> The leading dimension of the array W. LDW >= max(1,N).
  145. *> \endverbatim
  146. *>
  147. *> \param[out] INFO
  148. *> \verbatim
  149. *> INFO is INTEGER
  150. *> = 0: successful exit
  151. *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
  152. *> has been completed, but the block diagonal matrix D is
  153. *> exactly singular.
  154. *> \endverbatim
  155. *
  156. * Authors:
  157. * ========
  158. *
  159. *> \author Univ. of Tennessee
  160. *> \author Univ. of California Berkeley
  161. *> \author Univ. of Colorado Denver
  162. *> \author NAG Ltd.
  163. *
  164. *> \date November 2013
  165. *
  166. *> \ingroup doubleSYcomputational
  167. *
  168. *> \par Contributors:
  169. * ==================
  170. *>
  171. *> \verbatim
  172. *>
  173. *> November 2013, Igor Kozachenko,
  174. *> Computer Science Division,
  175. *> University of California, Berkeley
  176. *>
  177. *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
  178. *> School of Mathematics,
  179. *> University of Manchester
  180. *>
  181. *> \endverbatim
  182. *
  183. * =====================================================================
  184. SUBROUTINE DLASYF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW,
  185. $ INFO )
  186. *
  187. * -- LAPACK computational routine (version 3.5.0) --
  188. * -- LAPACK is a software package provided by Univ. of Tennessee, --
  189. * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
  190. * November 2013
  191. *
  192. * .. Scalar Arguments ..
  193. CHARACTER UPLO
  194. INTEGER INFO, KB, LDA, LDW, N, NB
  195. * ..
  196. * .. Array Arguments ..
  197. INTEGER IPIV( * )
  198. DOUBLE PRECISION A( LDA, * ), W( LDW, * )
  199. * ..
  200. *
  201. * =====================================================================
  202. *
  203. * .. Parameters ..
  204. DOUBLE PRECISION ZERO, ONE
  205. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  206. DOUBLE PRECISION EIGHT, SEVTEN
  207. PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
  208. * ..
  209. * .. Local Scalars ..
  210. LOGICAL DONE
  211. INTEGER IMAX, ITEMP, J, JB, JJ, JMAX, JP1, JP2, K, KK,
  212. $ KW, KKW, KP, KSTEP, P, II
  213. DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, D11, D12, D21, D22,
  214. $ DTEMP, R1, ROWMAX, T, SFMIN
  215. * ..
  216. * .. External Functions ..
  217. LOGICAL LSAME
  218. INTEGER IDAMAX
  219. DOUBLE PRECISION DLAMCH
  220. EXTERNAL LSAME, IDAMAX, DLAMCH
  221. * ..
  222. * .. External Subroutines ..
  223. EXTERNAL DCOPY, DGEMM, DGEMV, DSCAL, DSWAP
  224. * ..
  225. * .. Intrinsic Functions ..
  226. INTRINSIC ABS, MAX, MIN, SQRT
  227. * ..
  228. * .. Executable Statements ..
  229. *
  230. INFO = 0
  231. *
  232. * Initialize ALPHA for use in choosing pivot block size.
  233. *
  234. ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
  235. *
  236. * Compute machine safe minimum
  237. *
  238. SFMIN = DLAMCH( 'S' )
  239. *
  240. IF( LSAME( UPLO, 'U' ) ) THEN
  241. *
  242. * Factorize the trailing columns of A using the upper triangle
  243. * of A and working backwards, and compute the matrix W = U12*D
  244. * for use in updating A11
  245. *
  246. * K is the main loop index, decreasing from N in steps of 1 or 2
  247. *
  248. K = N
  249. 10 CONTINUE
  250. *
  251. * KW is the column of W which corresponds to column K of A
  252. *
  253. KW = NB + K - N
  254. *
  255. * Exit from loop
  256. *
  257. IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
  258. $ GO TO 30
  259. *
  260. KSTEP = 1
  261. P = K
  262. *
  263. * Copy column K of A to column KW of W and update it
  264. *
  265. CALL DCOPY( K, A( 1, K ), 1, W( 1, KW ), 1 )
  266. IF( K.LT.N )
  267. $ CALL DGEMV( 'No transpose', K, N-K, -ONE, A( 1, K+1 ),
  268. $ LDA, W( K, KW+1 ), LDW, ONE, W( 1, KW ), 1 )
  269. *
  270. * Determine rows and columns to be interchanged and whether
  271. * a 1-by-1 or 2-by-2 pivot block will be used
  272. *
  273. ABSAKK = ABS( W( K, KW ) )
  274. *
  275. * IMAX is the row-index of the largest off-diagonal element in
  276. * column K, and COLMAX is its absolute value.
  277. * Determine both COLMAX and IMAX.
  278. *
  279. IF( K.GT.1 ) THEN
  280. IMAX = IDAMAX( K-1, W( 1, KW ), 1 )
  281. COLMAX = ABS( W( IMAX, KW ) )
  282. ELSE
  283. COLMAX = ZERO
  284. END IF
  285. *
  286. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  287. *
  288. * Column K is zero or underflow: set INFO and continue
  289. *
  290. IF( INFO.EQ.0 )
  291. $ INFO = K
  292. KP = K
  293. CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  294. ELSE
  295. *
  296. * ============================================================
  297. *
  298. * Test for interchange
  299. *
  300. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  301. * (used to handle NaN and Inf)
  302. *
  303. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  304. *
  305. * no interchange, use 1-by-1 pivot block
  306. *
  307. KP = K
  308. *
  309. ELSE
  310. *
  311. DONE = .FALSE.
  312. *
  313. * Loop until pivot found
  314. *
  315. 12 CONTINUE
  316. *
  317. * Begin pivot search loop body
  318. *
  319. *
  320. * Copy column IMAX to column KW-1 of W and update it
  321. *
  322. CALL DCOPY( IMAX, A( 1, IMAX ), 1, W( 1, KW-1 ), 1 )
  323. CALL DCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
  324. $ W( IMAX+1, KW-1 ), 1 )
  325. *
  326. IF( K.LT.N )
  327. $ CALL DGEMV( 'No transpose', K, N-K, -ONE,
  328. $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
  329. $ ONE, W( 1, KW-1 ), 1 )
  330. *
  331. * JMAX is the column-index of the largest off-diagonal
  332. * element in row IMAX, and ROWMAX is its absolute value.
  333. * Determine both ROWMAX and JMAX.
  334. *
  335. IF( IMAX.NE.K ) THEN
  336. JMAX = IMAX + IDAMAX( K-IMAX, W( IMAX+1, KW-1 ),
  337. $ 1 )
  338. ROWMAX = ABS( W( JMAX, KW-1 ) )
  339. ELSE
  340. ROWMAX = ZERO
  341. END IF
  342. *
  343. IF( IMAX.GT.1 ) THEN
  344. ITEMP = IDAMAX( IMAX-1, W( 1, KW-1 ), 1 )
  345. DTEMP = ABS( W( ITEMP, KW-1 ) )
  346. IF( DTEMP.GT.ROWMAX ) THEN
  347. ROWMAX = DTEMP
  348. JMAX = ITEMP
  349. END IF
  350. END IF
  351. *
  352. * Equivalent to testing for
  353. * ABS( W( IMAX, KW-1 ) ).GE.ALPHA*ROWMAX
  354. * (used to handle NaN and Inf)
  355. *
  356. IF( .NOT.(ABS( W( IMAX, KW-1 ) ).LT.ALPHA*ROWMAX ) )
  357. $ THEN
  358. *
  359. * interchange rows and columns K and IMAX,
  360. * use 1-by-1 pivot block
  361. *
  362. KP = IMAX
  363. *
  364. * copy column KW-1 of W to column KW of W
  365. *
  366. CALL DCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  367. *
  368. DONE = .TRUE.
  369. *
  370. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  371. * (used to handle NaN and Inf)
  372. *
  373. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  374. $ THEN
  375. *
  376. * interchange rows and columns K-1 and IMAX,
  377. * use 2-by-2 pivot block
  378. *
  379. KP = IMAX
  380. KSTEP = 2
  381. DONE = .TRUE.
  382. ELSE
  383. *
  384. * Pivot not found: set params and repeat
  385. *
  386. P = IMAX
  387. COLMAX = ROWMAX
  388. IMAX = JMAX
  389. *
  390. * Copy updated JMAXth (next IMAXth) column to Kth of W
  391. *
  392. CALL DCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
  393. *
  394. END IF
  395. *
  396. * End pivot search loop body
  397. *
  398. IF( .NOT. DONE ) GOTO 12
  399. *
  400. END IF
  401. *
  402. * ============================================================
  403. *
  404. KK = K - KSTEP + 1
  405. *
  406. * KKW is the column of W which corresponds to column KK of A
  407. *
  408. KKW = NB + KK - N
  409. *
  410. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  411. *
  412. * Copy non-updated column K to column P
  413. *
  414. CALL DCOPY( K-P, A( P+1, K ), 1, A( P, P+1 ), LDA )
  415. CALL DCOPY( P, A( 1, K ), 1, A( 1, P ), 1 )
  416. *
  417. * Interchange rows K and P in last N-K+1 columns of A
  418. * and last N-K+2 columns of W
  419. *
  420. CALL DSWAP( N-K+1, A( K, K ), LDA, A( P, K ), LDA )
  421. CALL DSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ), LDW )
  422. END IF
  423. *
  424. * Updated column KP is already stored in column KKW of W
  425. *
  426. IF( KP.NE.KK ) THEN
  427. *
  428. * Copy non-updated column KK to column KP
  429. *
  430. A( KP, K ) = A( KK, K )
  431. CALL DCOPY( K-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
  432. $ LDA )
  433. CALL DCOPY( KP, A( 1, KK ), 1, A( 1, KP ), 1 )
  434. *
  435. * Interchange rows KK and KP in last N-KK+1 columns
  436. * of A and W
  437. *
  438. CALL DSWAP( N-KK+1, A( KK, KK ), LDA, A( KP, KK ), LDA )
  439. CALL DSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
  440. $ LDW )
  441. END IF
  442. *
  443. IF( KSTEP.EQ.1 ) THEN
  444. *
  445. * 1-by-1 pivot block D(k): column KW of W now holds
  446. *
  447. * W(k) = U(k)*D(k)
  448. *
  449. * where U(k) is the k-th column of U
  450. *
  451. * Store U(k) in column k of A
  452. *
  453. CALL DCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
  454. IF( K.GT.1 ) THEN
  455. IF( ABS( A( K, K ) ).GE.SFMIN ) THEN
  456. R1 = ONE / A( K, K )
  457. CALL DSCAL( K-1, R1, A( 1, K ), 1 )
  458. ELSE IF( A( K, K ).NE.ZERO ) THEN
  459. DO 14 II = 1, K - 1
  460. A( II, K ) = A( II, K ) / A( K, K )
  461. 14 CONTINUE
  462. END IF
  463. END IF
  464. *
  465. ELSE
  466. *
  467. * 2-by-2 pivot block D(k): columns KW and KW-1 of W now
  468. * hold
  469. *
  470. * ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
  471. *
  472. * where U(k) and U(k-1) are the k-th and (k-1)-th columns
  473. * of U
  474. *
  475. IF( K.GT.2 ) THEN
  476. *
  477. * Store U(k) and U(k-1) in columns k and k-1 of A
  478. *
  479. D12 = W( K-1, KW )
  480. D11 = W( K, KW ) / D12
  481. D22 = W( K-1, KW-1 ) / D12
  482. T = ONE / ( D11*D22-ONE )
  483. DO 20 J = 1, K - 2
  484. A( J, K-1 ) = T*( (D11*W( J, KW-1 )-W( J, KW ) ) /
  485. $ D12 )
  486. A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
  487. $ D12 )
  488. 20 CONTINUE
  489. END IF
  490. *
  491. * Copy D(k) to A
  492. *
  493. A( K-1, K-1 ) = W( K-1, KW-1 )
  494. A( K-1, K ) = W( K-1, KW )
  495. A( K, K ) = W( K, KW )
  496. END IF
  497. END IF
  498. *
  499. * Store details of the interchanges in IPIV
  500. *
  501. IF( KSTEP.EQ.1 ) THEN
  502. IPIV( K ) = KP
  503. ELSE
  504. IPIV( K ) = -P
  505. IPIV( K-1 ) = -KP
  506. END IF
  507. *
  508. * Decrease K and return to the start of the main loop
  509. *
  510. K = K - KSTEP
  511. GO TO 10
  512. *
  513. 30 CONTINUE
  514. *
  515. * Update the upper triangle of A11 (= A(1:k,1:k)) as
  516. *
  517. * A11 := A11 - U12*D*U12**T = A11 - U12*W**T
  518. *
  519. * computing blocks of NB columns at a time
  520. *
  521. DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
  522. JB = MIN( NB, K-J+1 )
  523. *
  524. * Update the upper triangle of the diagonal block
  525. *
  526. DO 40 JJ = J, J + JB - 1
  527. CALL DGEMV( 'No transpose', JJ-J+1, N-K, -ONE,
  528. $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, ONE,
  529. $ A( J, JJ ), 1 )
  530. 40 CONTINUE
  531. *
  532. * Update the rectangular superdiagonal block
  533. *
  534. IF( J.GE.2 )
  535. $ CALL DGEMM( 'No transpose', 'Transpose', J-1, JB,
  536. $ N-K, -ONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
  537. $ ONE, A( 1, J ), LDA )
  538. 50 CONTINUE
  539. *
  540. * Put U12 in standard form by partially undoing the interchanges
  541. * in columns k+1:n
  542. *
  543. J = K + 1
  544. 60 CONTINUE
  545. *
  546. KSTEP = 1
  547. JP1 = 1
  548. JJ = J
  549. JP2 = IPIV( J )
  550. IF( JP2.LT.0 ) THEN
  551. JP2 = -JP2
  552. J = J + 1
  553. JP1 = -IPIV( J )
  554. KSTEP = 2
  555. END IF
  556. *
  557. J = J + 1
  558. IF( JP2.NE.JJ .AND. J.LE.N )
  559. $ CALL DSWAP( N-J+1, A( JP2, J ), LDA, A( JJ, J ), LDA )
  560. JJ = J - 1
  561. IF( JP1.NE.JJ .AND. KSTEP.EQ.2 )
  562. $ CALL DSWAP( N-J+1, A( JP1, J ), LDA, A( JJ, J ), LDA )
  563. IF( J.LE.N )
  564. $ GO TO 60
  565. *
  566. * Set KB to the number of columns factorized
  567. *
  568. KB = N - K
  569. *
  570. ELSE
  571. *
  572. * Factorize the leading columns of A using the lower triangle
  573. * of A and working forwards, and compute the matrix W = L21*D
  574. * for use in updating A22
  575. *
  576. * K is the main loop index, increasing from 1 in steps of 1 or 2
  577. *
  578. K = 1
  579. 70 CONTINUE
  580. *
  581. * Exit from loop
  582. *
  583. IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
  584. $ GO TO 90
  585. *
  586. KSTEP = 1
  587. P = K
  588. *
  589. * Copy column K of A to column K of W and update it
  590. *
  591. CALL DCOPY( N-K+1, A( K, K ), 1, W( K, K ), 1 )
  592. IF( K.GT.1 )
  593. $ CALL DGEMV( 'No transpose', N-K+1, K-1, -ONE, A( K, 1 ),
  594. $ LDA, W( K, 1 ), LDW, ONE, W( K, K ), 1 )
  595. *
  596. * Determine rows and columns to be interchanged and whether
  597. * a 1-by-1 or 2-by-2 pivot block will be used
  598. *
  599. ABSAKK = ABS( W( K, K ) )
  600. *
  601. * IMAX is the row-index of the largest off-diagonal element in
  602. * column K, and COLMAX is its absolute value.
  603. * Determine both COLMAX and IMAX.
  604. *
  605. IF( K.LT.N ) THEN
  606. IMAX = K + IDAMAX( N-K, W( K+1, K ), 1 )
  607. COLMAX = ABS( W( IMAX, K ) )
  608. ELSE
  609. COLMAX = ZERO
  610. END IF
  611. *
  612. IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
  613. *
  614. * Column K is zero or underflow: set INFO and continue
  615. *
  616. IF( INFO.EQ.0 )
  617. $ INFO = K
  618. KP = K
  619. CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  620. ELSE
  621. *
  622. * ============================================================
  623. *
  624. * Test for interchange
  625. *
  626. * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
  627. * (used to handle NaN and Inf)
  628. *
  629. IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
  630. *
  631. * no interchange, use 1-by-1 pivot block
  632. *
  633. KP = K
  634. *
  635. ELSE
  636. *
  637. DONE = .FALSE.
  638. *
  639. * Loop until pivot found
  640. *
  641. 72 CONTINUE
  642. *
  643. * Begin pivot search loop body
  644. *
  645. *
  646. * Copy column IMAX to column K+1 of W and update it
  647. *
  648. CALL DCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
  649. CALL DCOPY( N-IMAX+1, A( IMAX, IMAX ), 1,
  650. $ W( IMAX, K+1 ), 1 )
  651. IF( K.GT.1 )
  652. $ CALL DGEMV( 'No transpose', N-K+1, K-1, -ONE,
  653. $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
  654. $ ONE, W( K, K+1 ), 1 )
  655. *
  656. * JMAX is the column-index of the largest off-diagonal
  657. * element in row IMAX, and ROWMAX is its absolute value.
  658. * Determine both ROWMAX and JMAX.
  659. *
  660. IF( IMAX.NE.K ) THEN
  661. JMAX = K - 1 + IDAMAX( IMAX-K, W( K, K+1 ), 1 )
  662. ROWMAX = ABS( W( JMAX, K+1 ) )
  663. ELSE
  664. ROWMAX = ZERO
  665. END IF
  666. *
  667. IF( IMAX.LT.N ) THEN
  668. ITEMP = IMAX + IDAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
  669. DTEMP = ABS( W( ITEMP, K+1 ) )
  670. IF( DTEMP.GT.ROWMAX ) THEN
  671. ROWMAX = DTEMP
  672. JMAX = ITEMP
  673. END IF
  674. END IF
  675. *
  676. * Equivalent to testing for
  677. * ABS( W( IMAX, K+1 ) ).GE.ALPHA*ROWMAX
  678. * (used to handle NaN and Inf)
  679. *
  680. IF( .NOT.( ABS( W( IMAX, K+1 ) ).LT.ALPHA*ROWMAX ) )
  681. $ THEN
  682. *
  683. * interchange rows and columns K and IMAX,
  684. * use 1-by-1 pivot block
  685. *
  686. KP = IMAX
  687. *
  688. * copy column K+1 of W to column K of W
  689. *
  690. CALL DCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  691. *
  692. DONE = .TRUE.
  693. *
  694. * Equivalent to testing for ROWMAX.EQ.COLMAX,
  695. * (used to handle NaN and Inf)
  696. *
  697. ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
  698. $ THEN
  699. *
  700. * interchange rows and columns K+1 and IMAX,
  701. * use 2-by-2 pivot block
  702. *
  703. KP = IMAX
  704. KSTEP = 2
  705. DONE = .TRUE.
  706. ELSE
  707. *
  708. * Pivot not found: set params and repeat
  709. *
  710. P = IMAX
  711. COLMAX = ROWMAX
  712. IMAX = JMAX
  713. *
  714. * Copy updated JMAXth (next IMAXth) column to Kth of W
  715. *
  716. CALL DCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
  717. *
  718. END IF
  719. *
  720. * End pivot search loop body
  721. *
  722. IF( .NOT. DONE ) GOTO 72
  723. *
  724. END IF
  725. *
  726. * ============================================================
  727. *
  728. KK = K + KSTEP - 1
  729. *
  730. IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
  731. *
  732. * Copy non-updated column K to column P
  733. *
  734. CALL DCOPY( P-K, A( K, K ), 1, A( P, K ), LDA )
  735. CALL DCOPY( N-P+1, A( P, K ), 1, A( P, P ), 1 )
  736. *
  737. * Interchange rows K and P in first K columns of A
  738. * and first K+1 columns of W
  739. *
  740. CALL DSWAP( K, A( K, 1 ), LDA, A( P, 1 ), LDA )
  741. CALL DSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
  742. END IF
  743. *
  744. * Updated column KP is already stored in column KK of W
  745. *
  746. IF( KP.NE.KK ) THEN
  747. *
  748. * Copy non-updated column KK to column KP
  749. *
  750. A( KP, K ) = A( KK, K )
  751. CALL DCOPY( KP-K-1, A( K+1, KK ), 1, A( KP, K+1 ), LDA )
  752. CALL DCOPY( N-KP+1, A( KP, KK ), 1, A( KP, KP ), 1 )
  753. *
  754. * Interchange rows KK and KP in first KK columns of A and W
  755. *
  756. CALL DSWAP( KK, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
  757. CALL DSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
  758. END IF
  759. *
  760. IF( KSTEP.EQ.1 ) THEN
  761. *
  762. * 1-by-1 pivot block D(k): column k of W now holds
  763. *
  764. * W(k) = L(k)*D(k)
  765. *
  766. * where L(k) is the k-th column of L
  767. *
  768. * Store L(k) in column k of A
  769. *
  770. CALL DCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
  771. IF( K.LT.N ) THEN
  772. IF( ABS( A( K, K ) ).GE.SFMIN ) THEN
  773. R1 = ONE / A( K, K )
  774. CALL DSCAL( N-K, R1, A( K+1, K ), 1 )
  775. ELSE IF( A( K, K ).NE.ZERO ) THEN
  776. DO 74 II = K + 1, N
  777. A( II, K ) = A( II, K ) / A( K, K )
  778. 74 CONTINUE
  779. END IF
  780. END IF
  781. *
  782. ELSE
  783. *
  784. * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
  785. *
  786. * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
  787. *
  788. * where L(k) and L(k+1) are the k-th and (k+1)-th columns
  789. * of L
  790. *
  791. IF( K.LT.N-1 ) THEN
  792. *
  793. * Store L(k) and L(k+1) in columns k and k+1 of A
  794. *
  795. D21 = W( K+1, K )
  796. D11 = W( K+1, K+1 ) / D21
  797. D22 = W( K, K ) / D21
  798. T = ONE / ( D11*D22-ONE )
  799. DO 80 J = K + 2, N
  800. A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
  801. $ D21 )
  802. A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
  803. $ D21 )
  804. 80 CONTINUE
  805. END IF
  806. *
  807. * Copy D(k) to A
  808. *
  809. A( K, K ) = W( K, K )
  810. A( K+1, K ) = W( K+1, K )
  811. A( K+1, K+1 ) = W( K+1, K+1 )
  812. END IF
  813. END IF
  814. *
  815. * Store details of the interchanges in IPIV
  816. *
  817. IF( KSTEP.EQ.1 ) THEN
  818. IPIV( K ) = KP
  819. ELSE
  820. IPIV( K ) = -P
  821. IPIV( K+1 ) = -KP
  822. END IF
  823. *
  824. * Increase K and return to the start of the main loop
  825. *
  826. K = K + KSTEP
  827. GO TO 70
  828. *
  829. 90 CONTINUE
  830. *
  831. * Update the lower triangle of A22 (= A(k:n,k:n)) as
  832. *
  833. * A22 := A22 - L21*D*L21**T = A22 - L21*W**T
  834. *
  835. * computing blocks of NB columns at a time
  836. *
  837. DO 110 J = K, N, NB
  838. JB = MIN( NB, N-J+1 )
  839. *
  840. * Update the lower triangle of the diagonal block
  841. *
  842. DO 100 JJ = J, J + JB - 1
  843. CALL DGEMV( 'No transpose', J+JB-JJ, K-1, -ONE,
  844. $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, ONE,
  845. $ A( JJ, JJ ), 1 )
  846. 100 CONTINUE
  847. *
  848. * Update the rectangular subdiagonal block
  849. *
  850. IF( J+JB.LE.N )
  851. $ CALL DGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
  852. $ K-1, -ONE, A( J+JB, 1 ), LDA, W( J, 1 ), LDW,
  853. $ ONE, A( J+JB, J ), LDA )
  854. 110 CONTINUE
  855. *
  856. * Put L21 in standard form by partially undoing the interchanges
  857. * in columns 1:k-1
  858. *
  859. J = K - 1
  860. 120 CONTINUE
  861. *
  862. KSTEP = 1
  863. JP1 = 1
  864. JJ = J
  865. JP2 = IPIV( J )
  866. IF( JP2.LT.0 ) THEN
  867. JP2 = -JP2
  868. J = J - 1
  869. JP1 = -IPIV( J )
  870. KSTEP = 2
  871. END IF
  872. *
  873. J = J - 1
  874. IF( JP2.NE.JJ .AND. J.GE.1 )
  875. $ CALL DSWAP( J, A( JP2, 1 ), LDA, A( JJ, 1 ), LDA )
  876. JJ = J + 1
  877. IF( JP1.NE.JJ .AND. KSTEP.EQ.2 )
  878. $ CALL DSWAP( J, A( JP1, 1 ), LDA, A( JJ, 1 ), LDA )
  879. IF( J.GE.1 )
  880. $ GO TO 120
  881. *
  882. * Set KB to the number of columns factorized
  883. *
  884. KB = K - 1
  885. *
  886. END IF
  887. RETURN
  888. *
  889. * End of DLASYF_ROOK
  890. *
  891. END