LAPACK 3.3.1
Linear Algebra PACKage
|
00001 SUBROUTINE ZUNGRQ( M, N, K, A, LDA, TAU, WORK, LWORK, INFO ) 00002 * 00003 * -- LAPACK routine (version 3.3.1) -- 00004 * -- LAPACK is a software package provided by Univ. of Tennessee, -- 00005 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..-- 00006 * -- April 2011 -- 00007 * 00008 * .. Scalar Arguments .. 00009 INTEGER INFO, K, LDA, LWORK, M, N 00010 * .. 00011 * .. Array Arguments .. 00012 COMPLEX*16 A( LDA, * ), TAU( * ), WORK( * ) 00013 * .. 00014 * 00015 * Purpose 00016 * ======= 00017 * 00018 * ZUNGRQ generates an M-by-N complex matrix Q with orthonormal rows, 00019 * which is defined as the last M rows of a product of K elementary 00020 * reflectors of order N 00021 * 00022 * Q = H(1)**H H(2)**H . . . H(k)**H 00023 * 00024 * as returned by ZGERQF. 00025 * 00026 * Arguments 00027 * ========= 00028 * 00029 * M (input) INTEGER 00030 * The number of rows of the matrix Q. M >= 0. 00031 * 00032 * N (input) INTEGER 00033 * The number of columns of the matrix Q. N >= M. 00034 * 00035 * K (input) INTEGER 00036 * The number of elementary reflectors whose product defines the 00037 * matrix Q. M >= K >= 0. 00038 * 00039 * A (input/output) COMPLEX*16 array, dimension (LDA,N) 00040 * On entry, the (m-k+i)-th row must contain the vector which 00041 * defines the elementary reflector H(i), for i = 1,2,...,k, as 00042 * returned by ZGERQF in the last k rows of its array argument 00043 * A. 00044 * On exit, the M-by-N matrix Q. 00045 * 00046 * LDA (input) INTEGER 00047 * The first dimension of the array A. LDA >= max(1,M). 00048 * 00049 * TAU (input) COMPLEX*16 array, dimension (K) 00050 * TAU(i) must contain the scalar factor of the elementary 00051 * reflector H(i), as returned by ZGERQF. 00052 * 00053 * WORK (workspace/output) COMPLEX*16 array, dimension (MAX(1,LWORK)) 00054 * On exit, if INFO = 0, WORK(1) returns the optimal LWORK. 00055 * 00056 * LWORK (input) INTEGER 00057 * The dimension of the array WORK. LWORK >= max(1,M). 00058 * For optimum performance LWORK >= M*NB, where NB is the 00059 * optimal blocksize. 00060 * 00061 * If LWORK = -1, then a workspace query is assumed; the routine 00062 * only calculates the optimal size of the WORK array, returns 00063 * this value as the first entry of the WORK array, and no error 00064 * message related to LWORK is issued by XERBLA. 00065 * 00066 * INFO (output) INTEGER 00067 * = 0: successful exit 00068 * < 0: if INFO = -i, the i-th argument has an illegal value 00069 * 00070 * ===================================================================== 00071 * 00072 * .. Parameters .. 00073 COMPLEX*16 ZERO 00074 PARAMETER ( ZERO = ( 0.0D+0, 0.0D+0 ) ) 00075 * .. 00076 * .. Local Scalars .. 00077 LOGICAL LQUERY 00078 INTEGER I, IB, II, IINFO, IWS, J, KK, L, LDWORK, 00079 $ LWKOPT, NB, NBMIN, NX 00080 * .. 00081 * .. External Subroutines .. 00082 EXTERNAL XERBLA, ZLARFB, ZLARFT, ZUNGR2 00083 * .. 00084 * .. Intrinsic Functions .. 00085 INTRINSIC MAX, MIN 00086 * .. 00087 * .. External Functions .. 00088 INTEGER ILAENV 00089 EXTERNAL ILAENV 00090 * .. 00091 * .. Executable Statements .. 00092 * 00093 * Test the input arguments 00094 * 00095 INFO = 0 00096 LQUERY = ( LWORK.EQ.-1 ) 00097 IF( M.LT.0 ) THEN 00098 INFO = -1 00099 ELSE IF( N.LT.M ) THEN 00100 INFO = -2 00101 ELSE IF( K.LT.0 .OR. K.GT.M ) THEN 00102 INFO = -3 00103 ELSE IF( LDA.LT.MAX( 1, M ) ) THEN 00104 INFO = -5 00105 END IF 00106 * 00107 IF( INFO.EQ.0 ) THEN 00108 IF( M.LE.0 ) THEN 00109 LWKOPT = 1 00110 ELSE 00111 NB = ILAENV( 1, 'ZUNGRQ', ' ', M, N, K, -1 ) 00112 LWKOPT = M*NB 00113 END IF 00114 WORK( 1 ) = LWKOPT 00115 * 00116 IF( LWORK.LT.MAX( 1, M ) .AND. .NOT.LQUERY ) THEN 00117 INFO = -8 00118 END IF 00119 END IF 00120 * 00121 IF( INFO.NE.0 ) THEN 00122 CALL XERBLA( 'ZUNGRQ', -INFO ) 00123 RETURN 00124 ELSE IF( LQUERY ) THEN 00125 RETURN 00126 END IF 00127 * 00128 * Quick return if possible 00129 * 00130 IF( M.LE.0 ) THEN 00131 RETURN 00132 END IF 00133 * 00134 NBMIN = 2 00135 NX = 0 00136 IWS = M 00137 IF( NB.GT.1 .AND. NB.LT.K ) THEN 00138 * 00139 * Determine when to cross over from blocked to unblocked code. 00140 * 00141 NX = MAX( 0, ILAENV( 3, 'ZUNGRQ', ' ', M, N, K, -1 ) ) 00142 IF( NX.LT.K ) THEN 00143 * 00144 * Determine if workspace is large enough for blocked code. 00145 * 00146 LDWORK = M 00147 IWS = LDWORK*NB 00148 IF( LWORK.LT.IWS ) THEN 00149 * 00150 * Not enough workspace to use optimal NB: reduce NB and 00151 * determine the minimum value of NB. 00152 * 00153 NB = LWORK / LDWORK 00154 NBMIN = MAX( 2, ILAENV( 2, 'ZUNGRQ', ' ', M, N, K, -1 ) ) 00155 END IF 00156 END IF 00157 END IF 00158 * 00159 IF( NB.GE.NBMIN .AND. NB.LT.K .AND. NX.LT.K ) THEN 00160 * 00161 * Use blocked code after the first block. 00162 * The last kk rows are handled by the block method. 00163 * 00164 KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB ) 00165 * 00166 * Set A(1:m-kk,n-kk+1:n) to zero. 00167 * 00168 DO 20 J = N - KK + 1, N 00169 DO 10 I = 1, M - KK 00170 A( I, J ) = ZERO 00171 10 CONTINUE 00172 20 CONTINUE 00173 ELSE 00174 KK = 0 00175 END IF 00176 * 00177 * Use unblocked code for the first or only block. 00178 * 00179 CALL ZUNGR2( M-KK, N-KK, K-KK, A, LDA, TAU, WORK, IINFO ) 00180 * 00181 IF( KK.GT.0 ) THEN 00182 * 00183 * Use blocked code 00184 * 00185 DO 50 I = K - KK + 1, K, NB 00186 IB = MIN( NB, K-I+1 ) 00187 II = M - K + I 00188 IF( II.GT.1 ) THEN 00189 * 00190 * Form the triangular factor of the block reflector 00191 * H = H(i+ib-1) . . . H(i+1) H(i) 00192 * 00193 CALL ZLARFT( 'Backward', 'Rowwise', N-K+I+IB-1, IB, 00194 $ A( II, 1 ), LDA, TAU( I ), WORK, LDWORK ) 00195 * 00196 * Apply H**H to A(1:m-k+i-1,1:n-k+i+ib-1) from the right 00197 * 00198 CALL ZLARFB( 'Right', 'Conjugate transpose', 'Backward', 00199 $ 'Rowwise', II-1, N-K+I+IB-1, IB, A( II, 1 ), 00200 $ LDA, WORK, LDWORK, A, LDA, WORK( IB+1 ), 00201 $ LDWORK ) 00202 END IF 00203 * 00204 * Apply H**H to columns 1:n-k+i+ib-1 of current block 00205 * 00206 CALL ZUNGR2( IB, N-K+I+IB-1, IB, A( II, 1 ), LDA, TAU( I ), 00207 $ WORK, IINFO ) 00208 * 00209 * Set columns n-k+i+ib:n of current block to zero 00210 * 00211 DO 40 L = N - K + I + IB, N 00212 DO 30 J = II, II + IB - 1 00213 A( J, L ) = ZERO 00214 30 CONTINUE 00215 40 CONTINUE 00216 50 CONTINUE 00217 END IF 00218 * 00219 WORK( 1 ) = IWS 00220 RETURN 00221 * 00222 * End of ZUNGRQ 00223 * 00224 END