LAPACK 3.3.0

sorgql.f

Go to the documentation of this file.
00001       SUBROUTINE SORGQL( M, N, K, A, LDA, TAU, WORK, LWORK, INFO )
00002 *
00003 *  -- LAPACK routine (version 3.2) --
00004 *  -- LAPACK is a software package provided by Univ. of Tennessee,    --
00005 *  -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
00006 *     November 2006
00007 *
00008 *     .. Scalar Arguments ..
00009       INTEGER            INFO, K, LDA, LWORK, M, N
00010 *     ..
00011 *     .. Array Arguments ..
00012       REAL               A( LDA, * ), TAU( * ), WORK( * )
00013 *     ..
00014 *
00015 *  Purpose
00016 *  =======
00017 *
00018 *  SORGQL generates an M-by-N real matrix Q with orthonormal columns,
00019 *  which is defined as the last N columns of a product of K elementary
00020 *  reflectors of order M
00021 *
00022 *        Q  =  H(k) . . . H(2) H(1)
00023 *
00024 *  as returned by SGEQLF.
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. M >= N >= 0.
00034 *
00035 *  K       (input) INTEGER
00036 *          The number of elementary reflectors whose product defines the
00037 *          matrix Q. N >= K >= 0.
00038 *
00039 *  A       (input/output) REAL array, dimension (LDA,N)
00040 *          On entry, the (n-k+i)-th column must contain the vector which
00041 *          defines the elementary reflector H(i), for i = 1,2,...,k, as
00042 *          returned by SGEQLF in the last k columns of its array
00043 *          argument 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) REAL array, dimension (K)
00050 *          TAU(i) must contain the scalar factor of the elementary
00051 *          reflector H(i), as returned by SGEQLF.
00052 *
00053 *  WORK    (workspace/output) REAL 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,N).
00058 *          For optimum performance LWORK >= N*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       REAL               ZERO
00074       PARAMETER          ( ZERO = 0.0E+0 )
00075 *     ..
00076 *     .. Local Scalars ..
00077       LOGICAL            LQUERY
00078       INTEGER            I, IB, IINFO, IWS, J, KK, L, LDWORK, LWKOPT,
00079      $                   NB, NBMIN, NX
00080 *     ..
00081 *     .. External Subroutines ..
00082       EXTERNAL           SLARFB, SLARFT, SORG2L, XERBLA
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.0 .OR. N.GT.M ) THEN
00100          INFO = -2
00101       ELSE IF( K.LT.0 .OR. K.GT.N ) 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( N.EQ.0 ) THEN
00109             LWKOPT = 1
00110          ELSE
00111             NB = ILAENV( 1, 'SORGQL', ' ', M, N, K, -1 )
00112             LWKOPT = N*NB
00113          END IF
00114          WORK( 1 ) = LWKOPT
00115 *
00116          IF( LWORK.LT.MAX( 1, N ) .AND. .NOT.LQUERY ) THEN
00117             INFO = -8
00118          END IF
00119       END IF
00120 *
00121       IF( INFO.NE.0 ) THEN
00122          CALL XERBLA( 'SORGQL', -INFO )
00123          RETURN
00124       ELSE IF( LQUERY ) THEN
00125          RETURN
00126       END IF
00127 *
00128 *     Quick return if possible
00129 *
00130       IF( N.LE.0 ) THEN
00131          RETURN
00132       END IF
00133 *
00134       NBMIN = 2
00135       NX = 0
00136       IWS = N
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, 'SORGQL', ' ', M, N, K, -1 ) )
00142          IF( NX.LT.K ) THEN
00143 *
00144 *           Determine if workspace is large enough for blocked code.
00145 *
00146             LDWORK = N
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, 'SORGQL', ' ', 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 columns are handled by the block method.
00163 *
00164          KK = MIN( K, ( ( K-NX+NB-1 ) / NB )*NB )
00165 *
00166 *        Set A(m-kk+1:m,1:n-kk) to zero.
00167 *
00168          DO 20 J = 1, N - KK
00169             DO 10 I = M - KK + 1, M
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 SORG2L( 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             IF( N-K+I.GT.1 ) THEN
00188 *
00189 *              Form the triangular factor of the block reflector
00190 *              H = H(i+ib-1) . . . H(i+1) H(i)
00191 *
00192                CALL SLARFT( 'Backward', 'Columnwise', M-K+I+IB-1, IB,
00193      $                      A( 1, N-K+I ), LDA, TAU( I ), WORK, LDWORK )
00194 *
00195 *              Apply H to A(1:m-k+i+ib-1,1:n-k+i-1) from the left
00196 *
00197                CALL SLARFB( 'Left', 'No transpose', 'Backward',
00198      $                      'Columnwise', M-K+I+IB-1, N-K+I-1, IB,
00199      $                      A( 1, N-K+I ), LDA, WORK, LDWORK, A, LDA,
00200      $                      WORK( IB+1 ), LDWORK )
00201             END IF
00202 *
00203 *           Apply H to rows 1:m-k+i+ib-1 of current block
00204 *
00205             CALL SORG2L( M-K+I+IB-1, IB, IB, A( 1, N-K+I ), LDA,
00206      $                   TAU( I ), WORK, IINFO )
00207 *
00208 *           Set rows m-k+i+ib:m of current block to zero
00209 *
00210             DO 40 J = N - K + I, N - K + I + IB - 1
00211                DO 30 L = M - K + I + IB, M
00212                   A( L, J ) = ZERO
00213    30          CONTINUE
00214    40       CONTINUE
00215    50    CONTINUE
00216       END IF
00217 *
00218       WORK( 1 ) = IWS
00219       RETURN
00220 *
00221 *     End of SORGQL
00222 *
00223       END
 All Files Functions