1 * \brief \b ZLAHEF_ROOK computes a partial factorization of a complex Hermitian indefinite matrix using the bounded Bunch-Kaufman ("rook") diagonal pivoting method (blocked algorithm, calling Level 3 BLAS).
3 * =========== DOCUMENTATION ===========
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
9 *> Download ZLAHEF_ROOK + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/zlahef_rook.f">
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/zlahef_rook.f">
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/zlahef_rook.f">
21 * SUBROUTINE ZLAHEF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW, INFO )
23 * .. Scalar Arguments ..
25 * INTEGER INFO, KB, LDA, LDW, N, NB
27 * .. Array Arguments ..
29 * COMPLEX*16 A( LDA, * ), W( LDW, * )
38 *> ZLAHEF_ROOK computes a partial factorization of a complex Hermitian
39 *> matrix A using the bounded Bunch-Kaufman ("rook") diagonal pivoting
40 *> method. The partial factorization has the form:
42 *> A = ( I U12 ) ( A11 0 ) ( I 0 ) if UPLO = 'U', or:
43 *> ( 0 U22 ) ( 0 D ) ( U12**H U22**H )
45 *> A = ( L11 0 ) ( D 0 ) ( L11**H L21**H ) if UPLO = 'L'
46 *> ( L21 I ) ( 0 A22 ) ( 0 I )
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**H denotes the conjugate transpose of U.
52 *> ZLAHEF_ROOK is an auxiliary routine called by ZHETRF_ROOK. It uses
53 *> blocked code (calling Level 3 BLAS) to update the submatrix
54 *> A11 (if UPLO = 'U') or A22 (if UPLO = 'L').
62 *> UPLO is CHARACTER*1
63 *> Specifies whether the upper or lower triangular part of the
64 *> Hermitian matrix A is stored:
65 *> = 'U': Upper triangular
66 *> = 'L': Lower triangular
72 *> The order of the matrix A. N >= 0.
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
86 *> The number of columns of A that were actually factored.
87 *> KB is either NB-1 or NB, or N if N <= NB.
92 *> A is COMPLEX*16 array, dimension (LDA,N)
93 *> On entry, the Hermitian 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.
106 *> The leading dimension of the array A. LDA >= max(1,N).
111 *> IPIV is INTEGER array, dimension (N)
112 *> Details of the interchanges and the block structure of D.
115 *> Only the last KB elements of IPIV are set.
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.
120 *> If IPIV(k) < 0 and IPIV(k-1) < 0, then rows and
121 *> columns k and -IPIV(k) were interchanged and rows and
122 *> columns k-1 and -IPIV(k-1) were inerchaged,
123 *> D(k-1:k,k-1:k) is a 2-by-2 diagonal block.
126 *> Only the first KB elements of IPIV are set.
128 *> If IPIV(k) > 0, then rows and columns k and IPIV(k)
129 *> were interchanged and D(k,k) is a 1-by-1 diagonal block.
131 *> If IPIV(k) < 0 and IPIV(k+1) < 0, then rows and
132 *> columns k and -IPIV(k) were interchanged and rows and
133 *> columns k+1 and -IPIV(k+1) were inerchaged,
134 *> D(k:k+1,k:k+1) is a 2-by-2 diagonal block.
139 *> W is COMPLEX*16 array, dimension (LDW,NB)
145 *> The leading dimension of the array W. LDW >= max(1,N).
151 *> = 0: successful exit
152 *> > 0: if INFO = k, D(k,k) is exactly zero. The factorization
153 *> has been completed, but the block diagonal matrix D is
160 *> \author Univ. of Tennessee
161 *> \author Univ. of California Berkeley
162 *> \author Univ. of Colorado Denver
165 *> \date November 2013
167 *> \ingroup complex16HEcomputational
169 *> \par Contributors:
174 *> November 2013, Igor Kozachenko,
175 *> Computer Science Division,
176 *> University of California, Berkeley
178 *> September 2007, Sven Hammarling, Nicholas J. Higham, Craig Lucas,
179 *> School of Mathematics,
180 *> University of Manchester
183 * =====================================================================
184 SUBROUTINE ZLAHEF_ROOK( UPLO, N, NB, KB, A, LDA, IPIV, W, LDW,
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..--
192 * .. Scalar Arguments ..
194 INTEGER INFO, KB, LDA, LDW, N, NB
196 * .. Array Arguments ..
198 COMPLEX*16 A( LDA, * ), W( LDW, * )
201 * =====================================================================
204 DOUBLE PRECISION ZERO, ONE
205 PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
207 PARAMETER ( CONE = ( 1.0D+0, 0.0D+0 ) )
208 DOUBLE PRECISION EIGHT, SEVTEN
209 PARAMETER ( EIGHT = 8.0D+0, SEVTEN = 17.0D+0 )
211 * .. Local Scalars ..
213 INTEGER IMAX, ITEMP, II, J, JB, JJ, JMAX, JP1, JP2, K,
214 $ KK, KKW, KP, KSTEP, KW, P
215 DOUBLE PRECISION ABSAKK, ALPHA, COLMAX, DTEMP, R1, ROWMAX, T,
217 COMPLEX*16 D11, D21, D22, Z
219 * .. External Functions ..
222 DOUBLE PRECISION DLAMCH
223 EXTERNAL LSAME, IZAMAX, DLAMCH
225 * .. External Subroutines ..
226 EXTERNAL ZCOPY, ZDSCAL, ZGEMM, ZGEMV, ZLACGV, ZSWAP
228 * .. Intrinsic Functions ..
229 INTRINSIC ABS, DBLE, DCONJG, DIMAG, MAX, MIN, SQRT
231 * .. Statement Functions ..
232 DOUBLE PRECISION CABS1
234 * .. Statement Function definitions ..
235 CABS1( Z ) = ABS( DBLE( Z ) ) + ABS( DIMAG( Z ) )
237 * .. Executable Statements ..
241 * Initialize ALPHA for use in choosing pivot block size.
243 ALPHA = ( ONE+SQRT( SEVTEN ) ) / EIGHT
245 * Compute machine safe minimum
247 SFMIN = DLAMCH( 'S' )
249 IF( LSAME( UPLO, 'U' ) ) THEN
251 * Factorize the trailing columns of A using the upper triangle
252 * of A and working backwards, and compute the matrix W = U12*D
253 * for use in updating A11 (note that conjg(W) is actually stored)
255 * K is the main loop index, decreasing from N in steps of 1 or 2
260 * KW is the column of W which corresponds to column K of A
266 IF( ( K.LE.N-NB+1 .AND. NB.LT.N ) .OR. K.LT.1 )
272 * Copy column K of A to column KW of W and update it
275 $ CALL ZCOPY( K-1, A( 1, K ), 1, W( 1, KW ), 1 )
276 W( K, KW ) = DBLE( A( K, K ) )
278 CALL ZGEMV( 'No transpose', K, N-K, -CONE, A( 1, K+1 ), LDA,
279 $ W( K, KW+1 ), LDW, CONE, W( 1, KW ), 1 )
280 W( K, KW ) = DBLE( W( K, KW ) )
283 * Determine rows and columns to be interchanged and whether
284 * a 1-by-1 or 2-by-2 pivot block will be used
286 ABSAKK = ABS( DBLE( W( K, KW ) ) )
288 * IMAX is the row-index of the largest off-diagonal element in
289 * column K, and COLMAX is its absolute value.
290 * Determine both COLMAX and IMAX.
293 IMAX = IZAMAX( K-1, W( 1, KW ), 1 )
294 COLMAX = CABS1( W( IMAX, KW ) )
299 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
301 * Column K is zero or underflow: set INFO and continue
306 A( K, K ) = DBLE( W( K, KW ) )
308 $ CALL ZCOPY( K-1, W( 1, KW ), 1, A( 1, K ), 1 )
311 * ============================================================
316 * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
317 * (used to handle NaN and Inf)
318 IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
320 * no interchange, use 1-by-1 pivot block
326 * Lop until pivot found
332 * BEGIN pivot search loop body
335 * Copy column IMAX to column KW-1 of W and update it
338 $ CALL ZCOPY( IMAX-1, A( 1, IMAX ), 1, W( 1, KW-1 ),
340 W( IMAX, KW-1 ) = DBLE( A( IMAX, IMAX ) )
342 CALL ZCOPY( K-IMAX, A( IMAX, IMAX+1 ), LDA,
343 $ W( IMAX+1, KW-1 ), 1 )
344 CALL ZLACGV( K-IMAX, W( IMAX+1, KW-1 ), 1 )
347 CALL ZGEMV( 'No transpose', K, N-K, -CONE,
348 $ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
349 $ CONE, W( 1, KW-1 ), 1 )
350 W( IMAX, KW-1 ) = DBLE( W( IMAX, KW-1 ) )
353 * JMAX is the column-index of the largest off-diagonal
354 * element in row IMAX, and ROWMAX is its absolute value.
355 * Determine both ROWMAX and JMAX.
358 JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ),
360 ROWMAX = CABS1( W( JMAX, KW-1 ) )
366 ITEMP = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
367 DTEMP = CABS1( W( ITEMP, KW-1 ) )
368 IF( DTEMP.GT.ROWMAX ) THEN
375 * Equivalent to testing for
376 * ABS( REAL( W( IMAX,KW-1 ) ) ).GE.ALPHA*ROWMAX
377 * (used to handle NaN and Inf)
379 IF( .NOT.( ABS( DBLE( W( IMAX,KW-1 ) ) )
380 $ .LT.ALPHA*ROWMAX ) ) THEN
382 * interchange rows and columns K and IMAX,
383 * use 1-by-1 pivot block
387 * copy column KW-1 of W to column KW of W
389 CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
394 * Equivalent to testing for ROWMAX.EQ.COLMAX,
395 * (used to handle NaN and Inf)
397 ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
400 * interchange rows and columns K-1 and IMAX,
401 * use 2-by-2 pivot block
410 * Pivot not found: set params and repeat
416 * Copy updated JMAXth (next IMAXth) column to Kth of W
418 CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
423 * END pivot search loop body
425 IF( .NOT.DONE ) GOTO 12
431 * ============================================================
433 * KK is the column of A where pivoting step stopped
437 * KKW is the column of W which corresponds to column KK of A
441 * Interchange rows and columns P and K.
442 * Updated column P is already stored in column KW of W.
444 IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
446 * Copy non-updated column K to column P of submatrix A
447 * at step K. No need to copy element into columns
448 * K and K-1 of A for 2-by-2 pivot, since these columns
449 * will be later overwritten.
451 A( P, P ) = DBLE( A( K, K ) )
452 CALL ZCOPY( K-1-P, A( P+1, K ), 1, A( P, P+1 ),
454 CALL ZLACGV( K-1-P, A( P, P+1 ), LDA )
456 $ CALL ZCOPY( P-1, A( 1, K ), 1, A( 1, P ), 1 )
458 * Interchange rows K and P in the last K+1 to N columns of A
459 * (columns K and K-1 of A for 2-by-2 pivot will be
460 * later overwritten). Interchange rows K and P
461 * in last KKW to NB columns of W.
464 $ CALL ZSWAP( N-K, A( K, K+1 ), LDA, A( P, K+1 ),
466 CALL ZSWAP( N-KK+1, W( K, KKW ), LDW, W( P, KKW ),
470 * Interchange rows and columns KP and KK.
471 * Updated column KP is already stored in column KKW of W.
475 * Copy non-updated column KK to column KP of submatrix A
476 * at step K. No need to copy element into column K
477 * (or K and K-1 for 2-by-2 pivot) of A, since these columns
478 * will be later overwritten.
480 A( KP, KP ) = DBLE( A( KK, KK ) )
481 CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
483 CALL ZLACGV( KK-1-KP, A( KP, KP+1 ), LDA )
485 $ CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
487 * Interchange rows KK and KP in last K+1 to N columns of A
488 * (columns K (or K and K-1 for 2-by-2 pivot) of A will be
489 * later overwritten). Interchange rows KK and KP
490 * in last KKW to NB columns of W.
493 $ CALL ZSWAP( N-K, A( KK, K+1 ), LDA, A( KP, K+1 ),
495 CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
499 IF( KSTEP.EQ.1 ) THEN
501 * 1-by-1 pivot block D(k): column kw of W now holds
505 * where U(k) is the k-th column of U
507 * (1) Store subdiag. elements of column U(k)
508 * and 1-by-1 block D(k) in column k of A.
509 * (NOTE: Diagonal element U(k,k) is a UNIT element
511 * A(k,k) := D(k,k) = W(k,kw)
512 * A(1:k-1,k) := U(1:k-1,k) = W(1:k-1,kw)/D(k,k)
514 * (NOTE: No need to use for Hermitian matrix
515 * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal
516 * element D(k,k) from W (potentially saves only one load))
517 CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
520 * (NOTE: No need to check if A(k,k) is NOT ZERO,
521 * since that was ensured earlier in pivot search:
522 * case A(k,k) = 0 falls into 2x2 pivot case(3))
524 * Handle division by a small number
526 T = DBLE( A( K, K ) )
527 IF( ABS( T ).GE.SFMIN ) THEN
529 CALL ZDSCAL( K-1, R1, A( 1, K ), 1 )
532 A( II, K ) = A( II, K ) / T
536 * (2) Conjugate column W(kw)
538 CALL ZLACGV( K-1, W( 1, KW ), 1 )
543 * 2-by-2 pivot block D(k): columns kw and kw-1 of W now hold
545 * ( W(kw-1) W(kw) ) = ( U(k-1) U(k) )*D(k)
547 * where U(k) and U(k-1) are the k-th and (k-1)-th columns
550 * (1) Store U(1:k-2,k-1) and U(1:k-2,k) and 2-by-2
551 * block D(k-1:k,k-1:k) in columns k-1 and k of A.
552 * (NOTE: 2-by-2 diagonal block U(k-1:k,k-1:k) is a UNIT
553 * block and not stored)
554 * A(k-1:k,k-1:k) := D(k-1:k,k-1:k) = W(k-1:k,kw-1:kw)
555 * A(1:k-2,k-1:k) := U(1:k-2,k:k-1:k) =
556 * = W(1:k-2,kw-1:kw) * ( D(k-1:k,k-1:k)**(-1) )
560 * Factor out the columns of the inverse of 2-by-2 pivot
561 * block D, so that each column contains 1, to reduce the
562 * number of FLOPS when we multiply panel
563 * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
565 * D**(-1) = ( d11 cj(d21) )**(-1) =
568 * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
571 * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
573 * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
574 * ( ( -1 ) ( d11/conj(d21) ) )
576 * = 1/(|d21|**2) * 1/(D22*D11-1) *
578 * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
581 * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
584 * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
587 * Handle division by a small number. (NOTE: order of
588 * operations is important)
590 * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
591 * ( (( -1 ) ) (( D22 ) ) ),
593 * where D11 = d22/d21,
594 * D22 = d11/conj(d21),
598 * (NOTE: No need to check for division by ZERO,
599 * since that was ensured earlier in pivot search:
600 * (a) d21 != 0 in 2x2 pivot case(4),
601 * since |d21| should be larger than |d11| and |d22|;
602 * (b) (D22*D11 - 1) != 0, since from (a),
603 * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
606 D11 = W( K, KW ) / DCONJG( D21 )
607 D22 = W( K-1, KW-1 ) / D21
608 T = ONE / ( DBLE( D11*D22 )-ONE )
610 * Update elements in columns A(k-1) and A(k) as
611 * dot products of rows of ( W(kw-1) W(kw) ) and columns
615 A( J, K-1 ) = T*( ( D11*W( J, KW-1 )-W( J, KW ) ) /
617 A( J, K ) = T*( ( D22*W( J, KW )-W( J, KW-1 ) ) /
624 A( K-1, K-1 ) = W( K-1, KW-1 )
625 A( K-1, K ) = W( K-1, KW )
626 A( K, K ) = W( K, KW )
628 * (2) Conjugate columns W(kw) and W(kw-1)
630 CALL ZLACGV( K-1, W( 1, KW ), 1 )
631 CALL ZLACGV( K-2, W( 1, KW-1 ), 1 )
637 * Store details of the interchanges in IPIV
639 IF( KSTEP.EQ.1 ) THEN
646 * Decrease K and return to the start of the main loop
653 * Update the upper triangle of A11 (= A(1:k,1:k)) as
655 * A11 := A11 - U12*D*U12**H = A11 - U12*W**H
657 * computing blocks of NB columns at a time (note that conjg(W) is
660 DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
661 JB = MIN( NB, K-J+1 )
663 * Update the upper triangle of the diagonal block
665 DO 40 JJ = J, J + JB - 1
666 A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
667 CALL ZGEMV( 'No transpose', JJ-J+1, N-K, -CONE,
668 $ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
670 A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
673 * Update the rectangular superdiagonal block
676 $ CALL ZGEMM( 'No transpose', 'Transpose', J-1, JB, N-K,
677 $ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
678 $ CONE, A( 1, J ), LDA )
681 * Put U12 in standard form by partially undoing the interchanges
682 * in of rows in columns k+1:n looping backwards from k+1 to n
687 * Undo the interchanges (if any) of rows J and JP2
688 * (or J and JP2, and J+1 and JP1) at each step J
692 * (Here, J is a diagonal index)
697 * (Here, J is a diagonal index)
702 * (NOTE: Here, J is used to determine row length. Length N-J+1
703 * of the rows to swap back doesn't include diagonal element)
705 IF( JP2.NE.JJ .AND. J.LE.N )
706 $ CALL ZSWAP( N-J+1, A( JP2, J ), LDA, A( JJ, J ), LDA )
708 IF( KSTEP.EQ.2 .AND. JP1.NE.JJ .AND. J.LE.N )
709 $ CALL ZSWAP( N-J+1, A( JP1, J ), LDA, A( JJ, J ), LDA )
713 * Set KB to the number of columns factorized
719 * Factorize the leading columns of A using the lower triangle
720 * of A and working forwards, and compute the matrix W = L21*D
721 * for use in updating A22 (note that conjg(W) is actually stored)
723 * K is the main loop index, increasing from 1 in steps of 1 or 2
730 IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
736 * Copy column K of A to column K of W and update column K of W
738 W( K, K ) = DBLE( A( K, K ) )
740 $ CALL ZCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
742 CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE, A( K, 1 ),
743 $ LDA, W( K, 1 ), LDW, CONE, W( K, K ), 1 )
744 W( K, K ) = DBLE( W( K, K ) )
747 * Determine rows and columns to be interchanged and whether
748 * a 1-by-1 or 2-by-2 pivot block will be used
750 ABSAKK = ABS( DBLE( W( K, K ) ) )
752 * IMAX is the row-index of the largest off-diagonal element in
753 * column K, and COLMAX is its absolute value.
754 * Determine both COLMAX and IMAX.
757 IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
758 COLMAX = CABS1( W( IMAX, K ) )
763 IF( MAX( ABSAKK, COLMAX ).EQ.ZERO ) THEN
765 * Column K is zero or underflow: set INFO and continue
770 A( K, K ) = DBLE( W( K, K ) )
772 $ CALL ZCOPY( N-K, W( K+1, K ), 1, A( K+1, K ), 1 )
775 * ============================================================
780 * Equivalent to testing for ABSAKK.GE.ALPHA*COLMAX
781 * (used to handle NaN and Inf)
783 IF( .NOT.( ABSAKK.LT.ALPHA*COLMAX ) ) THEN
785 * no interchange, use 1-by-1 pivot block
793 * Loop until pivot found
797 * BEGIN pivot search loop body
800 * Copy column IMAX to column k+1 of W and update it
802 CALL ZCOPY( IMAX-K, A( IMAX, K ), LDA, W( K, K+1 ), 1)
803 CALL ZLACGV( IMAX-K, W( K, K+1 ), 1 )
804 W( IMAX, K+1 ) = DBLE( A( IMAX, IMAX ) )
807 $ CALL ZCOPY( N-IMAX, A( IMAX+1, IMAX ), 1,
808 $ W( IMAX+1, K+1 ), 1 )
811 CALL ZGEMV( 'No transpose', N-K+1, K-1, -CONE,
812 $ A( K, 1 ), LDA, W( IMAX, 1 ), LDW,
813 $ CONE, W( K, K+1 ), 1 )
814 W( IMAX, K+1 ) = DBLE( W( IMAX, K+1 ) )
817 * JMAX is the column-index of the largest off-diagonal
818 * element in row IMAX, and ROWMAX is its absolute value.
819 * Determine both ROWMAX and JMAX.
822 JMAX = K - 1 + IZAMAX( IMAX-K, W( K, K+1 ), 1 )
823 ROWMAX = CABS1( W( JMAX, K+1 ) )
829 ITEMP = IMAX + IZAMAX( N-IMAX, W( IMAX+1, K+1 ), 1)
830 DTEMP = CABS1( W( ITEMP, K+1 ) )
831 IF( DTEMP.GT.ROWMAX ) THEN
838 * Equivalent to testing for
839 * ABS( REAL( W( IMAX,K+1 ) ) ).GE.ALPHA*ROWMAX
840 * (used to handle NaN and Inf)
842 IF( .NOT.( ABS( DBLE( W( IMAX,K+1 ) ) )
843 $ .LT.ALPHA*ROWMAX ) ) THEN
845 * interchange rows and columns K and IMAX,
846 * use 1-by-1 pivot block
850 * copy column K+1 of W to column K of W
852 CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
857 * Equivalent to testing for ROWMAX.EQ.COLMAX,
858 * (used to handle NaN and Inf)
860 ELSE IF( ( P.EQ.JMAX ) .OR. ( ROWMAX.LE.COLMAX ) )
863 * interchange rows and columns K+1 and IMAX,
864 * use 2-by-2 pivot block
873 * Pivot not found: set params and repeat
879 * Copy updated JMAXth (next IMAXth) column to Kth of W
881 CALL ZCOPY( N-K+1, W( K, K+1 ), 1, W( K, K ), 1 )
886 * End pivot search loop body
888 IF( .NOT.DONE ) GOTO 72
894 * ============================================================
896 * KK is the column of A where pivoting step stopped
900 * Interchange rows and columns P and K (only for 2-by-2 pivot).
901 * Updated column P is already stored in column K of W.
903 IF( ( KSTEP.EQ.2 ) .AND. ( P.NE.K ) ) THEN
905 * Copy non-updated column KK-1 to column P of submatrix A
906 * at step K. No need to copy element into columns
907 * K and K+1 of A for 2-by-2 pivot, since these columns
908 * will be later overwritten.
910 A( P, P ) = DBLE( A( K, K ) )
911 CALL ZCOPY( P-K-1, A( K+1, K ), 1, A( P, K+1 ), LDA )
912 CALL ZLACGV( P-K-1, A( P, K+1 ), LDA )
914 $ CALL ZCOPY( N-P, A( P+1, K ), 1, A( P+1, P ), 1 )
916 * Interchange rows K and P in first K-1 columns of A
917 * (columns K and K+1 of A for 2-by-2 pivot will be
918 * later overwritten). Interchange rows K and P
919 * in first KK columns of W.
922 $ CALL ZSWAP( K-1, A( K, 1 ), LDA, A( P, 1 ), LDA )
923 CALL ZSWAP( KK, W( K, 1 ), LDW, W( P, 1 ), LDW )
926 * Interchange rows and columns KP and KK.
927 * Updated column KP is already stored in column KK of W.
931 * Copy non-updated column KK to column KP of submatrix A
932 * at step K. No need to copy element into column K
933 * (or K and K+1 for 2-by-2 pivot) of A, since these columns
934 * will be later overwritten.
936 A( KP, KP ) = DBLE( A( KK, KK ) )
937 CALL ZCOPY( KP-KK-1, A( KK+1, KK ), 1, A( KP, KK+1 ),
939 CALL ZLACGV( KP-KK-1, A( KP, KK+1 ), LDA )
941 $ CALL ZCOPY( N-KP, A( KP+1, KK ), 1, A( KP+1, KP ), 1 )
943 * Interchange rows KK and KP in first K-1 columns of A
944 * (column K (or K and K+1 for 2-by-2 pivot) of A will be
945 * later overwritten). Interchange rows KK and KP
946 * in first KK columns of W.
949 $ CALL ZSWAP( K-1, A( KK, 1 ), LDA, A( KP, 1 ), LDA )
950 CALL ZSWAP( KK, W( KK, 1 ), LDW, W( KP, 1 ), LDW )
953 IF( KSTEP.EQ.1 ) THEN
955 * 1-by-1 pivot block D(k): column k of W now holds
959 * where L(k) is the k-th column of L
961 * (1) Store subdiag. elements of column L(k)
962 * and 1-by-1 block D(k) in column k of A.
963 * (NOTE: Diagonal element L(k,k) is a UNIT element
965 * A(k,k) := D(k,k) = W(k,k)
966 * A(k+1:N,k) := L(k+1:N,k) = W(k+1:N,k)/D(k,k)
968 * (NOTE: No need to use for Hermitian matrix
969 * A( K, K ) = REAL( W( K, K) ) to separately copy diagonal
970 * element D(k,k) from W (potentially saves only one load))
971 CALL ZCOPY( N-K+1, W( K, K ), 1, A( K, K ), 1 )
974 * (NOTE: No need to check if A(k,k) is NOT ZERO,
975 * since that was ensured earlier in pivot search:
976 * case A(k,k) = 0 falls into 2x2 pivot case(3))
978 * Handle division by a small number
980 T = DBLE( A( K, K ) )
981 IF( ABS( T ).GE.SFMIN ) THEN
983 CALL ZDSCAL( N-K, R1, A( K+1, K ), 1 )
986 A( II, K ) = A( II, K ) / T
990 * (2) Conjugate column W(k)
992 CALL ZLACGV( N-K, W( K+1, K ), 1 )
997 * 2-by-2 pivot block D(k): columns k and k+1 of W now hold
999 * ( W(k) W(k+1) ) = ( L(k) L(k+1) )*D(k)
1001 * where L(k) and L(k+1) are the k-th and (k+1)-th columns
1004 * (1) Store L(k+2:N,k) and L(k+2:N,k+1) and 2-by-2
1005 * block D(k:k+1,k:k+1) in columns k and k+1 of A.
1006 * NOTE: 2-by-2 diagonal block L(k:k+1,k:k+1) is a UNIT
1007 * block and not stored.
1008 * A(k:k+1,k:k+1) := D(k:k+1,k:k+1) = W(k:k+1,k:k+1)
1009 * A(k+2:N,k:k+1) := L(k+2:N,k:k+1) =
1010 * = W(k+2:N,k:k+1) * ( D(k:k+1,k:k+1)**(-1) )
1014 * Factor out the columns of the inverse of 2-by-2 pivot
1015 * block D, so that each column contains 1, to reduce the
1016 * number of FLOPS when we multiply panel
1017 * ( W(kw-1) W(kw) ) by this inverse, i.e. by D**(-1).
1019 * D**(-1) = ( d11 cj(d21) )**(-1) =
1022 * = 1/(d11*d22-|d21|**2) * ( ( d22) (-cj(d21) ) ) =
1023 * ( (-d21) ( d11 ) )
1025 * = 1/(|d21|**2) * 1/((d11/cj(d21))*(d22/d21)-1) *
1027 * * ( d21*( d22/d21 ) conj(d21)*( - 1 ) ) =
1028 * ( ( -1 ) ( d11/conj(d21) ) )
1030 * = 1/(|d21|**2) * 1/(D22*D11-1) *
1032 * * ( d21*( D11 ) conj(d21)*( -1 ) ) =
1033 * ( ( -1 ) ( D22 ) )
1035 * = (1/|d21|**2) * T * ( d21*( D11 ) conj(d21)*( -1 ) ) =
1036 * ( ( -1 ) ( D22 ) )
1038 * = ( (T/conj(d21))*( D11 ) (T/d21)*( -1 ) ) =
1039 * ( ( -1 ) ( D22 ) )
1041 * Handle division by a small number. (NOTE: order of
1042 * operations is important)
1044 * = ( T*(( D11 )/conj(D21)) T*(( -1 )/D21 ) )
1045 * ( (( -1 ) ) (( D22 ) ) ),
1047 * where D11 = d22/d21,
1048 * D22 = d11/conj(d21),
1050 * T = 1/(D22*D11-1).
1052 * (NOTE: No need to check for division by ZERO,
1053 * since that was ensured earlier in pivot search:
1054 * (a) d21 != 0 in 2x2 pivot case(4),
1055 * since |d21| should be larger than |d11| and |d22|;
1056 * (b) (D22*D11 - 1) != 0, since from (a),
1057 * both |D11| < 1, |D22| < 1, hence |D22*D11| << 1.)
1060 D11 = W( K+1, K+1 ) / D21
1061 D22 = W( K, K ) / DCONJG( D21 )
1062 T = ONE / ( DBLE( D11*D22 )-ONE )
1064 * Update elements in columns A(k) and A(k+1) as
1065 * dot products of rows of ( W(k) W(k+1) ) and columns
1069 A( J, K ) = T*( ( D11*W( J, K )-W( J, K+1 ) ) /
1071 A( J, K+1 ) = T*( ( D22*W( J, K+1 )-W( J, K ) ) /
1078 A( K, K ) = W( K, K )
1079 A( K+1, K ) = W( K+1, K )
1080 A( K+1, K+1 ) = W( K+1, K+1 )
1082 * (2) Conjugate columns W(k) and W(k+1)
1084 CALL ZLACGV( N-K, W( K+1, K ), 1 )
1085 CALL ZLACGV( N-K-1, W( K+2, K+1 ), 1 )
1091 * Store details of the interchanges in IPIV
1093 IF( KSTEP.EQ.1 ) THEN
1100 * Increase K and return to the start of the main loop
1107 * Update the lower triangle of A22 (= A(k:n,k:n)) as
1109 * A22 := A22 - L21*D*L21**H = A22 - L21*W**H
1111 * computing blocks of NB columns at a time (note that conjg(W) is
1115 JB = MIN( NB, N-J+1 )
1117 * Update the lower triangle of the diagonal block
1119 DO 100 JJ = J, J + JB - 1
1120 A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
1121 CALL ZGEMV( 'No transpose', J+JB-JJ, K-1, -CONE,
1122 $ A( JJ, 1 ), LDA, W( JJ, 1 ), LDW, CONE,
1124 A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
1127 * Update the rectangular subdiagonal block
1130 $ CALL ZGEMM( 'No transpose', 'Transpose', N-J-JB+1, JB,
1131 $ K-1, -CONE, A( J+JB, 1 ), LDA, W( J, 1 ),
1132 $ LDW, CONE, A( J+JB, J ), LDA )
1135 * Put L21 in standard form by partially undoing the interchanges
1136 * of rows in columns 1:k-1 looping backwards from k-1 to 1
1141 * Undo the interchanges (if any) of rows J and JP2
1142 * (or J and JP2, and J-1 and JP1) at each step J
1146 * (Here, J is a diagonal index)
1151 * (Here, J is a diagonal index)
1156 * (NOTE: Here, J is used to determine row length. Length J
1157 * of the rows to swap back doesn't include diagonal element)
1159 IF( JP2.NE.JJ .AND. J.GE.1 )
1160 $ CALL ZSWAP( J, A( JP2, 1 ), LDA, A( JJ, 1 ), LDA )
1162 IF( KSTEP.EQ.2 .AND. JP1.NE.JJ .AND. J.GE.1 )
1163 $ CALL ZSWAP( J, A( JP1, 1 ), LDA, A( JJ, 1 ), LDA )
1167 * Set KB to the number of columns factorized
1174 * End of ZLAHEF_ROOK