ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pdgeqrf.f
Go to the documentation of this file.
00001       SUBROUTINE PDGEQRF( M, N, A, IA, JA, DESCA, TAU, WORK, LWORK,
00002      $                    INFO )
00003 *
00004 *  -- ScaLAPACK routine (version 1.7) --
00005 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00006 *     and University of California, Berkeley.
00007 *     May 25, 2001
00008 *
00009 *     .. Scalar Arguments ..
00010       INTEGER            IA, INFO, JA, LWORK, M, N
00011 *     ..
00012 *     .. Array Arguments ..
00013       INTEGER            DESCA( * )
00014       DOUBLE PRECISION   A( * ), TAU( * ), WORK( * )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  PDGEQRF computes a QR factorization of a real distributed M-by-N
00021 *  matrix sub( A ) = A(IA:IA+M-1,JA:JA+N-1) = Q * R.
00022 *
00023 *  Notes
00024 *  =====
00025 *
00026 *  Each global data object is described by an associated description
00027 *  vector.  This vector stores the information required to establish
00028 *  the mapping between an object element and its corresponding process
00029 *  and memory location.
00030 *
00031 *  Let A be a generic term for any 2D block cyclicly distributed array.
00032 *  Such a global array has an associated description vector DESCA.
00033 *  In the following comments, the character _ should be read as
00034 *  "of the global array".
00035 *
00036 *  NOTATION        STORED IN      EXPLANATION
00037 *  --------------- -------------- --------------------------------------
00038 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00039 *                                 DTYPE_A = 1.
00040 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00041 *                                 the BLACS process grid A is distribu-
00042 *                                 ted over. The context itself is glo-
00043 *                                 bal, but the handle (the integer
00044 *                                 value) may vary.
00045 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00046 *                                 array A.
00047 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00048 *                                 array A.
00049 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00050 *                                 the rows of the array.
00051 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00052 *                                 the columns of the array.
00053 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00054 *                                 row of the array A is distributed.
00055 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00056 *                                 first column of the array A is
00057 *                                 distributed.
00058 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00059 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00060 *
00061 *  Let K be the number of rows or columns of a distributed matrix,
00062 *  and assume that its process grid has dimension p x q.
00063 *  LOCr( K ) denotes the number of elements of K that a process
00064 *  would receive if K were distributed over the p processes of its
00065 *  process column.
00066 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00067 *  process would receive if K were distributed over the q processes of
00068 *  its process row.
00069 *  The values of LOCr() and LOCc() may be determined via a call to the
00070 *  ScaLAPACK tool function, NUMROC:
00071 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00072 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00073 *  An upper bound for these quantities may be computed by:
00074 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00075 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00076 *
00077 *  Arguments
00078 *  =========
00079 *
00080 *  M       (global input) INTEGER
00081 *          The number of rows to be operated on, i.e. the number of rows
00082 *          of the distributed submatrix sub( A ). M >= 0.
00083 *
00084 *  N       (global input) INTEGER
00085 *          The number of columns to be operated on, i.e. the number of
00086 *          columns of the distributed submatrix sub( A ). N >= 0.
00087 *
00088 *  A       (local input/local output) DOUBLE PRECISION pointer into the
00089 *          local memory to an array of dimension (LLD_A, LOCc(JA+N-1)).
00090 *          On entry, the local pieces of the M-by-N distributed matrix
00091 *          sub( A ) which is to be factored.  On exit, the elements on
00092 *          and above the diagonal of sub( A ) contain the min(M,N) by N
00093 *          upper trapezoidal matrix R (R is upper triangular if M >= N);
00094 *          the elements below the diagonal, with the array TAU,
00095 *          represent the orthogonal matrix Q as a product of elementary
00096 *          reflectors (see Further Details).
00097 *
00098 *  IA      (global input) INTEGER
00099 *          The row index in the global array A indicating the first
00100 *          row of sub( A ).
00101 *
00102 *  JA      (global input) INTEGER
00103 *          The column index in the global array A indicating the
00104 *          first column of sub( A ).
00105 *
00106 *  DESCA   (global and local input) INTEGER array of dimension DLEN_.
00107 *          The array descriptor for the distributed matrix A.
00108 *
00109 *  TAU     (local output) DOUBLE PRECISION array, dimension
00110 *          LOCc(JA+MIN(M,N)-1). This array contains the scalar factors
00111 *          TAU of the elementary reflectors. TAU is tied to the
00112 *          distributed matrix A.
00113 *
00114 *  WORK    (local workspace/local output) DOUBLE PRECISION array,
00115 *                                                     dimension (LWORK)
00116 *          On exit, WORK(1) returns the minimal and optimal LWORK.
00117 *
00118 *  LWORK   (local or global input) INTEGER
00119 *          The dimension of the array WORK.
00120 *          LWORK is local input and must be at least
00121 *          LWORK >= NB_A * ( Mp0 + Nq0 + NB_A ), where
00122 *
00123 *          IROFF = MOD( IA-1, MB_A ), ICOFF = MOD( JA-1, NB_A ),
00124 *          IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW ),
00125 *          IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL ),
00126 *          Mp0   = NUMROC( M+IROFF, MB_A, MYROW, IAROW, NPROW ),
00127 *          Nq0   = NUMROC( N+ICOFF, NB_A, MYCOL, IACOL, NPCOL ),
00128 *
00129 *          and NUMROC, INDXG2P are ScaLAPACK tool functions;
00130 *          MYROW, MYCOL, NPROW and NPCOL can be determined by calling
00131 *          the subroutine BLACS_GRIDINFO.
00132 *
00133 *          If LWORK = -1, then LWORK is global input and a workspace
00134 *          query is assumed; the routine only calculates the minimum
00135 *          and optimal size for all work arrays. Each of these
00136 *          values is returned in the first entry of the corresponding
00137 *          work array, and no error message is issued by PXERBLA.
00138 *
00139 *  INFO    (global output) INTEGER
00140 *          = 0:  successful exit
00141 *          < 0:  If the i-th argument is an array and the j-entry had
00142 *                an illegal value, then INFO = -(i*100+j), if the i-th
00143 *                argument is a scalar and had an illegal value, then
00144 *                INFO = -i.
00145 *
00146 *  Further Details
00147 *  ===============
00148 *
00149 *  The matrix Q is represented as a product of elementary reflectors
00150 *
00151 *     Q = H(ja) H(ja+1) . . . H(ja+k-1), where k = min(m,n).
00152 *
00153 *  Each H(i) has the form
00154 *
00155 *     H(j) = I - tau * v * v'
00156 *
00157 *  where tau is a real scalar, and v is a real vector with v(1:i-1) = 0
00158 *  and v(i) = 1; v(i+1:m) is stored on exit in A(ia+i:ia+m-1,ja+i-1),
00159 *  and tau in TAU(ja+i-1).
00160 *
00161 *  =====================================================================
00162 *
00163 *     .. Parameters ..
00164       INTEGER            BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
00165      $                   LLD_, MB_, M_, NB_, N_, RSRC_
00166       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00167      $                     CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00168      $                     RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00169 *     ..
00170 *     .. Local Scalars ..
00171       LOGICAL            LQUERY
00172       CHARACTER          COLBTOP, ROWBTOP
00173       INTEGER            I, IACOL, IAROW, ICOFF, ICTXT, IINFO, IPW, J,
00174      $                   JB, JN, K, LWMIN, MP0, MYCOL, MYROW, NPCOL,
00175      $                   NPROW, NQ0
00176 *     ..
00177 *     .. Local Arrays ..
00178       INTEGER            IDUM1( 1 ), IDUM2( 1 )
00179 *     ..
00180 *     .. External Subroutines ..
00181       EXTERNAL           BLACS_GRIDINFO, CHK1MAT, PCHK1MAT, PDGEQR2,
00182      $                   PDLARFB, PDLARFT, PB_TOPGET, PB_TOPSET, PXERBLA
00183 *     ..
00184 *     .. External Functions ..
00185       INTEGER            ICEIL, INDXG2P, NUMROC
00186       EXTERNAL           ICEIL, INDXG2P, NUMROC
00187 *     ..
00188 *     .. Intrinsic Functions ..
00189       INTRINSIC          DBLE, MIN, MOD
00190 *     ..
00191 *     .. Executable Statements ..
00192 *
00193 *     Get grid parameters
00194 *
00195       ICTXT = DESCA( CTXT_ )
00196       CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL )
00197 *
00198 *     Test the input parameters
00199 *
00200       INFO = 0
00201       IF( NPROW.EQ.-1 ) THEN
00202          INFO = -(600+CTXT_)
00203       ELSE
00204          CALL CHK1MAT( M, 1, N, 2, IA, JA, DESCA, 6, INFO )
00205          IF( INFO.EQ.0 ) THEN
00206             ICOFF = MOD( JA-1, DESCA( NB_ ) )
00207             IAROW = INDXG2P( IA, DESCA( MB_ ), MYROW, DESCA( RSRC_ ),
00208      $                       NPROW )
00209             IACOL = INDXG2P( JA, DESCA( NB_ ), MYCOL, DESCA( CSRC_ ),
00210      $                       NPCOL )
00211             MP0 = NUMROC( M+MOD( IA-1, DESCA( MB_ ) ), DESCA( MB_ ),
00212      $                    MYROW, IAROW, NPROW )
00213             NQ0 = NUMROC( N+ICOFF, DESCA( NB_ ), MYCOL, IACOL, NPCOL )
00214             LWMIN = DESCA( NB_ ) * ( MP0 + NQ0 + DESCA( NB_ ) )
00215 *
00216             WORK( 1 ) = DBLE( LWMIN )
00217             LQUERY = ( LWORK.EQ.-1 )
00218             IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY )
00219      $         INFO = -9
00220          END IF
00221          IF( LWORK.EQ.-1 ) THEN
00222             IDUM1( 1 ) = -1
00223          ELSE
00224             IDUM1( 1 ) = 1
00225          END IF
00226          IDUM2( 1 ) = 9
00227          CALL PCHK1MAT( M, 1, N, 2, IA, JA, DESCA, 6, 1, IDUM1, IDUM2,
00228      $                  INFO )
00229       END IF
00230 *
00231       IF( INFO.NE.0 ) THEN
00232          CALL PXERBLA( ICTXT, 'PDGEQRF', -INFO )
00233          RETURN
00234       ELSE IF( LQUERY ) THEN
00235          RETURN
00236       END IF
00237 *
00238 *     Quick return if possible
00239 *
00240       IF( M.EQ.0 .OR. N.EQ.0 )
00241      $   RETURN
00242 *
00243       K = MIN( M, N )
00244       IPW = DESCA( NB_ ) * DESCA( NB_ ) + 1
00245       CALL PB_TOPGET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP )
00246       CALL PB_TOPGET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP )
00247       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', 'I-ring' )
00248       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', ' ' )
00249 *
00250 *     Handle the first block of columns separately
00251 *
00252       JN = MIN( ICEIL( JA, DESCA( NB_ ) ) * DESCA( NB_ ), JA+K-1 )
00253       JB = JN - JA + 1
00254 *
00255 *     Compute the QR factorization of the first block A(ia:ia+m-1,ja:jn)
00256 *
00257       CALL PDGEQR2( M, JB, A, IA, JA, DESCA, TAU, WORK, LWORK, IINFO )
00258 *
00259       IF( JA+JB.LE.JA+N-1 ) THEN
00260 *
00261 *        Form the triangular factor of the block reflector
00262 *        H = H(ja) H(ja+1) . . . H(jn)
00263 *
00264          CALL PDLARFT( 'Forward', 'Columnwise', M, JB, A, IA, JA, DESCA,
00265      $                 TAU, WORK, WORK( IPW ) )
00266 *
00267 *        Apply H' to A(ia:ia+m-1,ja+jb:ja+n-1) from the left
00268 *
00269          CALL PDLARFB( 'Left', 'Transpose', 'Forward', 'Columnwise', M,
00270      $                 N-JB, JB, A, IA, JA, DESCA, WORK, A, IA, JA+JB,
00271      $                 DESCA, WORK( IPW ) )
00272       END IF
00273 *
00274 *     Loop over the remaining blocks of columns
00275 *
00276       DO 10 J = JN+1, JA+K-1, DESCA( NB_ )
00277          JB = MIN( K-J+JA, DESCA( NB_ ) )
00278          I = IA + J - JA
00279 *
00280 *        Compute the QR factorization of the current block
00281 *        A(i:ia+m-1,j:j+jb-1)
00282 *
00283          CALL PDGEQR2( M-J+JA, JB, A, I, J, DESCA, TAU, WORK, LWORK,
00284      $                 IINFO )
00285 *
00286          IF( J+JB.LE.JA+N-1 ) THEN
00287 *
00288 *           Form the triangular factor of the block reflector
00289 *           H = H(j) H(j+1) . . . H(j+jb-1)
00290 *
00291             CALL PDLARFT( 'Forward', 'Columnwise', M-J+JA, JB, A, I, J,
00292      $                    DESCA, TAU, WORK, WORK( IPW ) )
00293 *
00294 *           Apply H' to A(i:ia+m-1,j+jb:ja+n-1) from the left
00295 *
00296             CALL PDLARFB( 'Left', 'Transpose', 'Forward', 'Columnwise',
00297      $                     M-J+JA, N-J-JB+JA, JB, A, I, J, DESCA, WORK,
00298      $                     A, I, J+JB, DESCA, WORK( IPW ) )
00299          END IF
00300 *
00301    10 CONTINUE
00302 *
00303       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP )
00304       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP )
00305 *
00306       WORK( 1 ) = DBLE( LWMIN )
00307 *
00308       RETURN
00309 *
00310 *     End of PDGEQRF
00311 *
00312       END