00001 SUBROUTINE CGELSD( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
00002 $ WORK, LWORK, RWORK, IWORK, INFO )
00003
00004
00005
00006
00007
00008
00009
00010 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
00011 REAL RCOND
00012
00013
00014 INTEGER IWORK( * )
00015 REAL RWORK( * ), S( * )
00016 COMPLEX A( LDA, * ), B( LDB, * ), 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
00113
00114
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152 REAL ZERO, ONE, TWO
00153 PARAMETER ( ZERO = 0.0E+0, ONE = 1.0E+0, TWO = 2.0E+0 )
00154 COMPLEX CZERO
00155 PARAMETER ( CZERO = ( 0.0E+0, 0.0E+0 ) )
00156
00157
00158 LOGICAL LQUERY
00159 INTEGER IASCL, IBSCL, IE, IL, ITAU, ITAUP, ITAUQ,
00160 $ LDWORK, LIWORK, LRWORK, MAXMN, MAXWRK, MINMN,
00161 $ MINWRK, MM, MNTHR, NLVL, NRWORK, NWORK, SMLSIZ
00162 REAL ANRM, BIGNUM, BNRM, EPS, SFMIN, SMLNUM
00163
00164
00165 EXTERNAL CGEBRD, CGELQF, CGEQRF, CLACPY,
00166 $ CLALSD, CLASCL, CLASET, CUNMBR,
00167 $ CUNMLQ, CUNMQR, SLABAD, SLASCL,
00168 $ SLASET, XERBLA
00169
00170
00171 INTEGER ILAENV
00172 REAL CLANGE, SLAMCH
00173 EXTERNAL CLANGE, SLAMCH, ILAENV
00174
00175
00176 INTRINSIC INT, LOG, MAX, MIN, REAL
00177
00178
00179
00180
00181
00182 INFO = 0
00183 MINMN = MIN( M, N )
00184 MAXMN = MAX( M, N )
00185 LQUERY = ( LWORK.EQ.-1 )
00186 IF( M.LT.0 ) THEN
00187 INFO = -1
00188 ELSE IF( N.LT.0 ) THEN
00189 INFO = -2
00190 ELSE IF( NRHS.LT.0 ) THEN
00191 INFO = -3
00192 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN
00193 INFO = -5
00194 ELSE IF( LDB.LT.MAX( 1, MAXMN ) ) THEN
00195 INFO = -7
00196 END IF
00197
00198
00199
00200
00201
00202
00203
00204
00205 IF( INFO.EQ.0 ) THEN
00206 MINWRK = 1
00207 MAXWRK = 1
00208 LIWORK = 1
00209 LRWORK = 1
00210 IF( MINMN.GT.0 ) THEN
00211 SMLSIZ = ILAENV( 9, 'CGELSD', ' ', 0, 0, 0, 0 )
00212 MNTHR = ILAENV( 6, 'CGELSD', ' ', M, N, NRHS, -1 )
00213 NLVL = MAX( INT( LOG( REAL( MINMN ) / REAL( SMLSIZ + 1 ) ) /
00214 $ LOG( TWO ) ) + 1, 0 )
00215 LIWORK = 3*MINMN*NLVL + 11*MINMN
00216 MM = M
00217 IF( M.GE.N .AND. M.GE.MNTHR ) THEN
00218
00219
00220
00221
00222 MM = N
00223 MAXWRK = MAX( MAXWRK, N*ILAENV( 1, 'CGEQRF', ' ', M, N,
00224 $ -1, -1 ) )
00225 MAXWRK = MAX( MAXWRK, NRHS*ILAENV( 1, 'CUNMQR', 'LC', M,
00226 $ NRHS, N, -1 ) )
00227 END IF
00228 IF( M.GE.N ) THEN
00229
00230
00231
00232 LRWORK = 10*N + 2*N*SMLSIZ + 8*N*NLVL + 3*SMLSIZ*NRHS +
00233 $ MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
00234 MAXWRK = MAX( MAXWRK, 2*N + ( MM + N )*ILAENV( 1,
00235 $ 'CGEBRD', ' ', MM, N, -1, -1 ) )
00236 MAXWRK = MAX( MAXWRK, 2*N + NRHS*ILAENV( 1, 'CUNMBR',
00237 $ 'QLC', MM, NRHS, N, -1 ) )
00238 MAXWRK = MAX( MAXWRK, 2*N + ( N - 1 )*ILAENV( 1,
00239 $ 'CUNMBR', 'PLN', N, NRHS, N, -1 ) )
00240 MAXWRK = MAX( MAXWRK, 2*N + N*NRHS )
00241 MINWRK = MAX( 2*N + MM, 2*N + N*NRHS )
00242 END IF
00243 IF( N.GT.M ) THEN
00244 LRWORK = 10*M + 2*M*SMLSIZ + 8*M*NLVL + 3*SMLSIZ*NRHS +
00245 $ MAX( (SMLSIZ+1)**2, N*(1+NRHS) + 2*NRHS )
00246 IF( N.GE.MNTHR ) THEN
00247
00248
00249
00250
00251 MAXWRK = M + M*ILAENV( 1, 'CGELQF', ' ', M, N, -1,
00252 $ -1 )
00253 MAXWRK = MAX( MAXWRK, M*M + 4*M + 2*M*ILAENV( 1,
00254 $ 'CGEBRD', ' ', M, M, -1, -1 ) )
00255 MAXWRK = MAX( MAXWRK, M*M + 4*M + NRHS*ILAENV( 1,
00256 $ 'CUNMBR', 'QLC', M, NRHS, M, -1 ) )
00257 MAXWRK = MAX( MAXWRK, M*M + 4*M + ( M - 1 )*ILAENV( 1,
00258 $ 'CUNMLQ', 'LC', N, NRHS, M, -1 ) )
00259 IF( NRHS.GT.1 ) THEN
00260 MAXWRK = MAX( MAXWRK, M*M + M + M*NRHS )
00261 ELSE
00262 MAXWRK = MAX( MAXWRK, M*M + 2*M )
00263 END IF
00264 MAXWRK = MAX( MAXWRK, M*M + 4*M + M*NRHS )
00265
00266
00267 MAXWRK = MAX( MAXWRK,
00268 $ 4*M+M*M+MAX( M, 2*M-4, NRHS, N-3*M ) )
00269 ELSE
00270
00271
00272
00273 MAXWRK = 2*M + ( N + M )*ILAENV( 1, 'CGEBRD', ' ', M,
00274 $ N, -1, -1 )
00275 MAXWRK = MAX( MAXWRK, 2*M + NRHS*ILAENV( 1, 'CUNMBR',
00276 $ 'QLC', M, NRHS, M, -1 ) )
00277 MAXWRK = MAX( MAXWRK, 2*M + M*ILAENV( 1, 'CUNMBR',
00278 $ 'PLN', N, NRHS, M, -1 ) )
00279 MAXWRK = MAX( MAXWRK, 2*M + M*NRHS )
00280 END IF
00281 MINWRK = MAX( 2*M + N, 2*M + M*NRHS )
00282 END IF
00283 END IF
00284 MINWRK = MIN( MINWRK, MAXWRK )
00285 WORK( 1 ) = MAXWRK
00286 IWORK( 1 ) = LIWORK
00287 RWORK( 1 ) = LRWORK
00288
00289 IF( LWORK.LT.MINWRK .AND. .NOT.LQUERY ) THEN
00290 INFO = -12
00291 END IF
00292 END IF
00293
00294 IF( INFO.NE.0 ) THEN
00295 CALL XERBLA( 'CGELSD', -INFO )
00296 RETURN
00297 ELSE IF( LQUERY ) THEN
00298 RETURN
00299 END IF
00300
00301
00302
00303 IF( M.EQ.0 .OR. N.EQ.0 ) THEN
00304 RANK = 0
00305 RETURN
00306 END IF
00307
00308
00309
00310 EPS = SLAMCH( 'P' )
00311 SFMIN = SLAMCH( 'S' )
00312 SMLNUM = SFMIN / EPS
00313 BIGNUM = ONE / SMLNUM
00314 CALL SLABAD( SMLNUM, BIGNUM )
00315
00316
00317
00318 ANRM = CLANGE( 'M', M, N, A, LDA, RWORK )
00319 IASCL = 0
00320 IF( ANRM.GT.ZERO .AND. ANRM.LT.SMLNUM ) THEN
00321
00322
00323
00324 CALL CLASCL( 'G', 0, 0, ANRM, SMLNUM, M, N, A, LDA, INFO )
00325 IASCL = 1
00326 ELSE IF( ANRM.GT.BIGNUM ) THEN
00327
00328
00329
00330 CALL CLASCL( 'G', 0, 0, ANRM, BIGNUM, M, N, A, LDA, INFO )
00331 IASCL = 2
00332 ELSE IF( ANRM.EQ.ZERO ) THEN
00333
00334
00335
00336 CALL CLASET( 'F', MAX( M, N ), NRHS, CZERO, CZERO, B, LDB )
00337 CALL SLASET( 'F', MINMN, 1, ZERO, ZERO, S, 1 )
00338 RANK = 0
00339 GO TO 10
00340 END IF
00341
00342
00343
00344 BNRM = CLANGE( 'M', M, NRHS, B, LDB, RWORK )
00345 IBSCL = 0
00346 IF( BNRM.GT.ZERO .AND. BNRM.LT.SMLNUM ) THEN
00347
00348
00349
00350 CALL CLASCL( 'G', 0, 0, BNRM, SMLNUM, M, NRHS, B, LDB, INFO )
00351 IBSCL = 1
00352 ELSE IF( BNRM.GT.BIGNUM ) THEN
00353
00354
00355
00356 CALL CLASCL( 'G', 0, 0, BNRM, BIGNUM, M, NRHS, B, LDB, INFO )
00357 IBSCL = 2
00358 END IF
00359
00360
00361
00362 IF( M.LT.N )
00363 $ CALL CLASET( 'F', N-M, NRHS, CZERO, CZERO, B( M+1, 1 ), LDB )
00364
00365
00366
00367 IF( M.GE.N ) THEN
00368
00369
00370
00371 MM = M
00372 IF( M.GE.MNTHR ) THEN
00373
00374
00375
00376 MM = N
00377 ITAU = 1
00378 NWORK = ITAU + N
00379
00380
00381
00382
00383
00384 CALL CGEQRF( M, N, A, LDA, WORK( ITAU ), WORK( NWORK ),
00385 $ LWORK-NWORK+1, INFO )
00386
00387
00388
00389
00390
00391 CALL CUNMQR( 'L', 'C', M, NRHS, N, A, LDA, WORK( ITAU ), B,
00392 $ LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00393
00394
00395
00396 IF( N.GT.1 ) THEN
00397 CALL CLASET( 'L', N-1, N-1, CZERO, CZERO, A( 2, 1 ),
00398 $ LDA )
00399 END IF
00400 END IF
00401
00402 ITAUQ = 1
00403 ITAUP = ITAUQ + N
00404 NWORK = ITAUP + N
00405 IE = 1
00406 NRWORK = IE + N
00407
00408
00409
00410
00411
00412 CALL CGEBRD( MM, N, A, LDA, S, RWORK( IE ), WORK( ITAUQ ),
00413 $ WORK( ITAUP ), WORK( NWORK ), LWORK-NWORK+1,
00414 $ INFO )
00415
00416
00417
00418
00419 CALL CUNMBR( 'Q', 'L', 'C', MM, NRHS, N, A, LDA, WORK( ITAUQ ),
00420 $ B, LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00421
00422
00423
00424 CALL CLALSD( 'U', SMLSIZ, N, NRHS, S, RWORK( IE ), B, LDB,
00425 $ RCOND, RANK, WORK( NWORK ), RWORK( NRWORK ),
00426 $ IWORK, INFO )
00427 IF( INFO.NE.0 ) THEN
00428 GO TO 10
00429 END IF
00430
00431
00432
00433 CALL CUNMBR( 'P', 'L', 'N', N, NRHS, N, A, LDA, WORK( ITAUP ),
00434 $ B, LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00435
00436 ELSE IF( N.GE.MNTHR .AND. LWORK.GE.4*M+M*M+
00437 $ MAX( M, 2*M-4, NRHS, N-3*M ) ) THEN
00438
00439
00440
00441
00442 LDWORK = M
00443 IF( LWORK.GE.MAX( 4*M+M*LDA+MAX( M, 2*M-4, NRHS, N-3*M ),
00444 $ M*LDA+M+M*NRHS ) )LDWORK = LDA
00445 ITAU = 1
00446 NWORK = M + 1
00447
00448
00449
00450
00451 CALL CGELQF( M, N, A, LDA, WORK( ITAU ), WORK( NWORK ),
00452 $ LWORK-NWORK+1, INFO )
00453 IL = NWORK
00454
00455
00456
00457 CALL CLACPY( 'L', M, M, A, LDA, WORK( IL ), LDWORK )
00458 CALL CLASET( 'U', M-1, M-1, CZERO, CZERO, WORK( IL+LDWORK ),
00459 $ LDWORK )
00460 ITAUQ = IL + LDWORK*M
00461 ITAUP = ITAUQ + M
00462 NWORK = ITAUP + M
00463 IE = 1
00464 NRWORK = IE + M
00465
00466
00467
00468
00469
00470 CALL CGEBRD( M, M, WORK( IL ), LDWORK, S, RWORK( IE ),
00471 $ WORK( ITAUQ ), WORK( ITAUP ), WORK( NWORK ),
00472 $ LWORK-NWORK+1, INFO )
00473
00474
00475
00476
00477 CALL CUNMBR( 'Q', 'L', 'C', M, NRHS, M, WORK( IL ), LDWORK,
00478 $ WORK( ITAUQ ), B, LDB, WORK( NWORK ),
00479 $ LWORK-NWORK+1, INFO )
00480
00481
00482
00483 CALL CLALSD( 'U', SMLSIZ, M, NRHS, S, RWORK( IE ), B, LDB,
00484 $ RCOND, RANK, WORK( NWORK ), RWORK( NRWORK ),
00485 $ IWORK, INFO )
00486 IF( INFO.NE.0 ) THEN
00487 GO TO 10
00488 END IF
00489
00490
00491
00492 CALL CUNMBR( 'P', 'L', 'N', M, NRHS, M, WORK( IL ), LDWORK,
00493 $ WORK( ITAUP ), B, LDB, WORK( NWORK ),
00494 $ LWORK-NWORK+1, INFO )
00495
00496
00497
00498 CALL CLASET( 'F', N-M, NRHS, CZERO, CZERO, B( M+1, 1 ), LDB )
00499 NWORK = ITAU + M
00500
00501
00502
00503
00504 CALL CUNMLQ( 'L', 'C', N, NRHS, M, A, LDA, WORK( ITAU ), B,
00505 $ LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00506
00507 ELSE
00508
00509
00510
00511 ITAUQ = 1
00512 ITAUP = ITAUQ + M
00513 NWORK = ITAUP + M
00514 IE = 1
00515 NRWORK = IE + M
00516
00517
00518
00519
00520
00521 CALL CGEBRD( M, N, A, LDA, S, RWORK( IE ), WORK( ITAUQ ),
00522 $ WORK( ITAUP ), WORK( NWORK ), LWORK-NWORK+1,
00523 $ INFO )
00524
00525
00526
00527
00528 CALL CUNMBR( 'Q', 'L', 'C', M, NRHS, N, A, LDA, WORK( ITAUQ ),
00529 $ B, LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00530
00531
00532
00533 CALL CLALSD( 'L', SMLSIZ, M, NRHS, S, RWORK( IE ), B, LDB,
00534 $ RCOND, RANK, WORK( NWORK ), RWORK( NRWORK ),
00535 $ IWORK, INFO )
00536 IF( INFO.NE.0 ) THEN
00537 GO TO 10
00538 END IF
00539
00540
00541
00542 CALL CUNMBR( 'P', 'L', 'N', N, NRHS, M, A, LDA, WORK( ITAUP ),
00543 $ B, LDB, WORK( NWORK ), LWORK-NWORK+1, INFO )
00544
00545 END IF
00546
00547
00548
00549 IF( IASCL.EQ.1 ) THEN
00550 CALL CLASCL( 'G', 0, 0, ANRM, SMLNUM, N, NRHS, B, LDB, INFO )
00551 CALL SLASCL( 'G', 0, 0, SMLNUM, ANRM, MINMN, 1, S, MINMN,
00552 $ INFO )
00553 ELSE IF( IASCL.EQ.2 ) THEN
00554 CALL CLASCL( 'G', 0, 0, ANRM, BIGNUM, N, NRHS, B, LDB, INFO )
00555 CALL SLASCL( 'G', 0, 0, BIGNUM, ANRM, MINMN, 1, S, MINMN,
00556 $ INFO )
00557 END IF
00558 IF( IBSCL.EQ.1 ) THEN
00559 CALL CLASCL( 'G', 0, 0, SMLNUM, BNRM, N, NRHS, B, LDB, INFO )
00560 ELSE IF( IBSCL.EQ.2 ) THEN
00561 CALL CLASCL( 'G', 0, 0, BIGNUM, BNRM, N, NRHS, B, LDB, INFO )
00562 END IF
00563
00564 10 CONTINUE
00565 WORK( 1 ) = MAXWRK
00566 IWORK( 1 ) = LIWORK
00567 RWORK( 1 ) = LRWORK
00568 RETURN
00569
00570
00571
00572 END