199 SUBROUTINE dgelsd( M, N, NRHS, A, LDA, B, LDB, S, RCOND, RANK,
200 $ WORK, LWORK, IWORK, INFO )
207 INTEGER INFO, LDA, LDB, LWORK, M, N, NRHS, RANK
208 DOUBLE PRECISION RCOND
212 DOUBLE PRECISION A( LDA, * ), B( LDB, * ), S( * ), WORK( * )
218 DOUBLE PRECISION ZERO, ONE, TWO
219 parameter( zero = 0.0d0, one = 1.0d0, two = 2.0d0 )
223 INTEGER IASCL, IBSCL, IE, IL, ITAU, ITAUP, ITAUQ,
224 $ ldwork, liwork, maxmn, maxwrk, minmn, minwrk,
225 $ mm, mnthr, nlvl, nwork, smlsiz, wlalsd
226 DOUBLE PRECISION ANRM, BIGNUM, BNRM, EPS, SFMIN, SMLNUM
235 DOUBLE PRECISION DLAMCH, DLANGE
236 EXTERNAL ilaenv, dlamch, dlange
239 INTRINSIC dble, int, log, max, min
248 mnthr = ilaenv( 6,
'DGELSD',
' ', m, n, nrhs, -1 )
249 lquery = ( lwork.EQ.-1 )
252 ELSE IF( n.LT.0 )
THEN
254 ELSE IF( nrhs.LT.0 )
THEN
256 ELSE IF( lda.LT.max( 1, m ) )
THEN
258 ELSE IF( ldb.LT.max( 1, maxmn ) )
THEN
262 smlsiz = ilaenv( 9,
'DGELSD',
' ', 0, 0, 0, 0 )
273 minmn = max( 1, minmn )
274 nlvl = max( int( log( dble( minmn ) / dble( smlsiz+1 ) ) /
275 $ log( two ) ) + 1, 0 )
279 liwork = 3*minmn*nlvl + 11*minmn
281 IF( m.GE.n .AND. m.GE.mnthr )
THEN
286 maxwrk = max( maxwrk, n+n*ilaenv( 1,
'DGEQRF',
' ', m, n,
288 maxwrk = max( maxwrk, n+nrhs*
289 $ ilaenv( 1,
'DORMQR',
'LT', m, nrhs, n, -1 ) )
295 maxwrk = max( maxwrk, 3*n+( mm+n )*
296 $ ilaenv( 1,
'DGEBRD',
' ', mm, n, -1, -1 ) )
297 maxwrk = max( maxwrk, 3*n+nrhs*
298 $ ilaenv( 1,
'DORMBR',
'QLT', mm, nrhs, n, -1 ) )
299 maxwrk = max( maxwrk, 3*n+( n-1 )*
300 $ ilaenv( 1,
'DORMBR',
'PLN', n, nrhs, n, -1 ) )
301 wlalsd = 9*n+2*n*smlsiz+8*n*nlvl+n*nrhs+(smlsiz+1)**2
302 maxwrk = max( maxwrk, 3*n+wlalsd )
303 minwrk = max( 3*n+mm, 3*n+nrhs, 3*n+wlalsd )
306 wlalsd = 9*m+2*m*smlsiz+8*m*nlvl+m*nrhs+(smlsiz+1)**2
307 IF( n.GE.mnthr )
THEN
312 maxwrk = m + m*ilaenv( 1,
'DGELQF',
' ', m, n, -1,
314 maxwrk = max( maxwrk, m*m+4*m+2*m*
315 $ ilaenv( 1,
'DGEBRD',
' ', m, m, -1, -1 ) )
316 maxwrk = max( maxwrk, m*m+4*m+nrhs*
317 $ ilaenv( 1,
'DORMBR',
'QLT', m, nrhs, m,
319 maxwrk = max( maxwrk, m*m+4*m+( m-1 )*
320 $ ilaenv( 1,
'DORMBR',
'PLN', m, nrhs, m,
323 maxwrk = max( maxwrk, m*m+m+m*nrhs )
325 maxwrk = max( maxwrk, m*m+2*m )
327 maxwrk = max( maxwrk, m+nrhs*
328 $ ilaenv( 1,
'DORMLQ',
'LT', n, nrhs, m, -1 ) )
329 maxwrk = max( maxwrk, m*m+4*m+wlalsd )
332 maxwrk = max( maxwrk,
333 $ 4*m+m*m+max( m, 2*m-4, nrhs, n-3*m ) )
338 maxwrk = 3*m + ( n+m )*ilaenv( 1,
'DGEBRD',
' ', m, n,
340 maxwrk = max( maxwrk, 3*m+nrhs*
341 $ ilaenv( 1,
'DORMBR',
'QLT', m, nrhs, n,
343 maxwrk = max( maxwrk, 3*m+m*
344 $ ilaenv( 1,
'DORMBR',
'PLN', n, nrhs, m,
346 maxwrk = max( maxwrk, 3*m+wlalsd )
348 minwrk = max( 3*m+nrhs, 3*m+m, 3*m+wlalsd )
350 minwrk = min( minwrk, maxwrk )
354 IF( lwork.LT.minwrk .AND. .NOT.lquery )
THEN
360 CALL xerbla(
'DGELSD', -info )
362 ELSE IF( lquery )
THEN
368 IF( m.EQ.0 .OR. n.EQ.0 )
THEN
376 sfmin = dlamch(
'S' )
378 bignum = one / smlnum
382 anrm = dlange(
'M', m, n, a, lda, work )
384 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
388 CALL dlascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, info )
390 ELSE IF( anrm.GT.bignum )
THEN
394 CALL dlascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, info )
396 ELSE IF( anrm.EQ.zero )
THEN
400 CALL dlaset(
'F', max( m, n ), nrhs, zero, zero, b, ldb )
401 CALL dlaset(
'F', minmn, 1, zero, zero, s, 1 )
408 bnrm = dlange(
'M', m, nrhs, b, ldb, work )
410 IF( bnrm.GT.zero .AND. bnrm.LT.smlnum )
THEN
414 CALL dlascl(
'G', 0, 0, bnrm, smlnum, m, nrhs, b, ldb,
417 ELSE IF( bnrm.GT.bignum )
THEN
421 CALL dlascl(
'G', 0, 0, bnrm, bignum, m, nrhs, b, ldb,
429 $
CALL dlaset(
'F', n-m, nrhs, zero, zero, b( m+1, 1 ), ldb )
438 IF( m.GE.mnthr )
THEN
449 CALL dgeqrf( m, n, a, lda, work( itau ), work( nwork ),
450 $ lwork-nwork+1, info )
455 CALL dormqr(
'L',
'T', m, nrhs, n, a, lda, work( itau ),
457 $ ldb, work( nwork ), lwork-nwork+1, info )
462 CALL dlaset(
'L', n-1, n-1, zero, zero, a( 2, 1 ),
475 CALL dgebrd( mm, n, a, lda, s, work( ie ), work( itauq ),
476 $ work( itaup ), work( nwork ), lwork-nwork+1,
482 CALL dormbr(
'Q',
'L',
'T', mm, nrhs, n, a, lda,
484 $ b, ldb, work( nwork ), lwork-nwork+1, info )
488 CALL dlalsd(
'U', smlsiz, n, nrhs, s, work( ie ), b, ldb,
489 $ rcond, rank, work( nwork ), iwork, info )
496 CALL dormbr(
'P',
'L',
'N', n, nrhs, n, a, lda,
498 $ b, ldb, work( nwork ), lwork-nwork+1, info )
500 ELSE IF( n.GE.mnthr .AND. lwork.GE.4*m+m*m+
501 $ max( m, 2*m-4, nrhs, n-3*m, wlalsd ) )
THEN
507 IF( lwork.GE.max( 4*m+m*lda+max( m, 2*m-4, nrhs, n-3*m ),
508 $ m*lda+m+m*nrhs, 4*m+m*lda+wlalsd ) )ldwork = lda
515 CALL dgelqf( m, n, a, lda, work( itau ), work( nwork ),
516 $ lwork-nwork+1, info )
521 CALL dlacpy(
'L', m, m, a, lda, work( il ), ldwork )
522 CALL dlaset(
'U', m-1, m-1, zero, zero, work( il+ldwork ),
532 CALL dgebrd( m, m, work( il ), ldwork, s, work( ie ),
533 $ work( itauq ), work( itaup ), work( nwork ),
534 $ lwork-nwork+1, info )
539 CALL dormbr(
'Q',
'L',
'T', m, nrhs, m, work( il ), ldwork,
540 $ work( itauq ), b, ldb, work( nwork ),
541 $ lwork-nwork+1, info )
545 CALL dlalsd(
'U', smlsiz, m, nrhs, s, work( ie ), b, ldb,
546 $ rcond, rank, work( nwork ), iwork, info )
553 CALL dormbr(
'P',
'L',
'N', m, nrhs, m, work( il ), ldwork,
554 $ work( itaup ), b, ldb, work( nwork ),
555 $ lwork-nwork+1, info )
559 CALL dlaset(
'F', n-m, nrhs, zero, zero, b( m+1, 1 ), ldb )
565 CALL dormlq(
'L',
'T', n, nrhs, m, a, lda, work( itau ), b,
566 $ ldb, work( nwork ), lwork-nwork+1, info )
580 CALL dgebrd( m, n, a, lda, s, work( ie ), work( itauq ),
581 $ work( itaup ), work( nwork ), lwork-nwork+1,
587 CALL dormbr(
'Q',
'L',
'T', m, nrhs, n, a, lda,
589 $ b, ldb, work( nwork ), lwork-nwork+1, info )
593 CALL dlalsd(
'L', smlsiz, m, nrhs, s, work( ie ), b, ldb,
594 $ rcond, rank, work( nwork ), iwork, info )
601 CALL dormbr(
'P',
'L',
'N', n, nrhs, m, a, lda,
603 $ b, ldb, work( nwork ), lwork-nwork+1, info )
609 IF( iascl.EQ.1 )
THEN
610 CALL dlascl(
'G', 0, 0, anrm, smlnum, n, nrhs, b, ldb,
612 CALL dlascl(
'G', 0, 0, smlnum, anrm, minmn, 1, s, minmn,
614 ELSE IF( iascl.EQ.2 )
THEN
615 CALL dlascl(
'G', 0, 0, anrm, bignum, n, nrhs, b, ldb,
617 CALL dlascl(
'G', 0, 0, bignum, anrm, minmn, 1, s, minmn,
620 IF( ibscl.EQ.1 )
THEN
621 CALL dlascl(
'G', 0, 0, smlnum, bnrm, n, nrhs, b, ldb,
623 ELSE IF( ibscl.EQ.2 )
THEN
624 CALL dlascl(
'G', 0, 0, bignum, bnrm, n, nrhs, b, ldb,