Annotation of rpl/lapack/lapack/zlamtsqr.f, revision 1.6

1.5       bertrand    1: *> \brief \b ZLAMTSQR
1.1       bertrand    2: *
                      3: *  Definition:
                      4: *  ===========
                      5: *
                      6: *      SUBROUTINE ZLAMTSQR( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
                      7: *     $                     LDT, C, LDC, WORK, LWORK, INFO )
                      8: *
                      9: *
                     10: *     .. Scalar Arguments ..
                     11: *      CHARACTER         SIDE, TRANS
                     12: *      INTEGER           INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
                     13: *     ..
                     14: *     .. Array Arguments ..
                     15: *      COMPLEX*16        A( LDA, * ), WORK( * ), C(LDC, * ),
                     16: *     $                  T( LDT, * )
                     17: *> \par Purpose:
                     18: *  =============
                     19: *>
                     20: *> \verbatim
                     21: *>
                     22: *>      ZLAMTSQR overwrites the general complex M-by-N matrix C with
                     23: *>
                     24: *>
                     25: *>                 SIDE = 'L'     SIDE = 'R'
                     26: *> TRANS = 'N':      Q * C          C * Q
1.3       bertrand   27: *> TRANS = 'C':      Q**H * C       C * Q**H
1.6     ! bertrand   28: *>      where Q is a complex unitary matrix defined as the product
1.1       bertrand   29: *>      of blocked elementary reflectors computed by tall skinny
                     30: *>      QR factorization (ZLATSQR)
                     31: *> \endverbatim
                     32: *
                     33: *  Arguments:
                     34: *  ==========
                     35: *
                     36: *> \param[in] SIDE
                     37: *> \verbatim
                     38: *>          SIDE is CHARACTER*1
1.3       bertrand   39: *>          = 'L': apply Q or Q**H from the Left;
                     40: *>          = 'R': apply Q or Q**H from the Right.
1.1       bertrand   41: *> \endverbatim
                     42: *>
                     43: *> \param[in] TRANS
                     44: *> \verbatim
                     45: *>          TRANS is CHARACTER*1
                     46: *>          = 'N':  No transpose, apply Q;
1.3       bertrand   47: *>          = 'C':  Conjugate Transpose, apply Q**H.
1.1       bertrand   48: *> \endverbatim
                     49: *>
                     50: *> \param[in] M
                     51: *> \verbatim
                     52: *>          M is INTEGER
                     53: *>          The number of rows of the matrix A.  M >=0.
                     54: *> \endverbatim
                     55: *>
                     56: *> \param[in] N
                     57: *> \verbatim
                     58: *>          N is INTEGER
1.6     ! bertrand   59: *>          The number of columns of the matrix C. N >= 0.
1.1       bertrand   60: *> \endverbatim
                     61: *>
                     62: *> \param[in] K
                     63: *> \verbatim
                     64: *>          K is INTEGER
                     65: *>          The number of elementary reflectors whose product defines
1.6     ! bertrand   66: *>          the matrix Q. M >= K >= 0;
1.1       bertrand   67: *>
                     68: *> \endverbatim
                     69: *>
                     70: *> \param[in] MB
                     71: *> \verbatim
                     72: *>          MB is INTEGER
                     73: *>          The block size to be used in the blocked QR.
1.6     ! bertrand   74: *>          MB > N. (must be the same as ZLATSQR)
1.1       bertrand   75: *> \endverbatim
                     76: *>
                     77: *> \param[in] NB
                     78: *> \verbatim
                     79: *>          NB is INTEGER
                     80: *>          The column block size to be used in the blocked QR.
                     81: *>          N >= NB >= 1.
                     82: *> \endverbatim
                     83: *>
1.3       bertrand   84: *> \param[in] A
1.1       bertrand   85: *> \verbatim
                     86: *>          A is COMPLEX*16 array, dimension (LDA,K)
                     87: *>          The i-th column must contain the vector which defines the
                     88: *>          blockedelementary reflector H(i), for i = 1,2,...,k, as
