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.

slasyf_rook.f 27 kB

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