zlahef.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 672 行 · 第 1/3 页
HTML
672 行
CALL ZGEMV( <span class="string">'No transpose'</span>, K, N-K, -CONE,
$ A( 1, K+1 ), LDA, W( IMAX, KW+1 ), LDW,
$ CONE, W( 1, KW-1 ), 1 )
W( IMAX, KW-1 ) = DBLE( W( IMAX, KW-1 ) )
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> JMAX is the column-index of the largest off-diagonal
</span><span class="comment">*</span><span class="comment"> element in row IMAX, and ROWMAX is its absolute value
</span><span class="comment">*</span><span class="comment">
</span> JMAX = IMAX + IZAMAX( K-IMAX, W( IMAX+1, KW-1 ), 1 )
ROWMAX = CABS1( W( JMAX, KW-1 ) )
IF( IMAX.GT.1 ) THEN
JMAX = IZAMAX( IMAX-1, W( 1, KW-1 ), 1 )
ROWMAX = MAX( ROWMAX, CABS1( W( JMAX, KW-1 ) ) )
END IF
<span class="comment">*</span><span class="comment">
</span> IF( ABSAKK.GE.ALPHA*COLMAX*( COLMAX / ROWMAX ) ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> no interchange, use 1-by-1 pivot block
</span><span class="comment">*</span><span class="comment">
</span> KP = K
ELSE IF( ABS( DBLE( W( IMAX, KW-1 ) ) ).GE.ALPHA*ROWMAX )
$ THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> interchange rows and columns K and IMAX, use 1-by-1
</span><span class="comment">*</span><span class="comment"> pivot block
</span><span class="comment">*</span><span class="comment">
</span> KP = IMAX
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> copy column KW-1 of W to column KW
</span><span class="comment">*</span><span class="comment">
</span> CALL ZCOPY( K, W( 1, KW-1 ), 1, W( 1, KW ), 1 )
ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> interchange rows and columns K-1 and IMAX, use 2-by-2
</span><span class="comment">*</span><span class="comment"> pivot block
</span><span class="comment">*</span><span class="comment">
</span> KP = IMAX
KSTEP = 2
END IF
END IF
<span class="comment">*</span><span class="comment">
</span> KK = K - KSTEP + 1
KKW = NB + KK - N
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Updated column KP is already stored in column KKW of W
</span><span class="comment">*</span><span class="comment">
</span> IF( KP.NE.KK ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Copy non-updated column KK to column KP
</span><span class="comment">*</span><span class="comment">
</span> A( KP, KP ) = DBLE( A( KK, KK ) )
CALL ZCOPY( KK-1-KP, A( KP+1, KK ), 1, A( KP, KP+1 ),
$ LDA )
CALL <a name="ZLACGV.260"></a><a href="zlacgv.f.html#ZLACGV.1">ZLACGV</a>( KK-1-KP, A( KP, KP+1 ), LDA )
CALL ZCOPY( KP-1, A( 1, KK ), 1, A( 1, KP ), 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Interchange rows KK and KP in last KK columns of A and W
</span><span class="comment">*</span><span class="comment">
</span> IF( KK.LT.N )
$ CALL ZSWAP( N-KK, A( KK, KK+1 ), LDA, A( KP, KK+1 ),
$ LDA )
CALL ZSWAP( N-KK+1, W( KK, KKW ), LDW, W( KP, KKW ),
$ LDW )
END IF
<span class="comment">*</span><span class="comment">
</span> IF( KSTEP.EQ.1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> 1-by-1 pivot block D(k): column KW of W now holds
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> W(k) = U(k)*D(k)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> where U(k) is the k-th column of U
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Store U(k) in column k of A
</span><span class="comment">*</span><span class="comment">
</span> CALL ZCOPY( K, W( 1, KW ), 1, A( 1, K ), 1 )
R1 = ONE / DBLE( A( K, K ) )
CALL ZDSCAL( K-1, R1, A( 1, K ), 1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Conjugate W(k)
</span><span class="comment">*</span><span class="comment">
</span> CALL <a name="ZLACGV.288"></a><a href="zlacgv.f.html#ZLACGV.1">ZLACGV</a>( K-1, W( 1, KW ), 1 )
ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> 2-by-2 pivot block D(k): columns KW and KW-1 of W now
</span><span class="comment">*</span><span class="comment"> hold
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> ( W(k-1) W(k) ) = ( U(k-1) U(k) )*D(k)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> where U(k) and U(k-1) are the k-th and (k-1)-th columns
</span><span class="comment">*</span><span class="comment"> of U
</span><span class="comment">*</span><span class="comment">
</span> IF( K.GT.2 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Store U(k) and U(k-1) in columns k and k-1 of A
</span><span class="comment">*</span><span class="comment">
</span> D21 = W( K-1, KW )
D11 = W( K, KW ) / DCONJG( D21 )
D22 = W( K-1, KW-1 ) / D21
T = ONE / ( DBLE( D11*D22 )-ONE )
D21 = T / D21
DO 20 J = 1, K - 2
A( J, K-1 ) = D21*( D11*W( J, KW-1 )-W( J, KW ) )
A( J, K ) = DCONJG( D21 )*
$ ( D22*W( J, KW )-W( J, KW-1 ) )
20 CONTINUE
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Copy D(k) to A
</span><span class="comment">*</span><span class="comment">
</span> A( K-1, K-1 ) = W( K-1, KW-1 )
A( K-1, K ) = W( K-1, KW )
A( K, K ) = W( K, KW )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Conjugate W(k) and W(k-1)
</span><span class="comment">*</span><span class="comment">
</span> CALL <a name="ZLACGV.323"></a><a href="zlacgv.f.html#ZLACGV.1">ZLACGV</a>( K-1, W( 1, KW ), 1 )
CALL <a name="ZLACGV.324"></a><a href="zlacgv.f.html#ZLACGV.1">ZLACGV</a>( K-2, W( 1, KW-1 ), 1 )
END IF
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Store details of the interchanges in IPIV
</span><span class="comment">*</span><span class="comment">
</span> IF( KSTEP.EQ.1 ) THEN
IPIV( K ) = KP
ELSE
IPIV( K ) = -KP
IPIV( K-1 ) = -KP
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Decrease K and return to the start of the main loop
</span><span class="comment">*</span><span class="comment">
</span> K = K - KSTEP
GO TO 10
<span class="comment">*</span><span class="comment">
</span> 30 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Update the upper triangle of A11 (= A(1:k,1:k)) as
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> A11 := A11 - U12*D*U12' = A11 - U12*W'
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> computing blocks of NB columns at a time (note that conjg(W) is
</span><span class="comment">*</span><span class="comment"> actually stored)
</span><span class="comment">*</span><span class="comment">
</span> DO 50 J = ( ( K-1 ) / NB )*NB + 1, 1, -NB
JB = MIN( NB, K-J+1 )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Update the upper triangle of the diagonal block
</span><span class="comment">*</span><span class="comment">
</span> DO 40 JJ = J, J + JB - 1
A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
CALL ZGEMV( <span class="string">'No transpose'</span>, JJ-J+1, N-K, -CONE,
$ A( J, K+1 ), LDA, W( JJ, KW+1 ), LDW, CONE,
$ A( J, JJ ), 1 )
A( JJ, JJ ) = DBLE( A( JJ, JJ ) )
40 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Update the rectangular superdiagonal block
</span><span class="comment">*</span><span class="comment">
</span> CALL ZGEMM( <span class="string">'No transpose'</span>, <span class="string">'Transpose'</span>, J-1, JB, N-K,
$ -CONE, A( 1, K+1 ), LDA, W( J, KW+1 ), LDW,
$ CONE, A( 1, J ), LDA )
50 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Put U12 in standard form by partially undoing the interchanges
</span><span class="comment">*</span><span class="comment"> in columns k+1:n
</span><span class="comment">*</span><span class="comment">
</span> J = K + 1
60 CONTINUE
JJ = J
JP = IPIV( J )
IF( JP.LT.0 ) THEN
JP = -JP
J = J + 1
END IF
J = J + 1
IF( JP.NE.JJ .AND. J.LE.N )
$ CALL ZSWAP( N-J+1, A( JP, J ), LDA, A( JJ, J ), LDA )
IF( J.LE.N )
$ GO TO 60
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Set KB to the number of columns factorized
</span><span class="comment">*</span><span class="comment">
</span> KB = N - K
<span class="comment">*</span><span class="comment">
</span> ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Factorize the leading columns of A using the lower triangle
</span><span class="comment">*</span><span class="comment"> of A and working forwards, and compute the matrix W = L21*D
</span><span class="comment">*</span><span class="comment"> for use in updating A22 (note that conjg(W) is actually stored)
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> K is the main loop index, increasing from 1 in steps of 1 or 2
</span><span class="comment">*</span><span class="comment">
</span> K = 1
70 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Exit from loop
</span><span class="comment">*</span><span class="comment">
</span> IF( ( K.GE.NB .AND. NB.LT.N ) .OR. K.GT.N )
$ GO TO 90
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Copy column K of A to column K of W and update it
</span><span class="comment">*</span><span class="comment">
</span> W( K, K ) = DBLE( A( K, K ) )
IF( K.LT.N )
$ CALL ZCOPY( N-K, A( K+1, K ), 1, W( K+1, K ), 1 )
CALL ZGEMV( <span class="string">'No transpose'</span>, N-K+1, K-1, -CONE, A( K, 1 ), LDA,
$ W( K, 1 ), LDW, CONE, W( K, K ), 1 )
W( K, K ) = DBLE( W( K, K ) )
<span class="comment">*</span><span class="comment">
</span> KSTEP = 1
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Determine rows and columns to be interchanged and whether
</span><span class="comment">*</span><span class="comment"> a 1-by-1 or 2-by-2 pivot block will be used
</span><span class="comment">*</span><span class="comment">
</span> ABSAKK = ABS( DBLE( W( K, K ) ) )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> IMAX is the row-index of the largest off-diagonal element in
</span><span class="comment">*</span><span class="comment"> column K, and COLMAX is its absolute value
</span><span class="comment">*</span><span class="comment">
</span> IF( K.LT.N ) THEN
IMAX = K + IZAMAX( N-K, W( K+1, K ), 1 )
COLMAX = CABS1( W( IMAX, K ) )
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?