1.6     ! bertrand   89: *>          returned by ZLATSQR in the first k columns of
1.1       bertrand   90: *>          its array argument A.
                     91: *> \endverbatim
                     92: *>
                     93: *> \param[in] LDA
                     94: *> \verbatim
                     95: *>          LDA is INTEGER
                     96: *>          The leading dimension of the array A.
                     97: *>          If SIDE = 'L', LDA >= max(1,M);
                     98: *>          if SIDE = 'R', LDA >= max(1,N).
                     99: *> \endverbatim
                    100: *>
                    101: *> \param[in] T
                    102: *> \verbatim
                    103: *>          T is COMPLEX*16 array, dimension
                    104: *>          ( N * Number of blocks(CEIL(M-K/MB-K)),
                    105: *>          The blocked upper triangular block reflectors stored in compact form
                    106: *>          as a sequence of upper triangular blocks.  See below
                    107: *>          for further details.
                    108: *> \endverbatim
                    109: *>
                    110: *> \param[in] LDT
                    111: *> \verbatim
                    112: *>          LDT is INTEGER
                    113: *>          The leading dimension of the array T.  LDT >= NB.
                    114: *> \endverbatim
                    115: *>
                    116: *> \param[in,out] C
                    117: *> \verbatim
                    118: *>          C is COMPLEX*16 array, dimension (LDC,N)
                    119: *>          On entry, the M-by-N matrix C.
1.3       bertrand  120: *>          On exit, C is overwritten by Q*C or Q**H*C or C*Q**H or C*Q.
1.1       bertrand  121: *> \endverbatim
                    122: *>
                    123: *> \param[in] LDC
                    124: *> \verbatim
                    125: *>          LDC is INTEGER
                    126: *>          The leading dimension of the array C. LDC >= max(1,M).
                    127: *> \endverbatim
                    128: *>
                    129: *> \param[out] WORK
                    130: *> \verbatim
                    131: *>         (workspace) COMPLEX*16 array, dimension (MAX(1,LWORK))
                    132: *>
                    133: *> \endverbatim
                    134: *> \param[in] LWORK
                    135: *> \verbatim
                    136: *>          LWORK is INTEGER
                    137: *>          The dimension of the array WORK.
                    138: *>
                    139: *>          If SIDE = 'L', LWORK >= max(1,N)*NB;
                    140: *>          if SIDE = 'R', LWORK >= max(1,MB)*NB.
                    141: *>          If LWORK = -1, then a workspace query is assumed; the routine
                    142: *>          only calculates the optimal size of the WORK array, returns
                    143: *>          this value as the first entry of the WORK array, and no error
                    144: *>          message related to LWORK is issued by XERBLA.
                    145: *>
                    146: *> \endverbatim
                    147: *> \param[out] INFO
                    148: *> \verbatim
                    149: *>          INFO is INTEGER
                    150: *>          = 0:  successful exit
                    151: *>          < 0:  if INFO = -i, the i-th argument had an illegal value
                    152: *> \endverbatim
                    153: *
                    154: *  Authors:
                    155: *  ========
                    156: *
                    157: *> \author Univ. of Tennessee
                    158: *> \author Univ. of California Berkeley
                    159: *> \author Univ. of Colorado Denver
                    160: *> \author NAG Ltd.
                    161: *
                    162: *> \par Further Details:
                    163: *  =====================
                    164: *>
                    165: *> \verbatim
1.6     ! bertrand  166: *> Tall-Skinny QR (TSQR) performs QR by a sequence of unitary transformations,
        !           167: *> representing Q as a product of other unitary matrices
1.1       bertrand  168: *>   Q = Q(1) * Q(2) * . . . * Q(k)
                    169: *> where each Q(i) zeros out subdiagonal entries of a block of MB rows of A:
                    170: *>   Q(1) zeros out the subdiagonal entries of rows 1:MB of A
                    171: *>   Q(2) zeros out the bottom MB-N rows of rows [1:N,MB+1:2*MB-N] of A
                    172: *>   Q(3) zeros out the bottom MB-N rows of rows [1:N,2*MB-N+1:3*MB-2*N] of A
                    173: *>   . . .
                    174: *>
                    175: *> Q(1) is computed by GEQRT, which represents Q(1) by Householder vectors
                    176: *> stored under the diagonal of rows 1:MB of A, and by upper triangular
                    177: *> block reflectors, stored in array T(1:LDT,1:N).
                    178: *> For more information see Further Details in GEQRT.
                    179: *>
                    180: *> Q(i) for i>1 is computed by TPQRT, which represents Q(i) by Householder vectors
                    181: *> stored in rows [(i-1)*(MB-N)+N+1:i*(MB-N)+N] of A, and by upper triangular
                    182: *> block reflectors, stored in array T(1:LDT,(i-1)*N+1:i*N).
                    183: *> The last Q(k) may use fewer rows.
                    184: *> For more information see Further Details in TPQRT.
                    185: *>
                    186: *> For more details of the overall algorithm, see the description of
                    187: *> Sequential TSQR in Section 2.2 of [1].
                    188: *>
                    189: *> [1] “Communication-Optimal Parallel and Sequential QR and LU Factorizations,”
                    190: *>     J. Demmel, L. Grigori, M. Hoemmen, J. Langou,
                    191: *>     SIAM J. Sci. Comput, vol. 34, no. 1, 2012
                    192: *> \endverbatim
                    193: *>
                    194: *  =====================================================================
                    195:       SUBROUTINE ZLAMTSQR( SIDE, TRANS, M, N, K, MB, NB, A, LDA, T,
                    196:      $        LDT, C, LDC, WORK, LWORK, INFO )
                    197: *
1.6     ! bertrand  198: *  -- LAPACK computational routine --
1.1       bertrand  199: *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
                    200: *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
                    201: *
                    202: *     .. Scalar Arguments ..
                    203:       CHARACTER         SIDE, TRANS
                    204:       INTEGER           INFO, LDA, M, N, K, MB, NB, LDT, LWORK, LDC
                    205: *     ..
                    206: *     .. Array Arguments ..
                    207:       COMPLEX*16        A( LDA, * ), WORK( * ), C(LDC, * ),
                    208:      $                T( LDT, * )
                    209: *     ..
                    210: *
                    211: * =====================================================================
                    212: *
                    213: *     ..
                    214: *     .. Local Scalars ..
                    215:       LOGICAL    LEFT, RIGHT, TRAN, NOTRAN, LQUERY
1.6     ! bertrand  216:       INTEGER    I, II, KK, LW, CTR, Q
1.1       bertrand  217: *     ..
                    218: *     .. External Functions ..
                    219:       LOGICAL            LSAME
                    220:       EXTERNAL           LSAME
                    221: *     .. External Subroutines ..
                    222:       EXTERNAL   ZGEMQRT, ZTPMQRT, XERBLA
                    223: *     ..
                    224: *     .. Executable Statements ..
                    225: *
                    226: *     Test the input arguments
                    227: *
                    228:       LQUERY  = LWORK.LT.0
                    229:       NOTRAN  = LSAME( TRANS, 'N' )
                    230:       TRAN    = LSAME( TRANS, 'C' )
                    231:       LEFT    = LSAME( SIDE, 'L' )
                    232:       RIGHT   = LSAME( SIDE, 'R' )
                    233:       IF (LEFT) THEN
                    234:         LW = N * NB
1.6     ! bertrand  235:         Q = M
1.1       bertrand  236:       ELSE
                    237:         LW = M * NB
1.6     ! bertrand  238:         Q = N
1.1       bertrand  239:       END IF
                    240: *
                    241:       INFO = 0
                    242:       IF( .NOT.LEFT .AND. .NOT.RIGHT ) THEN
                    243:          INFO = -1
                    244:       ELSE IF( .NOT.TRAN .AND. .NOT.NOTRAN ) THEN
                    245:          INFO = -2
1.6     ! bertrand  246:       ELSE IF( M.LT.K ) THEN
1.1       bertrand  247:         INFO = -3
                    248:       ELSE IF( N.LT.0 ) THEN
                    249:         INFO = -4
                    250:       ELSE IF( K.LT.0 ) THEN
                    251:         INFO = -5
1.6     ! bertrand  252:       ELSE IF( K.LT.NB .OR. NB.LT.1 ) THEN
        !           253:         INFO = -7
        !           254:       ELSE IF( LDA.LT.MAX( 1, Q ) ) THEN
1.1       bertrand  255:         INFO = -9
                    256:       ELSE IF( LDT.LT.MAX( 1, NB) ) THEN
                    257:         INFO = -11
                    258:       ELSE IF( LDC.LT.MAX( 1, M ) ) THEN
                    259:          INFO = -13
                    260:       ELSE IF(( LWORK.LT.MAX(1,LW)).AND.(.NOT.LQUERY)) THEN
                    261:         INFO = -15
                    262:       END IF
                    263: *
                    264: *     Determine the block size if it is tall skinny or short and wide
                    265: *
                    266:       IF( INFO.EQ.0)  THEN
                    267:           WORK(1) = LW
                    268:       END IF
                    269: *
                    270:       IF( INFO.NE.0 ) THEN
                    271:         CALL XERBLA( 'ZLAMTSQR', -INFO )
                    272:         RETURN
                    273:       ELSE IF (LQUERY) THEN
                    274:        RETURN
                    275:       END IF
                    276: *
                    277: *     Quick return if possible
                    278: *
                    279:       IF( MIN(M,N,K).EQ.0 ) THEN
                    280:         RETURN
                    281:       END IF
                    282: *
                    283:       IF((MB.LE.K).OR.(MB.GE.MAX(M,N,K))) THEN
                    284:         CALL ZGEMQRT( SIDE, TRANS, M, N, K, NB, A, LDA,
                    285:      $        T, LDT, C, LDC, WORK, INFO)
                    286:         RETURN
                    287:        END IF
                    288: *
                    289:       IF(LEFT.AND.NOTRAN) THEN
                    290: *
                    291: *         Multiply Q to the last block of C
                    292: *
                    293:          KK = MOD((M-K),(MB-K))
                    294:          CTR = (M-K)/(MB-K)
                    295:          IF (KK.GT.0) THEN
                    296:            II=M-KK+1
                    297:            CALL ZTPMQRT('L','N',KK , N, K, 0, NB, A(II,1), LDA,
                    298:      $       T(1, CTR * K + 1),LDT , C(1,1), LDC,
                    299:      $       C(II,1), LDC, WORK, INFO )
                    300:          ELSE
                    301:            II=M+1
                    302:          END IF
                    303: *
                    304:          DO I=II-(MB-K),MB+1,-(MB-K)
                    305: *
                    306: *         Multiply Q to the current block of C (I:I+MB,1:N)
                    307: *
                    308:            CTR = CTR - 1
                    309:            CALL ZTPMQRT('L','N',MB-K , N, K, 0,NB, A(I,1), LDA,
                    310:      $         T(1,CTR * K + 1),LDT, C(1,1), LDC,
                    311:      $         C(I,1), LDC, WORK, INFO )
                    312: 
                    313:          END DO
                    314: *
                    315: *         Multiply Q to the first block of C (1:MB,1:N)
                    316: *
                    317:          CALL ZGEMQRT('L','N',MB , N, K, NB, A(1,1), LDA, T
                    318:      $            ,LDT ,C(1,1), LDC, WORK, INFO )
                    319: *
                    320:       ELSE IF (LEFT.AND.TRAN) THEN
                    321: *
                    322: *         Multiply Q to the first block of C
                    323: *
                    324:          KK = MOD((M-K),(MB-K))
                    325:          II=M-KK+1
                    326:          CTR = 1
                    327:          CALL ZGEMQRT('L','C',MB , N, K, NB, A(1,1), LDA, T
                    328:      $            ,LDT ,C(1,1), LDC, WORK, INFO )
                    329: *
                    330:          DO I=MB+1,II-MB+K,(MB-K)
                    331: *
                    332: *         Multiply Q to the current block of C (I:I+MB,1:N)
                    333: *
                    334:           CALL ZTPMQRT('L','C',MB-K , N, K, 0,NB, A(I,1), LDA,
                    335:      $       T(1,CTR * K + 1),LDT, C(1,1), LDC,
                    336:      $       C(I,1), LDC, WORK, INFO )
                    337:           CTR = CTR + 1
                    338: *
                    339:          END DO
                    340:          IF(II.LE.M) THEN
                    341: *
                    342: *         Multiply Q to the last block of C
                    343: *
                    344:           CALL ZTPMQRT('L','C',KK , N, K, 0,NB, A(II,1), LDA,
                    345:      $      T(1, CTR * K + 1), LDT, C(1,1), LDC,
                    346:      $      C(II,1), LDC, WORK, INFO )
                    347: *
                    348:          END IF
                    349: *
                    350:       ELSE IF(RIGHT.AND.TRAN) THEN
                    351: *
                    352: *         Multiply Q to the last block of C
                    353: *
                    354:           KK = MOD((N-K),(MB-K))
                    355:           CTR = (N-K)/(MB-K)
                    356:           IF (KK.GT.0) THEN
                    357:             II=N-KK+1
                    358:             CALL ZTPMQRT('R','C',M , KK, K, 0, NB, A(II,1), LDA,
                    359:      $        T(1,CTR * K + 1), LDT, C(1,1), LDC,
                    360:      $        C(1,II), LDC, WORK, INFO )
                    361:           ELSE
                    362:             II=N+1
                    363:           END IF
                    364: *
                    365:           DO I=II-(MB-K),MB+1,-(MB-K)
                    366: *
                    367: *         Multiply Q to the current block of C (1:M,I:I+MB)
                    368: *
                    369:             CTR = CTR - 1
                    370:             CALL ZTPMQRT('R','C',M , MB-K, K, 0,NB, A(I,1), LDA,
                    371:      $          T(1, CTR * K + 1), LDT, C(1,1), LDC,
                    372:      $          C(1,I), LDC, WORK, INFO )
                    373: 
                    374:           END DO
                    375: *
                    376: *         Multiply Q to the first block of C (1:M,1:MB)
                    377: *
                    378:           CALL ZGEMQRT('R','C',M , MB, K, NB, A(1,1), LDA, T
                    379:      $              ,LDT ,C(1,1), LDC, WORK, INFO )
                    380: *
                    381:       ELSE IF (RIGHT.AND.NOTRAN) THEN
                    382: *
                    383: *         Multiply Q to the first block of C
                    384: *
                    385:          KK = MOD((N-K),(MB-K))
                    386:          II=N-KK+1
                    387:          CTR = 1
                    388:          CALL ZGEMQRT('R','N', M, MB , K, NB, A(1,1), LDA, T
                    389:      $              ,LDT ,C(1,1), LDC, WORK, INFO )
                    390: *
                    391:          DO I=MB+1,II-MB+K,(MB-K)
                    392: *
                    393: *         Multiply Q to the current block of C (1:M,I:I+MB)
                    394: *
                    395:           CALL ZTPMQRT('R','N', M, MB-K, K, 0,NB, A(I,1), LDA,
                    396:      $         T(1, CTR * K + 1),LDT, C(1,1), LDC,
                    397:      $         C(1,I), LDC, WORK, INFO )
                    398:           CTR = CTR + 1
                    399: *
                    400:          END DO
                    401:          IF(II.LE.N) THEN
                    402: *
                    403: *         Multiply Q to the last block of C
                    404: *
                    405:           CALL ZTPMQRT('R','N', M, KK , K, 0,NB, A(II,1), LDA,
                    406:      $        T(1,CTR * K + 1),LDT, C(1,1), LDC,
                    407:      $        C(1,II), LDC, WORK, INFO )
                    408: *
                    409:          END IF
                    410: *
                    411:       END IF
                    412: *
                    413:       WORK(1) = LW
                    414:       RETURN
                    415: *
                    416: *     End of ZLAMTSQR
                    417: *
                    418:       END

CVSweb interface <joel.bertrand@systella.fr>