217 SUBROUTINE cgesdd( JOBZ, M, N, A, LDA, S, U, LDU, VT, LDVT,
218 $ WORK, LWORK, RWORK, IWORK, INFO )
227 INTEGER INFO, LDA, LDU, LDVT, LWORK, M, N
231 REAL RWORK( * ), S( * )
232 COMPLEX A( LDA, * ), U( LDU, * ), VT( LDVT, * ),
240 parameter( czero = ( 0.0e+0, 0.0e+0 ),
241 $ cone = ( 1.0e+0, 0.0e+0 ) )
243 parameter( zero = 0.0e+0, one = 1.0e+0 )
246 LOGICAL LQUERY, WNTQA, WNTQAS, WNTQN, WNTQO, WNTQS
247 INTEGER BLK, CHUNK, I, IE, IERR, IL, IR, IRU, IRVT,
248 $ iscl, itau, itaup, itauq, iu, ivt, ldwkvt,
249 $ ldwrkl, ldwrkr, ldwrku, maxwrk, minmn, minwrk,
250 $ mnthr1, mnthr2, nrwork, nwork, wrkbl
251 INTEGER LWORK_CGEBRD_MN, LWORK_CGEBRD_MM,
252 $ lwork_cgebrd_nn, lwork_cgelqf_mn,
254 $ lwork_cungbr_p_mn, lwork_cungbr_p_nn,
255 $ lwork_cungbr_q_mn, lwork_cungbr_q_mm,
256 $ lwork_cunglq_mn, lwork_cunglq_nn,
257 $ lwork_cungqr_mm, lwork_cungqr_mn,
258 $ lwork_cunmbr_prc_mm, lwork_cunmbr_qln_mm,
259 $ lwork_cunmbr_prc_mn, lwork_cunmbr_qln_mn,
260 $ lwork_cunmbr_prc_nn, lwork_cunmbr_qln_nn
261 REAL ANRM, BIGNUM, EPS, SMLNUM
275 LOGICAL LSAME, SISNAN
276 REAL SLAMCH, CLANGE, SROUNDUP_LWORK
277 EXTERNAL lsame, slamch, clange, sisnan,
281 INTRINSIC int, max, min, sqrt
289 mnthr1 = int( real( minmn )*17.0e0 / 9.0e0 )
290 mnthr2 = int( real( minmn )*5.0e0 / 3.0e0 )
291 wntqa = lsame( jobz,
'A' )
292 wntqs = lsame( jobz,
'S' )
293 wntqas = wntqa .OR. wntqs
294 wntqo = lsame( jobz,
'O' )
295 wntqn = lsame( jobz,
'N' )
296 lquery = ( lwork.EQ.-1 )
300 IF( .NOT.( wntqa .OR. wntqs .OR. wntqo .OR. wntqn ) )
THEN
302 ELSE IF( m.LT.0 )
THEN
304 ELSE IF( n.LT.0 )
THEN
306 ELSE IF( lda.LT.max( 1, m ) )
THEN
308 ELSE IF( ldu.LT.1 .OR. ( wntqas .AND. ldu.LT.m ) .OR.
309 $ ( wntqo .AND. m.LT.n .AND. ldu.LT.m ) )
THEN
311 ELSE IF( ldvt.LT.1 .OR. ( wntqa .AND. ldvt.LT.n ) .OR.
312 $ ( wntqs .AND. ldvt.LT.minmn ) .OR.
313 $ ( wntqo .AND. m.GE.n .AND. ldvt.LT.n ) )
THEN
328 IF( m.GE.n .AND. minmn.GT.0 )
THEN
337 CALL cgebrd( m, n, cdum(1), m, dum(1), dum(1), cdum(1),
338 $ cdum(1), cdum(1), -1, ierr )
339 lwork_cgebrd_mn = int( cdum(1) )
341 CALL cgebrd( n, n, cdum(1), n, dum(1), dum(1), cdum(1),
342 $ cdum(1), cdum(1), -1, ierr )
343 lwork_cgebrd_nn = int( cdum(1) )
345 CALL cgeqrf( m, n, cdum(1), m, cdum(1), cdum(1), -1,
347 lwork_cgeqrf_mn = int( cdum(1) )
349 CALL cungbr(
'P', n, n, n, cdum(1), n, cdum(1), cdum(1),
351 lwork_cungbr_p_nn = int( cdum(1) )
353 CALL cungbr(
'Q', m, m, n, cdum(1), m, cdum(1), cdum(1),
355 lwork_cungbr_q_mm = int( cdum(1) )
357 CALL cungbr(
'Q', m, n, n, cdum(1), m, cdum(1), cdum(1),
359 lwork_cungbr_q_mn = int( cdum(1) )
361 CALL cungqr( m, m, n, cdum(1), m, cdum(1), cdum(1),
363 lwork_cungqr_mm = int( cdum(1) )
365 CALL cungqr( m, n, n, cdum(1), m, cdum(1), cdum(1),
367 lwork_cungqr_mn = int( cdum(1) )
369 CALL cunmbr(
'P',
'R',
'C', n, n, n, cdum(1), n, cdum(1),
370 $ cdum(1), n, cdum(1), -1, ierr )
371 lwork_cunmbr_prc_nn = int( cdum(1) )
373 CALL cunmbr(
'Q',
'L',
'N', m, m, n, cdum(1), m, cdum(1),
374 $ cdum(1), m, cdum(1), -1, ierr )
375 lwork_cunmbr_qln_mm = int( cdum(1) )
377 CALL cunmbr(
'Q',
'L',
'N', m, n, n, cdum(1), m, cdum(1),
378 $ cdum(1), m, cdum(1), -1, ierr )
379 lwork_cunmbr_qln_mn = int( cdum(1) )
381 CALL cunmbr(
'Q',
'L',
'N', n, n, n, cdum(1), n, cdum(1),
382 $ cdum(1), n, cdum(1), -1, ierr )
383 lwork_cunmbr_qln_nn = int( cdum(1) )
385 IF( m.GE.mnthr1 )
THEN
390 maxwrk = n + lwork_cgeqrf_mn
391 maxwrk = max( maxwrk, 2*n + lwork_cgebrd_nn )
393 ELSE IF( wntqo )
THEN
397 wrkbl = n + lwork_cgeqrf_mn
398 wrkbl = max( wrkbl, n + lwork_cungqr_mn )
399 wrkbl = max( wrkbl, 2*n + lwork_cgebrd_nn )
400 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_qln_nn )
401 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_prc_nn )
402 maxwrk = m*n + n*n + wrkbl
404 ELSE IF( wntqs )
THEN
408 wrkbl = n + lwork_cgeqrf_mn
409 wrkbl = max( wrkbl, n + lwork_cungqr_mn )
410 wrkbl = max( wrkbl, 2*n + lwork_cgebrd_nn )
411 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_qln_nn )
412 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_prc_nn )
415 ELSE IF( wntqa )
THEN
419 wrkbl = n + lwork_cgeqrf_mn
420 wrkbl = max( wrkbl, n + lwork_cungqr_mm )
421 wrkbl = max( wrkbl, 2*n + lwork_cgebrd_nn )
422 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_qln_nn )
423 wrkbl = max( wrkbl, 2*n + lwork_cunmbr_prc_nn )
425 minwrk = n*n + max( 3*n, n + m )
427 ELSE IF( m.GE.mnthr2 )
THEN
431 maxwrk = 2*n + lwork_cgebrd_mn
435 maxwrk = max( maxwrk, 2*n + lwork_cungbr_p_nn )
436 maxwrk = max( maxwrk, 2*n + lwork_cungbr_q_mn )
437 maxwrk = maxwrk + m*n
438 minwrk = minwrk + n*n
439 ELSE IF( wntqs )
THEN
441 maxwrk = max( maxwrk, 2*n + lwork_cungbr_p_nn )
442 maxwrk = max( maxwrk, 2*n + lwork_cungbr_q_mn )
443 ELSE IF( wntqa )
THEN
445 maxwrk = max( maxwrk, 2*n + lwork_cungbr_p_nn )
446 maxwrk = max( maxwrk, 2*n + lwork_cungbr_q_mm )
452 maxwrk = 2*n + lwork_cgebrd_mn
456 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_prc_nn )
457 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_qln_mn )
458 maxwrk = maxwrk + m*n
459 minwrk = minwrk + n*n
460 ELSE IF( wntqs )
THEN
462 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_qln_mn )
463 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_prc_nn )
464 ELSE IF( wntqa )
THEN
466 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_qln_mm )
467 maxwrk = max( maxwrk, 2*n + lwork_cunmbr_prc_nn )
470 ELSE IF( minmn.GT.0 )
THEN
479 CALL cgebrd( m, n, cdum(1), m, dum(1), dum(1), cdum(1),
480 $ cdum(1), cdum(1), -1, ierr )
481 lwork_cgebrd_mn = int( cdum(1) )
483 CALL cgebrd( m, m, cdum(1), m, dum(1), dum(1), cdum(1),
484 $ cdum(1), cdum(1), -1, ierr )
485 lwork_cgebrd_mm = int( cdum(1) )
487 CALL cgelqf( m, n, cdum(1), m, cdum(1), cdum(1), -1,
489 lwork_cgelqf_mn = int( cdum(1) )
491 CALL cungbr(
'P', m, n, m, cdum(1), m, cdum(1), cdum(1),
493 lwork_cungbr_p_mn = int( cdum(1) )
495 CALL cungbr(
'P', n, n, m, cdum(1), n, cdum(1), cdum(1),
497 lwork_cungbr_p_nn = int( cdum(1) )
499 CALL cungbr(
'Q', m, m, n, cdum(1), m, cdum(1), cdum(1),
501 lwork_cungbr_q_mm = int( cdum(1) )
503 CALL cunglq( m, n, m, cdum(1), m, cdum(1), cdum(1),
505 lwork_cunglq_mn = int( cdum(1) )
507 CALL cunglq( n, n, m, cdum(1), n, cdum(1), cdum(1),
509 lwork_cunglq_nn = int( cdum(1) )
511 CALL cunmbr(
'P',
'R',
'C', m, m, m, cdum(1), m, cdum(1),
512 $ cdum(1), m, cdum(1), -1, ierr )
513 lwork_cunmbr_prc_mm = int( cdum(1) )
515 CALL cunmbr(
'P',
'R',
'C', m, n, m, cdum(1), m, cdum(1),
516 $ cdum(1), m, cdum(1), -1, ierr )
517 lwork_cunmbr_prc_mn = int( cdum(1) )
519 CALL cunmbr(
'P',
'R',
'C', n, n, m, cdum(1), n, cdum(1),
520 $ cdum(1), n, cdum(1), -1, ierr )
521 lwork_cunmbr_prc_nn = int( cdum(1) )
523 CALL cunmbr(
'Q',
'L',
'N', m, m, m, cdum(1), m, cdum(1),
524 $ cdum(1), m, cdum(1), -1, ierr )
525 lwork_cunmbr_qln_mm = int( cdum(1) )
527 IF( n.GE.mnthr1 )
THEN
532 maxwrk = m + lwork_cgelqf_mn
533 maxwrk = max( maxwrk, 2*m + lwork_cgebrd_mm )
535 ELSE IF( wntqo )
THEN
539 wrkbl = m + lwork_cgelqf_mn
540 wrkbl = max( wrkbl, m + lwork_cunglq_mn )
541 wrkbl = max( wrkbl, 2*m + lwork_cgebrd_mm )
542 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_qln_mm )
543 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_prc_mm )
544 maxwrk = m*n + m*m + wrkbl
546 ELSE IF( wntqs )
THEN
550 wrkbl = m + lwork_cgelqf_mn
551 wrkbl = max( wrkbl, m + lwork_cunglq_mn )
552 wrkbl = max( wrkbl, 2*m + lwork_cgebrd_mm )
553 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_qln_mm )
554 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_prc_mm )
557 ELSE IF( wntqa )
THEN
561 wrkbl = m + lwork_cgelqf_mn
562 wrkbl = max( wrkbl, m + lwork_cunglq_nn )
563 wrkbl = max( wrkbl, 2*m + lwork_cgebrd_mm )
564 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_qln_mm )
565 wrkbl = max( wrkbl, 2*m + lwork_cunmbr_prc_mm )
567 minwrk = m*m + max( 3*m, m + n )
569 ELSE IF( n.GE.mnthr2 )
THEN
573 maxwrk = 2*m + lwork_cgebrd_mn
577 maxwrk = max( maxwrk, 2*m + lwork_cungbr_q_mm )
578 maxwrk = max( maxwrk, 2*m + lwork_cungbr_p_mn )
579 maxwrk = maxwrk + m*n
580 minwrk = minwrk + m*m
581 ELSE IF( wntqs )
THEN
583 maxwrk = max( maxwrk, 2*m + lwork_cungbr_q_mm )
584 maxwrk = max( maxwrk, 2*m + lwork_cungbr_p_mn )
585 ELSE IF( wntqa )
THEN
587 maxwrk = max( maxwrk, 2*m + lwork_cungbr_q_mm )
588 maxwrk = max( maxwrk, 2*m + lwork_cungbr_p_nn )
594 maxwrk = 2*m + lwork_cgebrd_mn
598 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_qln_mm )
599 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_prc_mn )
600 maxwrk = maxwrk + m*n
601 minwrk = minwrk + m*m
602 ELSE IF( wntqs )
THEN
604 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_qln_mm )
605 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_prc_mn )
606 ELSE IF( wntqa )
THEN
608 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_qln_mm )
609 maxwrk = max( maxwrk, 2*m + lwork_cunmbr_prc_nn )
613 maxwrk = max( maxwrk, minwrk )
616 work( 1 ) = sroundup_lwork( maxwrk )
617 IF( lwork.LT.minwrk .AND. .NOT. lquery )
THEN
623 CALL xerbla(
'CGESDD', -info )
625 ELSE IF( lquery )
THEN
631 IF( m.EQ.0 .OR. n.EQ.0 )
THEN
638 smlnum = sqrt( slamch(
'S' ) ) / eps
639 bignum = one / smlnum
643 anrm = clange(
'M', m, n, a, lda, dum )
644 IF( sisnan( anrm ) )
THEN
649 IF( anrm.GT.zero .AND. anrm.LT.smlnum )
THEN
651 CALL clascl(
'G', 0, 0, anrm, smlnum, m, n, a, lda, ierr )
652 ELSE IF( anrm.GT.bignum )
THEN
654 CALL clascl(
'G', 0, 0, anrm, bignum, m, n, a, lda, ierr )
663 IF( m.GE.mnthr1 )
THEN
678 CALL cgeqrf( m, n, a, lda, work( itau ),
680 $ lwork-nwork+1, ierr )
684 CALL claset(
'L', n-1, n-1, czero, czero, a( 2, 1 ),
696 CALL cgebrd( n, n, a, lda, s, rwork( ie ),
698 $ work( itaup ), work( nwork ), lwork-nwork+1,
706 CALL sbdsdc(
'U',
'N', n, s, rwork( ie ), dum,1,dum,1,
707 $ dum, idum, rwork( nrwork ), iwork, info )
709 ELSE IF( wntqo )
THEN
721 IF( lwork .GE. m*n + n*n + 3*n )
THEN
727 ldwrkr = ( lwork - n*n - 3*n ) / n
737 CALL cgeqrf( m, n, a, lda, work( itau ),
739 $ lwork-nwork+1, ierr )
743 CALL clacpy(
'U', n, n, a, lda, work( ir ), ldwrkr )
744 CALL claset(
'L', n-1, n-1, czero, czero,
753 CALL cungqr( m, n, n, a, lda, work( itau ),
754 $ work( nwork ), lwork-nwork+1, ierr )
765 CALL cgebrd( n, n, work( ir ), ldwrkr, s, rwork( ie ),
766 $ work( itauq ), work( itaup ), work( nwork ),
767 $ lwork-nwork+1, ierr )
778 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
780 $ n, rwork( irvt ), n, dum, idum,
781 $ rwork( nrwork ), iwork, info )
789 CALL clacp2(
'F', n, n, rwork( iru ), n, work( iu ),
791 CALL cunmbr(
'Q',
'L',
'N', n, n, n, work( ir ),
793 $ work( itauq ), work( iu ), ldwrku,
794 $ work( nwork ), lwork-nwork+1, ierr )
802 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
803 CALL cunmbr(
'P',
'R',
'C', n, n, n, work( ir ),
805 $ work( itaup ), vt, ldvt, work( nwork ),
806 $ lwork-nwork+1, ierr )
814 DO 10 i = 1, m, ldwrkr
815 chunk = min( m-i+1, ldwrkr )
816 CALL cgemm(
'N',
'N', chunk, n, n, cone, a( i, 1 ),
817 $ lda, work( iu ), ldwrku, czero,
818 $ work( ir ), ldwrkr )
819 CALL clacpy(
'F', chunk, n, work( ir ), ldwrkr,
823 ELSE IF( wntqs )
THEN
842 CALL cgeqrf( m, n, a, lda, work( itau ),
844 $ lwork-nwork+1, ierr )
848 CALL clacpy(
'U', n, n, a, lda, work( ir ), ldwrkr )
849 CALL claset(
'L', n-1, n-1, czero, czero,
858 CALL cungqr( m, n, n, a, lda, work( itau ),
859 $ work( nwork ), lwork-nwork+1, ierr )
870 CALL cgebrd( n, n, work( ir ), ldwrkr, s, rwork( ie ),
871 $ work( itauq ), work( itaup ), work( nwork ),
872 $ lwork-nwork+1, ierr )
883 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
885 $ n, rwork( irvt ), n, dum, idum,
886 $ rwork( nrwork ), iwork, info )
894 CALL clacp2(
'F', n, n, rwork( iru ), n, u, ldu )
895 CALL cunmbr(
'Q',
'L',
'N', n, n, n, work( ir ),
897 $ work( itauq ), u, ldu, work( nwork ),
898 $ lwork-nwork+1, ierr )
906 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
907 CALL cunmbr(
'P',
'R',
'C', n, n, n, work( ir ),
909 $ work( itaup ), vt, ldvt, work( nwork ),
910 $ lwork-nwork+1, ierr )
917 CALL clacpy(
'F', n, n, u, ldu, work( ir ), ldwrkr )
918 CALL cgemm(
'N',
'N', m, n, n, cone, a, lda,
920 $ ldwrkr, czero, u, ldu )
922 ELSE IF( wntqa )
THEN
941 CALL cgeqrf( m, n, a, lda, work( itau ),
943 $ lwork-nwork+1, ierr )
944 CALL clacpy(
'L', m, n, a, lda, u, ldu )
951 CALL cungqr( m, m, n, u, ldu, work( itau ),
952 $ work( nwork ), lwork-nwork+1, ierr )
956 CALL claset(
'L', n-1, n-1, czero, czero, a( 2, 1 ),
968 CALL cgebrd( n, n, a, lda, s, rwork( ie ),
970 $ work( itaup ), work( nwork ), lwork-nwork+1,
982 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
984 $ n, rwork( irvt ), n, dum, idum,
985 $ rwork( nrwork ), iwork, info )
993 CALL clacp2(
'F', n, n, rwork( iru ), n, work( iu ),
995 CALL cunmbr(
'Q',
'L',
'N', n, n, n, a, lda,
996 $ work( itauq ), work( iu ), ldwrku,
997 $ work( nwork ), lwork-nwork+1, ierr )
1005 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
1006 CALL cunmbr(
'P',
'R',
'C', n, n, n, a, lda,
1007 $ work( itaup ), vt, ldvt, work( nwork ),
1008 $ lwork-nwork+1, ierr )
1015 CALL cgemm(
'N',
'N', m, n, n, cone, u, ldu,
1017 $ ldwrku, czero, a, lda )
1021 CALL clacpy(
'F', m, n, a, lda, u, ldu )
1025 ELSE IF( m.GE.mnthr2 )
THEN
1044 CALL cgebrd( m, n, a, lda, s, rwork( ie ), work( itauq ),
1045 $ work( itaup ), work( nwork ), lwork-nwork+1,
1054 CALL sbdsdc(
'U',
'N', n, s, rwork( ie ), dum, 1,dum,
1056 $ dum, idum, rwork( nrwork ), iwork, info )
1057 ELSE IF( wntqo )
THEN
1069 CALL clacpy(
'U', n, n, a, lda, vt, ldvt )
1070 CALL cungbr(
'P', n, n, n, vt, ldvt, work( itaup ),
1071 $ work( nwork ), lwork-nwork+1, ierr )
1078 CALL cungbr(
'Q', m, n, n, a, lda, work( itauq ),
1079 $ work( nwork ), lwork-nwork+1, ierr )
1081 IF( lwork .GE. m*n + 3*n )
THEN
1090 ldwrku = ( lwork - 3*n ) / n
1092 nwork = iu + ldwrku*n
1100 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1102 $ n, rwork( irvt ), n, dum, idum,
1103 $ rwork( nrwork ), iwork, info )
1110 CALL clarcm( n, n, rwork( irvt ), n, vt, ldvt,
1111 $ work( iu ), ldwrku, rwork( nrwork ) )
1112 CALL clacpy(
'F', n, n, work( iu ), ldwrku, vt, ldvt )
1122 DO 20 i = 1, m, ldwrku
1123 chunk = min( m-i+1, ldwrku )
1124 CALL clacrm( chunk, n, a( i, 1 ), lda,
1126 $ n, work( iu ), ldwrku, rwork( nrwork ) )
1127 CALL clacpy(
'F', chunk, n, work( iu ), ldwrku,
1131 ELSE IF( wntqs )
THEN
1139 CALL clacpy(
'U', n, n, a, lda, vt, ldvt )
1140 CALL cungbr(
'P', n, n, n, vt, ldvt, work( itaup ),
1141 $ work( nwork ), lwork-nwork+1, ierr )
1148 CALL clacpy(
'L', m, n, a, lda, u, ldu )
1149 CALL cungbr(
'Q', m, n, n, u, ldu, work( itauq ),
1150 $ work( nwork ), lwork-nwork+1, ierr )
1161 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1163 $ n, rwork( irvt ), n, dum, idum,
1164 $ rwork( nrwork ), iwork, info )
1171 CALL clarcm( n, n, rwork( irvt ), n, vt, ldvt, a, lda,
1173 CALL clacpy(
'F', n, n, a, lda, vt, ldvt )
1181 CALL clacrm( m, n, u, ldu, rwork( iru ), n, a, lda,
1183 CALL clacpy(
'F', m, n, a, lda, u, ldu )
1192 CALL clacpy(
'U', n, n, a, lda, vt, ldvt )
1193 CALL cungbr(
'P', n, n, n, vt, ldvt, work( itaup ),
1194 $ work( nwork ), lwork-nwork+1, ierr )
1201 CALL clacpy(
'L', m, n, a, lda, u, ldu )
1202 CALL cungbr(
'Q', m, m, n, u, ldu, work( itauq ),
1203 $ work( nwork ), lwork-nwork+1, ierr )
1214 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1216 $ n, rwork( irvt ), n, dum, idum,
1217 $ rwork( nrwork ), iwork, info )
1224 CALL clarcm( n, n, rwork( irvt ), n, vt, ldvt, a, lda,
1226 CALL clacpy(
'F', n, n, a, lda, vt, ldvt )
1234 CALL clacrm( m, n, u, ldu, rwork( iru ), n, a, lda,
1236 CALL clacpy(
'F', m, n, a, lda, u, ldu )
1258 CALL cgebrd( m, n, a, lda, s, rwork( ie ), work( itauq ),
1259 $ work( itaup ), work( nwork ), lwork-nwork+1,
1268 CALL sbdsdc(
'U',
'N', n, s, rwork( ie ), dum,1,dum,1,
1269 $ dum, idum, rwork( nrwork ), iwork, info )
1270 ELSE IF( wntqo )
THEN
1275 IF( lwork .GE. m*n + 3*n )
THEN
1284 ldwrku = ( lwork - 3*n ) / n
1286 nwork = iu + ldwrku*n
1295 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1297 $ n, rwork( irvt ), n, dum, idum,
1298 $ rwork( nrwork ), iwork, info )
1306 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
1307 CALL cunmbr(
'P',
'R',
'C', n, n, n, a, lda,
1308 $ work( itaup ), vt, ldvt, work( nwork ),
1309 $ lwork-nwork+1, ierr )
1311 IF( lwork .GE. m*n + 3*n )
THEN
1321 CALL claset(
'F', m, n, czero, czero, work( iu ),
1323 CALL clacp2(
'F', n, n, rwork( iru ), n,
1326 CALL cunmbr(
'Q',
'L',
'N', m, n, n, a, lda,
1327 $ work( itauq ), work( iu ), ldwrku,
1328 $ work( nwork ), lwork-nwork+1, ierr )
1329 CALL clacpy(
'F', m, n, work( iu ), ldwrku, a,
1339 CALL cungbr(
'Q', m, n, n, a, lda, work( itauq ),
1340 $ work( nwork ), lwork-nwork+1, ierr )
1350 DO 30 i = 1, m, ldwrku
1351 chunk = min( m-i+1, ldwrku )
1352 CALL clacrm( chunk, n, a( i, 1 ), lda,
1353 $ rwork( iru ), n, work( iu ), ldwrku,
1355 CALL clacpy(
'F', chunk, n, work( iu ), ldwrku,
1360 ELSE IF( wntqs )
THEN
1372 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1374 $ n, rwork( irvt ), n, dum, idum,
1375 $ rwork( nrwork ), iwork, info )
1383 CALL claset(
'F', m, n, czero, czero, u, ldu )
1384 CALL clacp2(
'F', n, n, rwork( iru ), n, u, ldu )
1385 CALL cunmbr(
'Q',
'L',
'N', m, n, n, a, lda,
1386 $ work( itauq ), u, ldu, work( nwork ),
1387 $ lwork-nwork+1, ierr )
1395 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
1396 CALL cunmbr(
'P',
'R',
'C', n, n, n, a, lda,
1397 $ work( itaup ), vt, ldvt, work( nwork ),
1398 $ lwork-nwork+1, ierr )
1411 CALL sbdsdc(
'U',
'I', n, s, rwork( ie ),
1413 $ n, rwork( irvt ), n, dum, idum,
1414 $ rwork( nrwork ), iwork, info )
1418 CALL claset(
'F', m, m, czero, czero, u, ldu )
1420 CALL claset(
'F', m-n, m-n, czero, cone,
1421 $ u( n+1, n+1 ), ldu )
1430 CALL clacp2(
'F', n, n, rwork( iru ), n, u, ldu )
1431 CALL cunmbr(
'Q',
'L',
'N', m, m, n, a, lda,
1432 $ work( itauq ), u, ldu, work( nwork ),
1433 $ lwork-nwork+1, ierr )
1441 CALL clacp2(
'F', n, n, rwork( irvt ), n, vt, ldvt )
1442 CALL cunmbr(
'P',
'R',
'C', n, n, n, a, lda,
1443 $ work( itaup ), vt, ldvt, work( nwork ),
1444 $ lwork-nwork+1, ierr )
1455 IF( n.GE.mnthr1 )
THEN
1470 CALL cgelqf( m, n, a, lda, work( itau ),
1472 $ lwork-nwork+1, ierr )
1476 CALL claset(
'U', m-1, m-1, czero, czero, a( 1, 2 ),
1488 CALL cgebrd( m, m, a, lda, s, rwork( ie ),
1490 $ work( itaup ), work( nwork ), lwork-nwork+1,
1498 CALL sbdsdc(
'U',
'N', m, s, rwork( ie ), dum,1,dum,1,
1499 $ dum, idum, rwork( nrwork ), iwork, info )
1501 ELSE IF( wntqo )
THEN
1513 IF( lwork .GE. m*n + m*m + 3*m )
THEN
1524 chunk = ( lwork - m*m - 3*m ) / m
1526 itau = il + ldwrkl*chunk
1534 CALL cgelqf( m, n, a, lda, work( itau ),
1536 $ lwork-nwork+1, ierr )
1540 CALL clacpy(
'L', m, m, a, lda, work( il ), ldwrkl )
1541 CALL claset(
'U', m-1, m-1, czero, czero,
1542 $ work( il+ldwrkl ), ldwrkl )
1549 CALL cunglq( m, n, m, a, lda, work( itau ),
1550 $ work( nwork ), lwork-nwork+1, ierr )
1561 CALL cgebrd( m, m, work( il ), ldwrkl, s, rwork( ie ),
1562 $ work( itauq ), work( itaup ), work( nwork ),
1563 $ lwork-nwork+1, ierr )
1574 CALL sbdsdc(
'U',
'I', m, s, rwork( ie ),
1576 $ m, rwork( irvt ), m, dum, idum,
1577 $ rwork( nrwork ), iwork, info )
1585 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
1586 CALL cunmbr(
'Q',
'L',
'N', m, m, m, work( il ),
1588 $ work( itauq ), u, ldu, work( nwork ),
1589 $ lwork-nwork+1, ierr )
1597 CALL clacp2(
'F', m, m, rwork( irvt ), m, work( ivt ),
1599 CALL cunmbr(
'P',
'R',
'C', m, m, m, work( il ),
1601 $ work( itaup ), work( ivt ), ldwkvt,
1602 $ work( nwork ), lwork-nwork+1, ierr )
1610 DO 40 i = 1, n, chunk
1611 blk = min( n-i+1, chunk )
1612 CALL cgemm(
'N',
'N', m, blk, m, cone, work( ivt ),
1614 $ a( 1, i ), lda, czero, work( il ),
1616 CALL clacpy(
'F', m, blk, work( il ), ldwrkl,
1620 ELSE IF( wntqs )
THEN
1631 itau = il + ldwrkl*m
1639 CALL cgelqf( m, n, a, lda, work( itau ),
1641 $ lwork-nwork+1, ierr )
1645 CALL clacpy(
'L', m, m, a, lda, work( il ), ldwrkl )
1646 CALL claset(
'U', m-1, m-1, czero, czero,
1647 $ work( il+ldwrkl ), ldwrkl )
1654 CALL cunglq( m, n, m, a, lda, work( itau ),
1655 $ work( nwork ), lwork-nwork+1, ierr )
1666 CALL cgebrd( m, m, work( il ), ldwrkl, s, rwork( ie ),
1667 $ work( itauq ), work( itaup ), work( nwork ),
1668 $ lwork-nwork+1, ierr )
1679 CALL sbdsdc(
'U',
'I', m, s, rwork( ie ),
1681 $ m, rwork( irvt ), m, dum, idum,
1682 $ rwork( nrwork ), iwork, info )
1690 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
1691 CALL cunmbr(
'Q',
'L',
'N', m, m, m, work( il ),
1693 $ work( itauq ), u, ldu, work( nwork ),
1694 $ lwork-nwork+1, ierr )
1702 CALL clacp2(
'F', m, m, rwork( irvt ), m, vt, ldvt )
1703 CALL cunmbr(
'P',
'R',
'C', m, m, m, work( il ),
1705 $ work( itaup ), vt, ldvt, work( nwork ),
1706 $ lwork-nwork+1, ierr )
1713 CALL clacpy(
'F', m, m, vt, ldvt, work( il ), ldwrkl )
1714 CALL cgemm(
'N',
'N', m, n, m, cone, work( il ),
1716 $ a, lda, czero, vt, ldvt )
1718 ELSE IF( wntqa )
THEN
1729 itau = ivt + ldwkvt*m
1737 CALL cgelqf( m, n, a, lda, work( itau ),
1739 $ lwork-nwork+1, ierr )
1740 CALL clacpy(
'U', m, n, a, lda, vt, ldvt )
1747 CALL cunglq( n, n, m, vt, ldvt, work( itau ),
1748 $ work( nwork ), lwork-nwork+1, ierr )
1752 CALL claset(
'U', m-1, m-1, czero, czero, a( 1, 2 ),
1764 CALL cgebrd( m, m, a, lda, s, rwork( ie ),
1766 $ work( itaup ), work( nwork ), lwork-nwork+1,
1778 CALL sbdsdc(
'U',
'I', m, s, rwork( ie ),
1780 $ m, rwork( irvt ), m, dum, idum,
1781 $ rwork( nrwork ), iwork, info )
1789 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
1790 CALL cunmbr(
'Q',
'L',
'N', m, m, m, a, lda,
1791 $ work( itauq ), u, ldu, work( nwork ),
1792 $ lwork-nwork+1, ierr )
1800 CALL clacp2(
'F', m, m, rwork( irvt ), m, work( ivt ),
1802 CALL cunmbr(
'P',
'R',
'C', m, m, m, a, lda,
1803 $ work( itaup ), work( ivt ), ldwkvt,
1804 $ work( nwork ), lwork-nwork+1, ierr )
1811 CALL cgemm(
'N',
'N', m, n, m, cone, work( ivt ),
1813 $ vt, ldvt, czero, a, lda )
1817 CALL clacpy(
'F', m, n, a, lda, vt, ldvt )
1821 ELSE IF( n.GE.mnthr2 )
THEN
1840 CALL cgebrd( m, n, a, lda, s, rwork( ie ), work( itauq ),
1841 $ work( itaup ), work( nwork ), lwork-nwork+1,
1851 CALL sbdsdc(
'L',
'N', m, s, rwork( ie ), dum,1,dum,1,
1852 $ dum, idum, rwork( nrwork ), iwork, info )
1853 ELSE IF( wntqo )
THEN
1865 CALL clacpy(
'L', m, m, a, lda, u, ldu )
1866 CALL cungbr(
'Q', m, m, n, u, ldu, work( itauq ),
1867 $ work( nwork ), lwork-nwork+1, ierr )
1874 CALL cungbr(
'P', m, n, m, a, lda, work( itaup ),
1875 $ work( nwork ), lwork-nwork+1, ierr )
1878 IF( lwork .GE. m*n + 3*m )
THEN
1882 nwork = ivt + ldwkvt*n
1888 chunk = ( lwork - 3*m ) / m
1889 nwork = ivt + ldwkvt*chunk
1898 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
1900 $ m, rwork( irvt ), m, dum, idum,
1901 $ rwork( nrwork ), iwork, info )
1908 CALL clacrm( m, m, u, ldu, rwork( iru ), m,
1910 $ ldwkvt, rwork( nrwork ) )
1911 CALL clacpy(
'F', m, m, work( ivt ), ldwkvt, u, ldu )
1921 DO 50 i = 1, n, chunk
1922 blk = min( n-i+1, chunk )
1923 CALL clarcm( m, blk, rwork( irvt ), m, a( 1, i ),
1925 $ work( ivt ), ldwkvt, rwork( nrwork ) )
1926 CALL clacpy(
'F', m, blk, work( ivt ), ldwkvt,
1929 ELSE IF( wntqs )
THEN
1937 CALL clacpy(
'L', m, m, a, lda, u, ldu )
1938 CALL cungbr(
'Q', m, m, n, u, ldu, work( itauq ),
1939 $ work( nwork ), lwork-nwork+1, ierr )
1946 CALL clacpy(
'U', m, n, a, lda, vt, ldvt )
1947 CALL cungbr(
'P', m, n, m, vt, ldvt, work( itaup ),
1948 $ work( nwork ), lwork-nwork+1, ierr )
1959 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
1961 $ m, rwork( irvt ), m, dum, idum,
1962 $ rwork( nrwork ), iwork, info )
1969 CALL clacrm( m, m, u, ldu, rwork( iru ), m, a, lda,
1971 CALL clacpy(
'F', m, m, a, lda, u, ldu )
1979 CALL clarcm( m, n, rwork( irvt ), m, vt, ldvt, a, lda,
1981 CALL clacpy(
'F', m, n, a, lda, vt, ldvt )
1990 CALL clacpy(
'L', m, m, a, lda, u, ldu )
1991 CALL cungbr(
'Q', m, m, n, u, ldu, work( itauq ),
1992 $ work( nwork ), lwork-nwork+1, ierr )
1999 CALL clacpy(
'U', m, n, a, lda, vt, ldvt )
2000 CALL cungbr(
'P', n, n, m, vt, ldvt, work( itaup ),
2001 $ work( nwork ), lwork-nwork+1, ierr )
2012 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
2014 $ m, rwork( irvt ), m, dum, idum,
2015 $ rwork( nrwork ), iwork, info )
2022 CALL clacrm( m, m, u, ldu, rwork( iru ), m, a, lda,
2024 CALL clacpy(
'F', m, m, a, lda, u, ldu )
2032 CALL clarcm( m, n, rwork( irvt ), m, vt, ldvt, a, lda,
2034 CALL clacpy(
'F', m, n, a, lda, vt, ldvt )
2056 CALL cgebrd( m, n, a, lda, s, rwork( ie ), work( itauq ),
2057 $ work( itaup ), work( nwork ), lwork-nwork+1,
2066 CALL sbdsdc(
'L',
'N', m, s, rwork( ie ), dum,1,dum,1,
2067 $ dum, idum, rwork( nrwork ), iwork, info )
2068 ELSE IF( wntqo )
THEN
2072 IF( lwork .GE. m*n + 3*m )
THEN
2076 CALL claset(
'F', m, n, czero, czero, work( ivt ),
2078 nwork = ivt + ldwkvt*n
2083 chunk = ( lwork - 3*m ) / m
2084 nwork = ivt + ldwkvt*chunk
2096 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
2098 $ m, rwork( irvt ), m, dum, idum,
2099 $ rwork( nrwork ), iwork, info )
2107 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
2108 CALL cunmbr(
'Q',
'L',
'N', m, m, n, a, lda,
2109 $ work( itauq ), u, ldu, work( nwork ),
2110 $ lwork-nwork+1, ierr )
2112 IF( lwork .GE. m*n + 3*m )
THEN
2122 CALL clacp2(
'F', m, m, rwork( irvt ), m,
2125 CALL cunmbr(
'P',
'R',
'C', m, n, m, a, lda,
2126 $ work( itaup ), work( ivt ), ldwkvt,
2127 $ work( nwork ), lwork-nwork+1, ierr )
2128 CALL clacpy(
'F', m, n, work( ivt ), ldwkvt, a,
2138 CALL cungbr(
'P', m, n, m, a, lda, work( itaup ),
2139 $ work( nwork ), lwork-nwork+1, ierr )
2149 DO 60 i = 1, n, chunk
2150 blk = min( n-i+1, chunk )
2151 CALL clarcm( m, blk, rwork( irvt ), m, a( 1,
2153 $ lda, work( ivt ), ldwkvt,
2155 CALL clacpy(
'F', m, blk, work( ivt ), ldwkvt,
2159 ELSE IF( wntqs )
THEN
2171 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
2173 $ m, rwork( irvt ), m, dum, idum,
2174 $ rwork( nrwork ), iwork, info )
2182 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
2183 CALL cunmbr(
'Q',
'L',
'N', m, m, n, a, lda,
2184 $ work( itauq ), u, ldu, work( nwork ),
2185 $ lwork-nwork+1, ierr )
2193 CALL claset(
'F', m, n, czero, czero, vt, ldvt )
2194 CALL clacp2(
'F', m, m, rwork( irvt ), m, vt, ldvt )
2195 CALL cunmbr(
'P',
'R',
'C', m, n, m, a, lda,
2196 $ work( itaup ), vt, ldvt, work( nwork ),
2197 $ lwork-nwork+1, ierr )
2211 CALL sbdsdc(
'L',
'I', m, s, rwork( ie ),
2213 $ m, rwork( irvt ), m, dum, idum,
2214 $ rwork( nrwork ), iwork, info )
2222 CALL clacp2(
'F', m, m, rwork( iru ), m, u, ldu )
2223 CALL cunmbr(
'Q',
'L',
'N', m, m, n, a, lda,
2224 $ work( itauq ), u, ldu, work( nwork ),
2225 $ lwork-nwork+1, ierr )
2229 CALL claset(
'F', n, n, czero, cone, vt, ldvt )
2237 CALL clacp2(
'F', m, m, rwork( irvt ), m, vt, ldvt )
2238 CALL cunmbr(
'P',
'R',
'C', n, n, m, a, lda,
2239 $ work( itaup ), vt, ldvt, work( nwork ),
2240 $ lwork-nwork+1, ierr )
2249 IF( iscl.EQ.1 )
THEN
2250 IF( anrm.GT.bignum )
2251 $
CALL slascl(
'G', 0, 0, bignum, anrm, minmn, 1, s, minmn,
2253 IF( info.NE.0 .AND. anrm.GT.bignum )
2254 $
CALL slascl(
'G', 0, 0, bignum, anrm, minmn-1, 1,
2255 $ rwork( ie ), minmn, ierr )
2256 IF( anrm.LT.smlnum )
2257 $
CALL slascl(
'G', 0, 0, smlnum, anrm, minmn, 1, s, minmn,
2259 IF( info.NE.0 .AND. anrm.LT.smlnum )
2260 $
CALL slascl(
'G', 0, 0, smlnum, anrm, minmn-1, 1,
2261 $ rwork( ie ), minmn, ierr )
2266 work( 1 ) = sroundup_lwork( maxwrk )