zlalsd.f.html
来自「famous linear algebra library (LAPACK) p」· HTML 代码 · 共 625 行 · 第 1/3 页
HTML
625 行
DO 10 I = 1, N - 1
CALL <a name="DLARTG.192"></a><a href="dlartg.f.html#DLARTG.1">DLARTG</a>( D( I ), E( I ), CS, SN, R )
D( I ) = R
E( I ) = SN*D( I+1 )
D( I+1 ) = CS*D( I+1 )
IF( NRHS.EQ.1 ) THEN
CALL ZDROT( 1, B( I, 1 ), 1, B( I+1, 1 ), 1, CS, SN )
ELSE
RWORK( I*2-1 ) = CS
RWORK( I*2 ) = SN
END IF
10 CONTINUE
IF( NRHS.GT.1 ) THEN
DO 30 I = 1, NRHS
DO 20 J = 1, N - 1
CS = RWORK( J*2-1 )
SN = RWORK( J*2 )
CALL ZDROT( 1, B( J, I ), 1, B( J+1, I ), 1, CS, SN )
20 CONTINUE
30 CONTINUE
END IF
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Scale.
</span><span class="comment">*</span><span class="comment">
</span> NM1 = N - 1
ORGNRM = <a name="DLANST.217"></a><a href="dlanst.f.html#DLANST.1">DLANST</a>( <span class="string">'M'</span>, N, D, E )
IF( ORGNRM.EQ.ZERO ) THEN
CALL <a name="ZLASET.219"></a><a href="zlaset.f.html#ZLASET.1">ZLASET</a>( <span class="string">'A'</span>, N, NRHS, CZERO, CZERO, B, LDB )
RETURN
END IF
<span class="comment">*</span><span class="comment">
</span> CALL <a name="DLASCL.223"></a><a href="dlascl.f.html#DLASCL.1">DLASCL</a>( <span class="string">'G'</span>, 0, 0, ORGNRM, ONE, N, 1, D, N, INFO )
CALL <a name="DLASCL.224"></a><a href="dlascl.f.html#DLASCL.1">DLASCL</a>( <span class="string">'G'</span>, 0, 0, ORGNRM, ONE, NM1, 1, E, NM1, INFO )
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> If N is smaller than the minimum divide size SMLSIZ, then solve
</span><span class="comment">*</span><span class="comment"> the problem with another solver.
</span><span class="comment">*</span><span class="comment">
</span> IF( N.LE.SMLSIZ ) THEN
IRWU = 1
IRWVT = IRWU + N*N
IRWWRK = IRWVT + N*N
IRWRB = IRWWRK
IRWIB = IRWRB + N*NRHS
IRWB = IRWIB + N*NRHS
CALL <a name="DLASET.236"></a><a href="dlaset.f.html#DLASET.1">DLASET</a>( <span class="string">'A'</span>, N, N, ZERO, ONE, RWORK( IRWU ), N )
CALL <a name="DLASET.237"></a><a href="dlaset.f.html#DLASET.1">DLASET</a>( <span class="string">'A'</span>, N, N, ZERO, ONE, RWORK( IRWVT ), N )
CALL <a name="DLASDQ.238"></a><a href="dlasdq.f.html#DLASDQ.1">DLASDQ</a>( <span class="string">'U'</span>, 0, N, N, N, 0, D, E, RWORK( IRWVT ), N,
$ RWORK( IRWU ), N, RWORK( IRWWRK ), 1,
$ RWORK( IRWWRK ), INFO )
IF( INFO.NE.0 ) THEN
RETURN
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> In the real version, B is passed to <a name="DLASDQ.245"></a><a href="dlasdq.f.html#DLASDQ.1">DLASDQ</a> and multiplied
</span><span class="comment">*</span><span class="comment"> internally by Q'. Here B is complex and that product is
</span><span class="comment">*</span><span class="comment"> computed below in two steps (real and imaginary parts).
</span><span class="comment">*</span><span class="comment">
</span> J = IRWB - 1
DO 50 JCOL = 1, NRHS
DO 40 JROW = 1, N
J = J + 1
RWORK( J ) = DBLE( B( JROW, JCOL ) )
40 CONTINUE
50 CONTINUE
CALL DGEMM( <span class="string">'T'</span>, <span class="string">'N'</span>, N, NRHS, N, ONE, RWORK( IRWU ), N,
$ RWORK( IRWB ), N, ZERO, RWORK( IRWRB ), N )
J = IRWB - 1
DO 70 JCOL = 1, NRHS
DO 60 JROW = 1, N
J = J + 1
RWORK( J ) = DIMAG( B( JROW, JCOL ) )
60 CONTINUE
70 CONTINUE
CALL DGEMM( <span class="string">'T'</span>, <span class="string">'N'</span>, N, NRHS, N, ONE, RWORK( IRWU ), N,
$ RWORK( IRWB ), N, ZERO, RWORK( IRWIB ), N )
JREAL = IRWRB - 1
JIMAG = IRWIB - 1
DO 90 JCOL = 1, NRHS
DO 80 JROW = 1, N
JREAL = JREAL + 1
JIMAG = JIMAG + 1
B( JROW, JCOL ) = DCMPLX( RWORK( JREAL ),
$ RWORK( JIMAG ) )
80 CONTINUE
90 CONTINUE
<span class="comment">*</span><span class="comment">
</span> TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) )
DO 100 I = 1, N
IF( D( I ).LE.TOL ) THEN
CALL <a name="ZLASET.281"></a><a href="zlaset.f.html#ZLASET.1">ZLASET</a>( <span class="string">'A'</span>, 1, NRHS, CZERO, CZERO, B( I, 1 ), LDB )
ELSE
CALL <a name="ZLASCL.283"></a><a href="zlascl.f.html#ZLASCL.1">ZLASCL</a>( <span class="string">'G'</span>, 0, 0, D( I ), ONE, 1, NRHS, B( I, 1 ),
$ LDB, INFO )
RANK = RANK + 1
END IF
100 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Since B is complex, the following call to DGEMM is performed
</span><span class="comment">*</span><span class="comment"> in two steps (real and imaginary parts). That is for V * B
</span><span class="comment">*</span><span class="comment"> (in the real version of the code V' is stored in WORK).
</span><span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO,
</span><span class="comment">*</span><span class="comment"> $ WORK( NWORK ), N )
</span><span class="comment">*</span><span class="comment">
</span> J = IRWB - 1
DO 120 JCOL = 1, NRHS
DO 110 JROW = 1, N
J = J + 1
RWORK( J ) = DBLE( B( JROW, JCOL ) )
110 CONTINUE
120 CONTINUE
CALL DGEMM( <span class="string">'T'</span>, <span class="string">'N'</span>, N, NRHS, N, ONE, RWORK( IRWVT ), N,
$ RWORK( IRWB ), N, ZERO, RWORK( IRWRB ), N )
J = IRWB - 1
DO 140 JCOL = 1, NRHS
DO 130 JROW = 1, N
J = J + 1
RWORK( J ) = DIMAG( B( JROW, JCOL ) )
130 CONTINUE
140 CONTINUE
CALL DGEMM( <span class="string">'T'</span>, <span class="string">'N'</span>, N, NRHS, N, ONE, RWORK( IRWVT ), N,
$ RWORK( IRWB ), N, ZERO, RWORK( IRWIB ), N )
JREAL = IRWRB - 1
JIMAG = IRWIB - 1
DO 160 JCOL = 1, NRHS
DO 150 JROW = 1, N
JREAL = JREAL + 1
JIMAG = JIMAG + 1
B( JROW, JCOL ) = DCMPLX( RWORK( JREAL ),
$ RWORK( JIMAG ) )
150 CONTINUE
160 CONTINUE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Unscale.
</span><span class="comment">*</span><span class="comment">
</span> CALL <a name="DLASCL.327"></a><a href="dlascl.f.html#DLASCL.1">DLASCL</a>( <span class="string">'G'</span>, 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
CALL <a name="DLASRT.328"></a><a href="dlasrt.f.html#DLASRT.1">DLASRT</a>( <span class="string">'D'</span>, N, D, INFO )
CALL <a name="ZLASCL.329"></a><a href="zlascl.f.html#ZLASCL.1">ZLASCL</a>( <span class="string">'G'</span>, 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO )
<span class="comment">*</span><span class="comment">
</span> RETURN
END IF
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Book-keeping and setting up some constants.
</span><span class="comment">*</span><span class="comment">
</span> NLVL = INT( LOG( DBLE( N ) / DBLE( SMLSIZ+1 ) ) / LOG( TWO ) ) + 1
<span class="comment">*</span><span class="comment">
</span> SMLSZP = SMLSIZ + 1
<span class="comment">*</span><span class="comment">
</span> U = 1
VT = 1 + SMLSIZ*N
DIFL = VT + SMLSZP*N
DIFR = DIFL + NLVL*N
Z = DIFR + NLVL*N*2
C = Z + NLVL*N
S = C + N
POLES = S + N
GIVNUM = POLES + 2*NLVL*N
NRWORK = GIVNUM + 2*NLVL*N
BX = 1
<span class="comment">*</span><span class="comment">
</span> IRWRB = NRWORK
IRWIB = IRWRB + SMLSIZ*NRHS
IRWB = IRWIB + SMLSIZ*NRHS
<span class="comment">*</span><span class="comment">
</span> SIZEI = 1 + N
K = SIZEI + N
GIVPTR = K + N
PERM = GIVPTR + N
GIVCOL = PERM + NLVL*N
IWK = GIVCOL + NLVL*N*2
<span class="comment">*</span><span class="comment">
</span> ST = 1
SQRE = 0
ICMPQ1 = 1
ICMPQ2 = 0
NSUB = 0
<span class="comment">*</span><span class="comment">
</span> DO 170 I = 1, N
IF( ABS( D( I ) ).LT.EPS ) THEN
D( I ) = SIGN( EPS, D( I ) )
END IF
170 CONTINUE
<span class="comment">*</span><span class="comment">
</span> DO 240 I = 1, NM1
IF( ( ABS( E( I ) ).LT.EPS ) .OR. ( I.EQ.NM1 ) ) THEN
NSUB = NSUB + 1
IWORK( NSUB ) = ST
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> Subproblem found. First determine its size and then
</span><span class="comment">*</span><span class="comment"> apply divide and conquer on it.
</span><span class="comment">*</span><span class="comment">
</span> IF( I.LT.NM1 ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> A subproblem with E(I) small for I < NM1.
</span><span class="comment">*</span><span class="comment">
</span> NSIZE = I - ST + 1
IWORK( SIZEI+NSUB-1 ) = NSIZE
ELSE IF( ABS( E( I ) ).GE.EPS ) THEN
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> A subproblem with E(NM1) not too small but I = NM1.
</span><span class="comment">*</span><span class="comment">
</span> NSIZE = N - ST + 1
IWORK( SIZEI+NSUB-1 ) = NSIZE
ELSE
<span class="comment">*</span><span class="comment">
</span><span class="comment">*</span><span class="comment"> A subproblem with E(NM1) small. This implies an
</span><span class="comment">*</span><span class="comment"> 1-by-1 subproblem at D(N), which is not solved
</span><span class="comment">*</span><span class="comment"> explicitly.
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?