root / src / lapack / double / dlalsd.f @ 3
Historique | Voir | Annoter | Télécharger (14,44 ko)
| 1 | 1 | pfleura2 | SUBROUTINE DLALSD( UPLO, SMLSIZ, N, NRHS, D, E, B, LDB, RCOND, |
|---|---|---|---|
| 2 | 1 | pfleura2 | $ RANK, WORK, IWORK, INFO ) |
| 3 | 1 | pfleura2 | * |
| 4 | 1 | pfleura2 | * -- LAPACK routine (version 3.2.2) -- |
| 5 | 1 | pfleura2 | * -- LAPACK is a software package provided by Univ. of Tennessee, -- |
| 6 | 1 | pfleura2 | * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- |
| 7 | 1 | pfleura2 | * June 2010 |
| 8 | 1 | pfleura2 | * |
| 9 | 1 | pfleura2 | * .. Scalar Arguments .. |
| 10 | 1 | pfleura2 | CHARACTER UPLO |
| 11 | 1 | pfleura2 | INTEGER INFO, LDB, N, NRHS, RANK, SMLSIZ |
| 12 | 1 | pfleura2 | DOUBLE PRECISION RCOND |
| 13 | 1 | pfleura2 | * .. |
| 14 | 1 | pfleura2 | * .. Array Arguments .. |
| 15 | 1 | pfleura2 | INTEGER IWORK( * ) |
| 16 | 1 | pfleura2 | DOUBLE PRECISION B( LDB, * ), D( * ), E( * ), WORK( * ) |
| 17 | 1 | pfleura2 | * .. |
| 18 | 1 | pfleura2 | * |
| 19 | 1 | pfleura2 | * Purpose |
| 20 | 1 | pfleura2 | * ======= |
| 21 | 1 | pfleura2 | * |
| 22 | 1 | pfleura2 | * DLALSD uses the singular value decomposition of A to solve the least |
| 23 | 1 | pfleura2 | * squares problem of finding X to minimize the Euclidean norm of each |
| 24 | 1 | pfleura2 | * column of A*X-B, where A is N-by-N upper bidiagonal, and X and B |
| 25 | 1 | pfleura2 | * are N-by-NRHS. The solution X overwrites B. |
| 26 | 1 | pfleura2 | * |
| 27 | 1 | pfleura2 | * The singular values of A smaller than RCOND times the largest |
| 28 | 1 | pfleura2 | * singular value are treated as zero in solving the least squares |
| 29 | 1 | pfleura2 | * problem; in this case a minimum norm solution is returned. |
| 30 | 1 | pfleura2 | * The actual singular values are returned in D in ascending order. |
| 31 | 1 | pfleura2 | * |
| 32 | 1 | pfleura2 | * This code makes very mild assumptions about floating point |
| 33 | 1 | pfleura2 | * arithmetic. It will work on machines with a guard digit in |
| 34 | 1 | pfleura2 | * add/subtract, or on those binary machines without guard digits |
| 35 | 1 | pfleura2 | * which subtract like the Cray XMP, Cray YMP, Cray C 90, or Cray 2. |
| 36 | 1 | pfleura2 | * It could conceivably fail on hexadecimal or decimal machines |
| 37 | 1 | pfleura2 | * without guard digits, but we know of none. |
| 38 | 1 | pfleura2 | * |
| 39 | 1 | pfleura2 | * Arguments |
| 40 | 1 | pfleura2 | * ========= |
| 41 | 1 | pfleura2 | * |
| 42 | 1 | pfleura2 | * UPLO (input) CHARACTER*1 |
| 43 | 1 | pfleura2 | * = 'U': D and E define an upper bidiagonal matrix. |
| 44 | 1 | pfleura2 | * = 'L': D and E define a lower bidiagonal matrix. |
| 45 | 1 | pfleura2 | * |
| 46 | 1 | pfleura2 | * SMLSIZ (input) INTEGER |
| 47 | 1 | pfleura2 | * The maximum size of the subproblems at the bottom of the |
| 48 | 1 | pfleura2 | * computation tree. |
| 49 | 1 | pfleura2 | * |
| 50 | 1 | pfleura2 | * N (input) INTEGER |
| 51 | 1 | pfleura2 | * The dimension of the bidiagonal matrix. N >= 0. |
| 52 | 1 | pfleura2 | * |
| 53 | 1 | pfleura2 | * NRHS (input) INTEGER |
| 54 | 1 | pfleura2 | * The number of columns of B. NRHS must be at least 1. |
| 55 | 1 | pfleura2 | * |
| 56 | 1 | pfleura2 | * D (input/output) DOUBLE PRECISION array, dimension (N) |
| 57 | 1 | pfleura2 | * On entry D contains the main diagonal of the bidiagonal |
| 58 | 1 | pfleura2 | * matrix. On exit, if INFO = 0, D contains its singular values. |
| 59 | 1 | pfleura2 | * |
| 60 | 1 | pfleura2 | * E (input/output) DOUBLE PRECISION array, dimension (N-1) |
| 61 | 1 | pfleura2 | * Contains the super-diagonal entries of the bidiagonal matrix. |
| 62 | 1 | pfleura2 | * On exit, E has been destroyed. |
| 63 | 1 | pfleura2 | * |
| 64 | 1 | pfleura2 | * B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) |
| 65 | 1 | pfleura2 | * On input, B contains the right hand sides of the least |
| 66 | 1 | pfleura2 | * squares problem. On output, B contains the solution X. |
| 67 | 1 | pfleura2 | * |
| 68 | 1 | pfleura2 | * LDB (input) INTEGER |
| 69 | 1 | pfleura2 | * The leading dimension of B in the calling subprogram. |
| 70 | 1 | pfleura2 | * LDB must be at least max(1,N). |
| 71 | 1 | pfleura2 | * |
| 72 | 1 | pfleura2 | * RCOND (input) DOUBLE PRECISION |
| 73 | 1 | pfleura2 | * The singular values of A less than or equal to RCOND times |
| 74 | 1 | pfleura2 | * the largest singular value are treated as zero in solving |
| 75 | 1 | pfleura2 | * the least squares problem. If RCOND is negative, |
| 76 | 1 | pfleura2 | * machine precision is used instead. |
| 77 | 1 | pfleura2 | * For example, if diag(S)*X=B were the least squares problem, |
| 78 | 1 | pfleura2 | * where diag(S) is a diagonal matrix of singular values, the |
| 79 | 1 | pfleura2 | * solution would be X(i) = B(i) / S(i) if S(i) is greater than |
| 80 | 1 | pfleura2 | * RCOND*max(S), and X(i) = 0 if S(i) is less than or equal to |
| 81 | 1 | pfleura2 | * RCOND*max(S). |
| 82 | 1 | pfleura2 | * |
| 83 | 1 | pfleura2 | * RANK (output) INTEGER |
| 84 | 1 | pfleura2 | * The number of singular values of A greater than RCOND times |
| 85 | 1 | pfleura2 | * the largest singular value. |
| 86 | 1 | pfleura2 | * |
| 87 | 1 | pfleura2 | * WORK (workspace) DOUBLE PRECISION array, dimension at least |
| 88 | 1 | pfleura2 | * (9*N + 2*N*SMLSIZ + 8*N*NLVL + N*NRHS + (SMLSIZ+1)**2), |
| 89 | 1 | pfleura2 | * where NLVL = max(0, INT(log_2 (N/(SMLSIZ+1))) + 1). |
| 90 | 1 | pfleura2 | * |
| 91 | 1 | pfleura2 | * IWORK (workspace) INTEGER array, dimension at least |
| 92 | 1 | pfleura2 | * (3*N*NLVL + 11*N) |
| 93 | 1 | pfleura2 | * |
| 94 | 1 | pfleura2 | * INFO (output) INTEGER |
| 95 | 1 | pfleura2 | * = 0: successful exit. |
| 96 | 1 | pfleura2 | * < 0: if INFO = -i, the i-th argument had an illegal value. |
| 97 | 1 | pfleura2 | * > 0: The algorithm failed to compute a singular value while |
| 98 | 1 | pfleura2 | * working on the submatrix lying in rows and columns |
| 99 | 1 | pfleura2 | * INFO/(N+1) through MOD(INFO,N+1). |
| 100 | 1 | pfleura2 | * |
| 101 | 1 | pfleura2 | * Further Details |
| 102 | 1 | pfleura2 | * =============== |
| 103 | 1 | pfleura2 | * |
| 104 | 1 | pfleura2 | * Based on contributions by |
| 105 | 1 | pfleura2 | * Ming Gu and Ren-Cang Li, Computer Science Division, University of |
| 106 | 1 | pfleura2 | * California at Berkeley, USA |
| 107 | 1 | pfleura2 | * Osni Marques, LBNL/NERSC, USA |
| 108 | 1 | pfleura2 | * |
| 109 | 1 | pfleura2 | * ===================================================================== |
| 110 | 1 | pfleura2 | * |
| 111 | 1 | pfleura2 | * .. Parameters .. |
| 112 | 1 | pfleura2 | DOUBLE PRECISION ZERO, ONE, TWO |
| 113 | 1 | pfleura2 | PARAMETER ( ZERO = 0.0D0, ONE = 1.0D0, TWO = 2.0D0 ) |
| 114 | 1 | pfleura2 | * .. |
| 115 | 1 | pfleura2 | * .. Local Scalars .. |
| 116 | 1 | pfleura2 | INTEGER BX, BXST, C, DIFL, DIFR, GIVCOL, GIVNUM, |
| 117 | 1 | pfleura2 | $ GIVPTR, I, ICMPQ1, ICMPQ2, IWK, J, K, NLVL, |
| 118 | 1 | pfleura2 | $ NM1, NSIZE, NSUB, NWORK, PERM, POLES, S, SIZEI, |
| 119 | 1 | pfleura2 | $ SMLSZP, SQRE, ST, ST1, U, VT, Z |
| 120 | 1 | pfleura2 | DOUBLE PRECISION CS, EPS, ORGNRM, R, RCND, SN, TOL |
| 121 | 1 | pfleura2 | * .. |
| 122 | 1 | pfleura2 | * .. External Functions .. |
| 123 | 1 | pfleura2 | INTEGER IDAMAX |
| 124 | 1 | pfleura2 | DOUBLE PRECISION DLAMCH, DLANST |
| 125 | 1 | pfleura2 | EXTERNAL IDAMAX, DLAMCH, DLANST |
| 126 | 1 | pfleura2 | * .. |
| 127 | 1 | pfleura2 | * .. External Subroutines .. |
| 128 | 1 | pfleura2 | EXTERNAL DCOPY, DGEMM, DLACPY, DLALSA, DLARTG, DLASCL, |
| 129 | 1 | pfleura2 | $ DLASDA, DLASDQ, DLASET, DLASRT, DROT, XERBLA |
| 130 | 1 | pfleura2 | * .. |
| 131 | 1 | pfleura2 | * .. Intrinsic Functions .. |
| 132 | 1 | pfleura2 | INTRINSIC ABS, DBLE, INT, LOG, SIGN |
| 133 | 1 | pfleura2 | * .. |
| 134 | 1 | pfleura2 | * .. Executable Statements .. |
| 135 | 1 | pfleura2 | * |
| 136 | 1 | pfleura2 | * Test the input parameters. |
| 137 | 1 | pfleura2 | * |
| 138 | 1 | pfleura2 | INFO = 0 |
| 139 | 1 | pfleura2 | * |
| 140 | 1 | pfleura2 | IF( N.LT.0 ) THEN |
| 141 | 1 | pfleura2 | INFO = -3 |
| 142 | 1 | pfleura2 | ELSE IF( NRHS.LT.1 ) THEN |
| 143 | 1 | pfleura2 | INFO = -4 |
| 144 | 1 | pfleura2 | ELSE IF( ( LDB.LT.1 ) .OR. ( LDB.LT.N ) ) THEN |
| 145 | 1 | pfleura2 | INFO = -8 |
| 146 | 1 | pfleura2 | END IF |
| 147 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 148 | 1 | pfleura2 | CALL XERBLA( 'DLALSD', -INFO ) |
| 149 | 1 | pfleura2 | RETURN |
| 150 | 1 | pfleura2 | END IF |
| 151 | 1 | pfleura2 | * |
| 152 | 1 | pfleura2 | EPS = DLAMCH( 'Epsilon' ) |
| 153 | 1 | pfleura2 | * |
| 154 | 1 | pfleura2 | * Set up the tolerance. |
| 155 | 1 | pfleura2 | * |
| 156 | 1 | pfleura2 | IF( ( RCOND.LE.ZERO ) .OR. ( RCOND.GE.ONE ) ) THEN |
| 157 | 1 | pfleura2 | RCND = EPS |
| 158 | 1 | pfleura2 | ELSE |
| 159 | 1 | pfleura2 | RCND = RCOND |
| 160 | 1 | pfleura2 | END IF |
| 161 | 1 | pfleura2 | * |
| 162 | 1 | pfleura2 | RANK = 0 |
| 163 | 1 | pfleura2 | * |
| 164 | 1 | pfleura2 | * Quick return if possible. |
| 165 | 1 | pfleura2 | * |
| 166 | 1 | pfleura2 | IF( N.EQ.0 ) THEN |
| 167 | 1 | pfleura2 | RETURN |
| 168 | 1 | pfleura2 | ELSE IF( N.EQ.1 ) THEN |
| 169 | 1 | pfleura2 | IF( D( 1 ).EQ.ZERO ) THEN |
| 170 | 1 | pfleura2 | CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B, LDB ) |
| 171 | 1 | pfleura2 | ELSE |
| 172 | 1 | pfleura2 | RANK = 1 |
| 173 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, D( 1 ), ONE, 1, NRHS, B, LDB, INFO ) |
| 174 | 1 | pfleura2 | D( 1 ) = ABS( D( 1 ) ) |
| 175 | 1 | pfleura2 | END IF |
| 176 | 1 | pfleura2 | RETURN |
| 177 | 1 | pfleura2 | END IF |
| 178 | 1 | pfleura2 | * |
| 179 | 1 | pfleura2 | * Rotate the matrix if it is lower bidiagonal. |
| 180 | 1 | pfleura2 | * |
| 181 | 1 | pfleura2 | IF( UPLO.EQ.'L' ) THEN |
| 182 | 1 | pfleura2 | DO 10 I = 1, N - 1 |
| 183 | 1 | pfleura2 | CALL DLARTG( D( I ), E( I ), CS, SN, R ) |
| 184 | 1 | pfleura2 | D( I ) = R |
| 185 | 1 | pfleura2 | E( I ) = SN*D( I+1 ) |
| 186 | 1 | pfleura2 | D( I+1 ) = CS*D( I+1 ) |
| 187 | 1 | pfleura2 | IF( NRHS.EQ.1 ) THEN |
| 188 | 1 | pfleura2 | CALL DROT( 1, B( I, 1 ), 1, B( I+1, 1 ), 1, CS, SN ) |
| 189 | 1 | pfleura2 | ELSE |
| 190 | 1 | pfleura2 | WORK( I*2-1 ) = CS |
| 191 | 1 | pfleura2 | WORK( I*2 ) = SN |
| 192 | 1 | pfleura2 | END IF |
| 193 | 1 | pfleura2 | 10 CONTINUE |
| 194 | 1 | pfleura2 | IF( NRHS.GT.1 ) THEN |
| 195 | 1 | pfleura2 | DO 30 I = 1, NRHS |
| 196 | 1 | pfleura2 | DO 20 J = 1, N - 1 |
| 197 | 1 | pfleura2 | CS = WORK( J*2-1 ) |
| 198 | 1 | pfleura2 | SN = WORK( J*2 ) |
| 199 | 1 | pfleura2 | CALL DROT( 1, B( J, I ), 1, B( J+1, I ), 1, CS, SN ) |
| 200 | 1 | pfleura2 | 20 CONTINUE |
| 201 | 1 | pfleura2 | 30 CONTINUE |
| 202 | 1 | pfleura2 | END IF |
| 203 | 1 | pfleura2 | END IF |
| 204 | 1 | pfleura2 | * |
| 205 | 1 | pfleura2 | * Scale. |
| 206 | 1 | pfleura2 | * |
| 207 | 1 | pfleura2 | NM1 = N - 1 |
| 208 | 1 | pfleura2 | ORGNRM = DLANST( 'M', N, D, E ) |
| 209 | 1 | pfleura2 | IF( ORGNRM.EQ.ZERO ) THEN |
| 210 | 1 | pfleura2 | CALL DLASET( 'A', N, NRHS, ZERO, ZERO, B, LDB ) |
| 211 | 1 | pfleura2 | RETURN |
| 212 | 1 | pfleura2 | END IF |
| 213 | 1 | pfleura2 | * |
| 214 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, 1, D, N, INFO ) |
| 215 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, NM1, 1, E, NM1, INFO ) |
| 216 | 1 | pfleura2 | * |
| 217 | 1 | pfleura2 | * If N is smaller than the minimum divide size SMLSIZ, then solve |
| 218 | 1 | pfleura2 | * the problem with another solver. |
| 219 | 1 | pfleura2 | * |
| 220 | 1 | pfleura2 | IF( N.LE.SMLSIZ ) THEN |
| 221 | 1 | pfleura2 | NWORK = 1 + N*N |
| 222 | 1 | pfleura2 | CALL DLASET( 'A', N, N, ZERO, ONE, WORK, N ) |
| 223 | 1 | pfleura2 | CALL DLASDQ( 'U', 0, N, N, 0, NRHS, D, E, WORK, N, WORK, N, B, |
| 224 | 1 | pfleura2 | $ LDB, WORK( NWORK ), INFO ) |
| 225 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 226 | 1 | pfleura2 | RETURN |
| 227 | 1 | pfleura2 | END IF |
| 228 | 1 | pfleura2 | TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) ) |
| 229 | 1 | pfleura2 | DO 40 I = 1, N |
| 230 | 1 | pfleura2 | IF( D( I ).LE.TOL ) THEN |
| 231 | 1 | pfleura2 | CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, B( I, 1 ), LDB ) |
| 232 | 1 | pfleura2 | ELSE |
| 233 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS, B( I, 1 ), |
| 234 | 1 | pfleura2 | $ LDB, INFO ) |
| 235 | 1 | pfleura2 | RANK = RANK + 1 |
| 236 | 1 | pfleura2 | END IF |
| 237 | 1 | pfleura2 | 40 CONTINUE |
| 238 | 1 | pfleura2 | CALL DGEMM( 'T', 'N', N, NRHS, N, ONE, WORK, N, B, LDB, ZERO, |
| 239 | 1 | pfleura2 | $ WORK( NWORK ), N ) |
| 240 | 1 | pfleura2 | CALL DLACPY( 'A', N, NRHS, WORK( NWORK ), N, B, LDB ) |
| 241 | 1 | pfleura2 | * |
| 242 | 1 | pfleura2 | * Unscale. |
| 243 | 1 | pfleura2 | * |
| 244 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO ) |
| 245 | 1 | pfleura2 | CALL DLASRT( 'D', N, D, INFO ) |
| 246 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO ) |
| 247 | 1 | pfleura2 | * |
| 248 | 1 | pfleura2 | RETURN |
| 249 | 1 | pfleura2 | END IF |
| 250 | 1 | pfleura2 | * |
| 251 | 1 | pfleura2 | * Book-keeping and setting up some constants. |
| 252 | 1 | pfleura2 | * |
| 253 | 1 | pfleura2 | NLVL = INT( LOG( DBLE( N ) / DBLE( SMLSIZ+1 ) ) / LOG( TWO ) ) + 1 |
| 254 | 1 | pfleura2 | * |
| 255 | 1 | pfleura2 | SMLSZP = SMLSIZ + 1 |
| 256 | 1 | pfleura2 | * |
| 257 | 1 | pfleura2 | U = 1 |
| 258 | 1 | pfleura2 | VT = 1 + SMLSIZ*N |
| 259 | 1 | pfleura2 | DIFL = VT + SMLSZP*N |
| 260 | 1 | pfleura2 | DIFR = DIFL + NLVL*N |
| 261 | 1 | pfleura2 | Z = DIFR + NLVL*N*2 |
| 262 | 1 | pfleura2 | C = Z + NLVL*N |
| 263 | 1 | pfleura2 | S = C + N |
| 264 | 1 | pfleura2 | POLES = S + N |
| 265 | 1 | pfleura2 | GIVNUM = POLES + 2*NLVL*N |
| 266 | 1 | pfleura2 | BX = GIVNUM + 2*NLVL*N |
| 267 | 1 | pfleura2 | NWORK = BX + N*NRHS |
| 268 | 1 | pfleura2 | * |
| 269 | 1 | pfleura2 | SIZEI = 1 + N |
| 270 | 1 | pfleura2 | K = SIZEI + N |
| 271 | 1 | pfleura2 | GIVPTR = K + N |
| 272 | 1 | pfleura2 | PERM = GIVPTR + N |
| 273 | 1 | pfleura2 | GIVCOL = PERM + NLVL*N |
| 274 | 1 | pfleura2 | IWK = GIVCOL + NLVL*N*2 |
| 275 | 1 | pfleura2 | * |
| 276 | 1 | pfleura2 | ST = 1 |
| 277 | 1 | pfleura2 | SQRE = 0 |
| 278 | 1 | pfleura2 | ICMPQ1 = 1 |
| 279 | 1 | pfleura2 | ICMPQ2 = 0 |
| 280 | 1 | pfleura2 | NSUB = 0 |
| 281 | 1 | pfleura2 | * |
| 282 | 1 | pfleura2 | DO 50 I = 1, N |
| 283 | 1 | pfleura2 | IF( ABS( D( I ) ).LT.EPS ) THEN |
| 284 | 1 | pfleura2 | D( I ) = SIGN( EPS, D( I ) ) |
| 285 | 1 | pfleura2 | END IF |
| 286 | 1 | pfleura2 | 50 CONTINUE |
| 287 | 1 | pfleura2 | * |
| 288 | 1 | pfleura2 | DO 60 I = 1, NM1 |
| 289 | 1 | pfleura2 | IF( ( ABS( E( I ) ).LT.EPS ) .OR. ( I.EQ.NM1 ) ) THEN |
| 290 | 1 | pfleura2 | NSUB = NSUB + 1 |
| 291 | 1 | pfleura2 | IWORK( NSUB ) = ST |
| 292 | 1 | pfleura2 | * |
| 293 | 1 | pfleura2 | * Subproblem found. First determine its size and then |
| 294 | 1 | pfleura2 | * apply divide and conquer on it. |
| 295 | 1 | pfleura2 | * |
| 296 | 1 | pfleura2 | IF( I.LT.NM1 ) THEN |
| 297 | 1 | pfleura2 | * |
| 298 | 1 | pfleura2 | * A subproblem with E(I) small for I < NM1. |
| 299 | 1 | pfleura2 | * |
| 300 | 1 | pfleura2 | NSIZE = I - ST + 1 |
| 301 | 1 | pfleura2 | IWORK( SIZEI+NSUB-1 ) = NSIZE |
| 302 | 1 | pfleura2 | ELSE IF( ABS( E( I ) ).GE.EPS ) THEN |
| 303 | 1 | pfleura2 | * |
| 304 | 1 | pfleura2 | * A subproblem with E(NM1) not too small but I = NM1. |
| 305 | 1 | pfleura2 | * |
| 306 | 1 | pfleura2 | NSIZE = N - ST + 1 |
| 307 | 1 | pfleura2 | IWORK( SIZEI+NSUB-1 ) = NSIZE |
| 308 | 1 | pfleura2 | ELSE |
| 309 | 1 | pfleura2 | * |
| 310 | 1 | pfleura2 | * A subproblem with E(NM1) small. This implies an |
| 311 | 1 | pfleura2 | * 1-by-1 subproblem at D(N), which is not solved |
| 312 | 1 | pfleura2 | * explicitly. |
| 313 | 1 | pfleura2 | * |
| 314 | 1 | pfleura2 | NSIZE = I - ST + 1 |
| 315 | 1 | pfleura2 | IWORK( SIZEI+NSUB-1 ) = NSIZE |
| 316 | 1 | pfleura2 | NSUB = NSUB + 1 |
| 317 | 1 | pfleura2 | IWORK( NSUB ) = N |
| 318 | 1 | pfleura2 | IWORK( SIZEI+NSUB-1 ) = 1 |
| 319 | 1 | pfleura2 | CALL DCOPY( NRHS, B( N, 1 ), LDB, WORK( BX+NM1 ), N ) |
| 320 | 1 | pfleura2 | END IF |
| 321 | 1 | pfleura2 | ST1 = ST - 1 |
| 322 | 1 | pfleura2 | IF( NSIZE.EQ.1 ) THEN |
| 323 | 1 | pfleura2 | * |
| 324 | 1 | pfleura2 | * This is a 1-by-1 subproblem and is not solved |
| 325 | 1 | pfleura2 | * explicitly. |
| 326 | 1 | pfleura2 | * |
| 327 | 1 | pfleura2 | CALL DCOPY( NRHS, B( ST, 1 ), LDB, WORK( BX+ST1 ), N ) |
| 328 | 1 | pfleura2 | ELSE IF( NSIZE.LE.SMLSIZ ) THEN |
| 329 | 1 | pfleura2 | * |
| 330 | 1 | pfleura2 | * This is a small subproblem and is solved by DLASDQ. |
| 331 | 1 | pfleura2 | * |
| 332 | 1 | pfleura2 | CALL DLASET( 'A', NSIZE, NSIZE, ZERO, ONE, |
| 333 | 1 | pfleura2 | $ WORK( VT+ST1 ), N ) |
| 334 | 1 | pfleura2 | CALL DLASDQ( 'U', 0, NSIZE, NSIZE, 0, NRHS, D( ST ), |
| 335 | 1 | pfleura2 | $ E( ST ), WORK( VT+ST1 ), N, WORK( NWORK ), |
| 336 | 1 | pfleura2 | $ N, B( ST, 1 ), LDB, WORK( NWORK ), INFO ) |
| 337 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 338 | 1 | pfleura2 | RETURN |
| 339 | 1 | pfleura2 | END IF |
| 340 | 1 | pfleura2 | CALL DLACPY( 'A', NSIZE, NRHS, B( ST, 1 ), LDB, |
| 341 | 1 | pfleura2 | $ WORK( BX+ST1 ), N ) |
| 342 | 1 | pfleura2 | ELSE |
| 343 | 1 | pfleura2 | * |
| 344 | 1 | pfleura2 | * A large problem. Solve it using divide and conquer. |
| 345 | 1 | pfleura2 | * |
| 346 | 1 | pfleura2 | CALL DLASDA( ICMPQ1, SMLSIZ, NSIZE, SQRE, D( ST ), |
| 347 | 1 | pfleura2 | $ E( ST ), WORK( U+ST1 ), N, WORK( VT+ST1 ), |
| 348 | 1 | pfleura2 | $ IWORK( K+ST1 ), WORK( DIFL+ST1 ), |
| 349 | 1 | pfleura2 | $ WORK( DIFR+ST1 ), WORK( Z+ST1 ), |
| 350 | 1 | pfleura2 | $ WORK( POLES+ST1 ), IWORK( GIVPTR+ST1 ), |
| 351 | 1 | pfleura2 | $ IWORK( GIVCOL+ST1 ), N, IWORK( PERM+ST1 ), |
| 352 | 1 | pfleura2 | $ WORK( GIVNUM+ST1 ), WORK( C+ST1 ), |
| 353 | 1 | pfleura2 | $ WORK( S+ST1 ), WORK( NWORK ), IWORK( IWK ), |
| 354 | 1 | pfleura2 | $ INFO ) |
| 355 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 356 | 1 | pfleura2 | RETURN |
| 357 | 1 | pfleura2 | END IF |
| 358 | 1 | pfleura2 | BXST = BX + ST1 |
| 359 | 1 | pfleura2 | CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, B( ST, 1 ), |
| 360 | 1 | pfleura2 | $ LDB, WORK( BXST ), N, WORK( U+ST1 ), N, |
| 361 | 1 | pfleura2 | $ WORK( VT+ST1 ), IWORK( K+ST1 ), |
| 362 | 1 | pfleura2 | $ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ), |
| 363 | 1 | pfleura2 | $ WORK( Z+ST1 ), WORK( POLES+ST1 ), |
| 364 | 1 | pfleura2 | $ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N, |
| 365 | 1 | pfleura2 | $ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ), |
| 366 | 1 | pfleura2 | $ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ), |
| 367 | 1 | pfleura2 | $ IWORK( IWK ), INFO ) |
| 368 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 369 | 1 | pfleura2 | RETURN |
| 370 | 1 | pfleura2 | END IF |
| 371 | 1 | pfleura2 | END IF |
| 372 | 1 | pfleura2 | ST = I + 1 |
| 373 | 1 | pfleura2 | END IF |
| 374 | 1 | pfleura2 | 60 CONTINUE |
| 375 | 1 | pfleura2 | * |
| 376 | 1 | pfleura2 | * Apply the singular values and treat the tiny ones as zero. |
| 377 | 1 | pfleura2 | * |
| 378 | 1 | pfleura2 | TOL = RCND*ABS( D( IDAMAX( N, D, 1 ) ) ) |
| 379 | 1 | pfleura2 | * |
| 380 | 1 | pfleura2 | DO 70 I = 1, N |
| 381 | 1 | pfleura2 | * |
| 382 | 1 | pfleura2 | * Some of the elements in D can be negative because 1-by-1 |
| 383 | 1 | pfleura2 | * subproblems were not solved explicitly. |
| 384 | 1 | pfleura2 | * |
| 385 | 1 | pfleura2 | IF( ABS( D( I ) ).LE.TOL ) THEN |
| 386 | 1 | pfleura2 | CALL DLASET( 'A', 1, NRHS, ZERO, ZERO, WORK( BX+I-1 ), N ) |
| 387 | 1 | pfleura2 | ELSE |
| 388 | 1 | pfleura2 | RANK = RANK + 1 |
| 389 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, D( I ), ONE, 1, NRHS, |
| 390 | 1 | pfleura2 | $ WORK( BX+I-1 ), N, INFO ) |
| 391 | 1 | pfleura2 | END IF |
| 392 | 1 | pfleura2 | D( I ) = ABS( D( I ) ) |
| 393 | 1 | pfleura2 | 70 CONTINUE |
| 394 | 1 | pfleura2 | * |
| 395 | 1 | pfleura2 | * Now apply back the right singular vectors. |
| 396 | 1 | pfleura2 | * |
| 397 | 1 | pfleura2 | ICMPQ2 = 1 |
| 398 | 1 | pfleura2 | DO 80 I = 1, NSUB |
| 399 | 1 | pfleura2 | ST = IWORK( I ) |
| 400 | 1 | pfleura2 | ST1 = ST - 1 |
| 401 | 1 | pfleura2 | NSIZE = IWORK( SIZEI+I-1 ) |
| 402 | 1 | pfleura2 | BXST = BX + ST1 |
| 403 | 1 | pfleura2 | IF( NSIZE.EQ.1 ) THEN |
| 404 | 1 | pfleura2 | CALL DCOPY( NRHS, WORK( BXST ), N, B( ST, 1 ), LDB ) |
| 405 | 1 | pfleura2 | ELSE IF( NSIZE.LE.SMLSIZ ) THEN |
| 406 | 1 | pfleura2 | CALL DGEMM( 'T', 'N', NSIZE, NRHS, NSIZE, ONE, |
| 407 | 1 | pfleura2 | $ WORK( VT+ST1 ), N, WORK( BXST ), N, ZERO, |
| 408 | 1 | pfleura2 | $ B( ST, 1 ), LDB ) |
| 409 | 1 | pfleura2 | ELSE |
| 410 | 1 | pfleura2 | CALL DLALSA( ICMPQ2, SMLSIZ, NSIZE, NRHS, WORK( BXST ), N, |
| 411 | 1 | pfleura2 | $ B( ST, 1 ), LDB, WORK( U+ST1 ), N, |
| 412 | 1 | pfleura2 | $ WORK( VT+ST1 ), IWORK( K+ST1 ), |
| 413 | 1 | pfleura2 | $ WORK( DIFL+ST1 ), WORK( DIFR+ST1 ), |
| 414 | 1 | pfleura2 | $ WORK( Z+ST1 ), WORK( POLES+ST1 ), |
| 415 | 1 | pfleura2 | $ IWORK( GIVPTR+ST1 ), IWORK( GIVCOL+ST1 ), N, |
| 416 | 1 | pfleura2 | $ IWORK( PERM+ST1 ), WORK( GIVNUM+ST1 ), |
| 417 | 1 | pfleura2 | $ WORK( C+ST1 ), WORK( S+ST1 ), WORK( NWORK ), |
| 418 | 1 | pfleura2 | $ IWORK( IWK ), INFO ) |
| 419 | 1 | pfleura2 | IF( INFO.NE.0 ) THEN |
| 420 | 1 | pfleura2 | RETURN |
| 421 | 1 | pfleura2 | END IF |
| 422 | 1 | pfleura2 | END IF |
| 423 | 1 | pfleura2 | 80 CONTINUE |
| 424 | 1 | pfleura2 | * |
| 425 | 1 | pfleura2 | * Unscale and sort the singular values. |
| 426 | 1 | pfleura2 | * |
| 427 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ONE, ORGNRM, N, 1, D, N, INFO ) |
| 428 | 1 | pfleura2 | CALL DLASRT( 'D', N, D, INFO ) |
| 429 | 1 | pfleura2 | CALL DLASCL( 'G', 0, 0, ORGNRM, ONE, N, NRHS, B, LDB, INFO ) |
| 430 | 1 | pfleura2 | * |
| 431 | 1 | pfleura2 | RETURN |
| 432 | 1 | pfleura2 | * |
| 433 | 1 | pfleura2 | * End of DLALSD |
| 434 | 1 | pfleura2 | * |
| 435 | 1 | pfleura2 | END |