00001 SUBROUTINE DLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND,
00002 $ RANK, WORK, IWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 CHARACTER UPLO
00011 INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ
00012 DOUBLE PRECISION RCOND
00013
00014
00015 INTEGER IWORK( * )
00016 DOUBLE PRECISION B( LDB, * ), D( * ), E( * ), WORK( * )
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076
00077
00078
00079
00080
00081
00082
00083
00084
00085
00086
00087
00088
00089
00090
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
00102
00103
00104
00105
00106
00107
00108
00109
00110
00111
00112 DOUBLE PRECISION ZERO, ONE, TWO
00113 PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 )
00114
00115
00116 INTEGER BX, BXST, C, DIFL, DIFR, GIVCOL, GIVNUM,
00117 $ GIVPTR, I, ICMPQ1, ICMPQ2, IWK, J, K, NLVL,
00118 $ NM1, NSIZE, NSUB, NWORK, PERM, POLES, S, SIZEI,
00119 $ SMLSZP, SQRE, ST, ST1, U, VT, Z
00120 DOUBLE PRECISION CS, EPS, ORGNRM, R, RCND, SN, TOL
00121
00122
00123 INTEGER IDAMAX
00124 DOUBLE PRECISION DLAMCH, DLANST
00125 EXTERNAL IDAMAX, DLAMCH, DLANST
00126
00127
00128 EXTERNAL DCOPY, DGEMM, DLACPY, DLALSA, DLARTG, DLASCL,
00129 $ DLASDA, DLASDQ, DLASET, DLASRT, DROT, XERBLA
00130
00131
00132 INTRINSIC ABS, DBLE, INT, LOG, SIGN
00133
00134
00135
00136
00137
00138 INFO = 0
00139
00140 IF( N.LT.0 ) THEN
00141 INFO = -3
00142 ELSE IF( NRHS.LT.1 ) THEN
00143 INFO = -4
00144 ELSE IF( ( LDB.LT.1 ) .OR. ( LDB.LT.N ) ) THEN
00145 INFO = -8
00146 END IF
00147 IF( INFO.NE.0 ) THEN
00148 CALL XERBLA( 'DLALSD', -INFO )
00149 RETURN
00150 END IF
00151
00152 EPS = DLAMCH( 'Epsilon' )
00153
00154
00155
00156 IF( ( RCOND.LE.ZERO ) .OR. ( RCOND.GE.ONE ) ) THEN
00157 RCND = EPS
00158 ELSE
00159 RCND = RCOND
00160 END IF
00161
00162 RANK = 0
00163
00164
00165
00166 IF( N.EQ.0 ) THEN
00167 RETURN
00168 ELSE IF( N.EQ.1 ) THEN
00169 IF( D( 1 ).EQ.ZERO ) THEN
00170 CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B, LDB )
00171 ELSE
00172 RANK = 1
00173 CALL DLASCL( 'G', 0, 0, D( 1 ), ONE, 1, NRHS, B, LDB, INFO )
00174 D( 1 ) = ABS( D( 1 ) )
00175 END IF
00176 RETURN
00177 END IF
00178
00179
00180
00181 IF( UPLO.EQ.'L' ) THEN
00182 DO 10 I = 1, N - 1
00183 CALL DLARTG( D( I ), E( I ), CS, SN, R )
00184 D( I ) = R
00185 E( I ) = SN*D( I+1 )
00186 D( I+1 ) = CS*D( I+1 )
00187 IF( NRHS.EQ.1 ) THEN
00188 CALL DROT( 1, B( I, 1 ), 1, B( I+1, 1 ), 1, CS, SN )
00189 ELSE
00190 WORK( I*2-1 ) = CS
00191 WORK( I*2 ) = SN
00192 END IF
00193 10 CONTINUE
00194 IF( NRHS.GT.1 ) THEN
00195 DO 30 I = 1, NRHS
00196 DO 20 J = 1, N - 1
00197 CS = WORK( J*2-1 )
00198 SN = WORK( J*2 )
00199 CALL DROT( 1, B( J, I ), 1, B( J+1, I ), 1, CS, SN )
00200 20 CONTINUE
00201 30 CONTINUE
00202 END IF
00203 END IF
00204
00205
00206
00207 NM1 = N - 1
00208 ORGNRM = DLANST( 'M', N, D, E )
00209 IF( ORGNRM.EQ.ZERO ) THEN
00210 CALL DLASET( 'A', N, NRHS, ZERO, ZERO, B, LDB )
00211 RETURN
00212 END IF
00213
00214 CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, 1, D, N, INFO )
00215 CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, NM1, 1, E, NM1, INFO )
00216
00217
00218
00219
00220 IF( N.LE.SMLSIZ ) THEN
00221 NWORK = 1 + N*N
00222 CALL DLASET( 'A', N, N, ZERO, ONE, WORK, N )
00223 CALL DLASDQ( 'U', 0, N, N, 0, NRHS, D, E, WORK, N, WORK, N, B,
00224 $ LDB, WORK( NWORK ), INFO )
00225 IF( INFO.NE.0 ) THEN
00226 RETURN
00227 END IF
00228 TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) )
00229 DO 40 I = 1, N
00230 IF( D( I ).LE.TOL ) THEN
00231 CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B( I, 1 ), LDB )
00232 ELSE
00233 CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS, B( I, 1 ),
00234 $ LDB, INFO )
00235 RANK = RANK + 1
00236 END IF
00237 40 CONTINUE
00238 CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO,
00239 $ WORK( NWORK ), N )
00240 CALL DLACPY( 'A', N, NRHS, WORK( NWORK ), N, B, LDB )
00241
00242
00243
00244 CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
00245 CALL DLASRT( 'D', N, D, INFO )
00246 CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO )
00247
00248 RETURN
00249 END IF
00250
00251
00252
00253 NLVL = INT( LOG( DBLE( N ) / DBLE( SMLSIZ+1 ) ) / LOG( TWO ) ) + 1
00254
00255 SMLSZP = SMLSIZ + 1
00256
00257 U = 1
00258 VT = 1 + SMLSIZ*N
00259 DIFL = VT + SMLSZP*N
00260 DIFR = DIFL + NLVL*N
00261 Z = DIFR + NLVL*N*2
00262 C = Z + NLVL*N
00263 S = C + N
00264 POLES = S + N
00265 GIVNUM = POLES + 2*NLVL*N
00266 BX = GIVNUM + 2*NLVL*N
00267 NWORK = BX + N*NRHS
00268
00269 SIZEI = 1 + N
00270 K = SIZEI + N
00271 GIVPTR = K + N
00272 PERM = GIVPTR + N
00273 GIVCOL = PERM + NLVL*N
00274 IWK = GIVCOL + NLVL*N*2
00275
00276 ST = 1
00277 SQRE = 0
00278 ICMPQ1 = 1
00279 ICMPQ2 = 0
00280 NSUB = 0
00281
00282 DO 50 I = 1, N
00283 IF( ABS( D( I ) ).LT.EPS ) THEN
00284 D( I ) = SIGN( EPS, D( I ) )
00285 END IF
00286 50 CONTINUE
00287
00288 DO 60 I = 1, NM1
00289 IF( ( ABS( E( I ) ).LT.EPS ) .OR. ( I.EQ.NM1 ) ) THEN
00290 NSUB = NSUB + 1
00291 IWORK( NSUB ) = ST
00292
00293
00294
00295
00296 IF( I.LT.NM1 ) THEN
00297
00298
00299
00300 NSIZE = I - ST + 1
00301 IWORK( SIZEI+NSUB-1 ) = NSIZE
00302 ELSE IF( ABS( E( I ) ).GE.EPS ) THEN
00303
00304
00305
00306 NSIZE = N - ST + 1
00307 IWORK( SIZEI+NSUB-1 ) = NSIZE
00308 ELSE
00309
00310
00311
00312
00313
00314 NSIZE = I - ST + 1
00315 IWORK( SIZEI+NSUB-1 ) = NSIZE
00316 NSUB = NSUB + 1
00317 IWORK( NSUB ) = N
00318 IWORK( SIZEI+NSUB-1 ) = 1
00319 CALL DCOPY( NRHS, B( N, 1 ), LDB, WORK( BX+NM1 ), N )
00320 END IF
00321 ST1 = ST - 1
00322 IF( NSIZE.EQ.1 ) THEN
00323
00324
00325
00326
00327 CALL DCOPY( NRHS, B( ST, 1 ), LDB, WORK( BX+ST1 ), N )
00328 ELSE IF( NSIZE.LE.SMLSIZ ) THEN
00329
00330
00331
00332 CALL DLASET( 'A', NSIZE, NSIZE, ZERO, ONE,
00333 $ WORK( VT+ST1 ), N )
00334 CALL DLASDQ( 'U', 0, NSIZE, NSIZE, 0, NRHS, D( ST ),
00335 $ E( ST ), WORK( VT+ST1 ), N, WORK( NWORK ),
00336 $ N, B( ST, 1 ), LDB, WORK( NWORK ), INFO )
00337 IF( INFO.NE.0 ) THEN
00338 RETURN
00339 END IF
00340 CALL DLACPY( 'A', NSIZE, NRHS, B( ST, 1 ), LDB,
00341 $ WORK( BX+ST1 ), N )
00342 ELSE
00343
00344
00345
00346 CALL DLASDA( ICMPQ1, SMLSIZ, NSIZE, SQRE, D( ST ),
00347 $ E( ST ), WORK( U+ST1 ), N, WORK( VT+ST1 ),
00348 $ IWORK( K+ST1 ), WORK( DIFL+ST1 ),
00349 $ WORK( DIFR+ST1 ), WORK( Z+ST1 ),
00350 $ WORK( POLES+ST1 ), IWORK( GIVPTR+ST1 ),
00351 $ IWORK( GIVCOL+ST1 ), N, IWORK( PERM+ST1 ),
00352 $ WORK( GIVNUM+ST1 ), WORK( C+ST1 ),
00353 $ WORK( S+ST1 ), WORK( NWORK ), IWORK( IWK ),
00354 $ INFO )
00355 IF( INFO.NE.0 ) THEN
00356 RETURN
00357 END IF
00358 BXST = BX + ST1
00359 CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, B( ST, 1 ),
00360 $ LDB, WORK( BXST ), N, WORK( U+ST1 ), N,
00361 $ WORK( VT+ST1 ), IWORK( K+ST1 ),
00362 $ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ),
00363 $ WORK( Z+ST1 ), WORK( POLES+ST1 ),
00364 $ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N,
00365 $ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ),
00366 $ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ),
00367 $ IWORK( IWK ), INFO )
00368 IF( INFO.NE.0 ) THEN
00369 RETURN
00370 END IF
00371 END IF
00372 ST = I + 1
00373 END IF
00374 60 CONTINUE
00375
00376
00377
00378 TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) )
00379
00380 DO 70 I = 1, N
00381
00382
00383
00384
00385 IF( ABS( D( I ) ).LE.TOL ) THEN
00386 CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, WORK( BX+I-1 ), N )
00387 ELSE
00388 RANK = RANK + 1
00389 CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS,
00390 $ WORK( BX+I-1 ), N, INFO )
00391 END IF
00392 D( I ) = ABS( D( I ) )
00393 70 CONTINUE
00394
00395
00396
00397 ICMPQ2 = 1
00398 DO 80 I = 1, NSUB
00399 ST = IWORK( I )
00400 ST1 = ST - 1
00401 NSIZE = IWORK( SIZEI+I-1 )
00402 BXST = BX + ST1
00403 IF( NSIZE.EQ.1 ) THEN
00404 CALL DCOPY( NRHS, WORK( BXST ), N, B( ST, 1 ), LDB )
00405 ELSE IF( NSIZE.LE.SMLSIZ ) THEN
00406 CALL DGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE,
00407 $ WORK( VT+ST1 ), N, WORK( BXST ), N, ZERO,
00408 $ B( ST, 1 ), LDB )
00409 ELSE
00410 CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, WORK( BXST ), N,
00411 $ B( ST, 1 ), LDB, WORK( U+ST1 ), N,
00412 $ WORK( VT+ST1 ), IWORK( K+ST1 ),
00413 $ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ),
00414 $ WORK( Z+ST1 ), WORK( POLES+ST1 ),
00415 $ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N,
00416 $ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ),
00417 $ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ),
00418 $ IWORK( IWK ), INFO )
00419 IF( INFO.NE.0 ) THEN
00420 RETURN
00421 END IF
00422 END IF
00423 80 CONTINUE
00424
00425
00426
00427 CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO )
00428 CALL DLASRT( 'D', N, D, INFO )
00429 CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO )
00430
00431 RETURN
00432
00433
00434
00435 END