ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pzgerq2.f
Go to the documentation of this file.
00001       SUBROUTINE PZGERQ2( 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       COMPLEX*16         A( * ), TAU( * ), WORK( * )
00015 *     ..
00016 *
00017 *  Purpose
00018 *  =======
00019 *
00020 *  PZGERQ2 computes a RQ factorization of a complex distributed M-by-N
00021 *  matrix sub( A ) = A(IA:IA+M-1,JA:JA+N-1) = R * Q.
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) COMPLEX*16 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, if M <= N, the
00092 *          upper triangle of A( IA:IA+M-1, JA+N-M:JA+N-1 ) contains the
00093 *          M by M upper triangular matrix R; if M >= N, the elements on
00094 *          and above the (M-N)-th subdiagonal contain the M by N upper
00095 *          trapezoidal matrix R; the remaining elements, with the array
00096 *          TAU, represent the unitary matrix Q as a product of
00097 *          elementary reflectors (see Further Details).
00098 *
00099 *  IA      (global input) INTEGER
00100 *          The row index in the global array A indicating the first
00101 *          row of sub( A ).
00102 *
00103 *  JA      (global input) INTEGER
00104 *          The column index in the global array A indicating the
00105 *          first column of sub( A ).
00106 *
00107 *  DESCA   (global and local input) INTEGER array of dimension DLEN_.
00108 *          The array descriptor for the distributed matrix A.
00109 *
00110 *  TAU     (local output) COMPLEX*16, array, dimension LOCr(IA+M-1)
00111 *          This array contains the scalar factors of the elementary
00112 *          reflectors. TAU is tied to the distributed matrix A.
00113 *
00114 *  WORK    (local workspace/local output) COMPLEX*16 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 >= Nq0 + MAX( 1, Mp0 ), 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    (local 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(ia)' H(ia+1)' . . . H(ia+k-1)', where k = min(m,n).
00152 *
00153 *  Each H(i) has the form
00154 *
00155 *     H(i) = I - tau * v * v'
00156 *
00157 *  where tau is a complex scalar, and v is a complex vector with
00158 *  v(n-k+i+1:n) = 0 and v(n-k+i) = 1; conjg(v(1:n-k+i-1)) is stored on
00159 *  exit in A(ia+m-k+i-1,ja:ja+n-k+i-2), and tau in TAU(ia+m-k+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       COMPLEX*16         ONE
00170       PARAMETER          ( ONE = 1.0D+0 )
00171 *     ..
00172 *     .. Local Scalars ..
00173       LOGICAL            LQUERY
00174       CHARACTER          COLBTOP, ROWBTOP
00175       INTEGER            IACOL, IAROW, I, ICTXT, J, K, LWMIN, MP, MYCOL,
00176      $                   MYROW, NPCOL, NPROW, NQ
00177       COMPLEX*16         AII
00178 *     ..
00179 *     .. External Subroutines ..
00180       EXTERNAL           BLACS_ABORT, BLACS_GRIDINFO, CHK1MAT,
00181      $                   PB_TOPGET, PB_TOPSET, PXERBLA, PZELSET,
00182      $                   PZLACGV, PZLARF, PZLARFG
00183 *     ..
00184 *     .. External Functions ..
00185       INTEGER            INDXG2P, NUMROC
00186       EXTERNAL           INDXG2P, NUMROC
00187 *     ..
00188 *     .. Intrinsic Functions ..
00189       INTRINSIC          DBLE, DCMPLX, MAX, 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             IAROW = INDXG2P( IA, DESCA( MB_ ), MYROW, DESCA( RSRC_ ),
00207      $                       NPROW )
00208             IACOL = INDXG2P( JA, DESCA( NB_ ), MYCOL, DESCA( CSRC_ ),
00209      $                       NPCOL )
00210             MP = NUMROC( M+MOD( IA-1, DESCA( MB_ ) ), DESCA( MB_ ),
00211      $                   MYROW, IAROW, NPROW )
00212             NQ = NUMROC( N+MOD( JA-1, DESCA( NB_ ) ), DESCA( NB_ ),
00213      $                   MYCOL, IACOL, NPCOL )
00214             LWMIN = NQ + MAX( 1, MP )
00215 *
00216             WORK( 1 ) = DCMPLX( DBLE( LWMIN ) )
00217             LQUERY = ( LWORK.EQ.-1 )
00218             IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY )
00219      $         INFO = -9
00220          END IF
00221       END IF
00222 *
00223       IF( INFO.NE.0 ) THEN
00224          CALL PXERBLA( ICTXT, 'PZGERQ2', -INFO )
00225          CALL BLACS_ABORT( ICTXT, 1 )
00226          RETURN
00227       ELSE IF( LQUERY ) THEN
00228          RETURN
00229       END IF
00230 *
00231 *     Quick return if possible
00232 *
00233       IF( M.EQ.0 .OR. N.EQ.0 )
00234      $   RETURN
00235 *
00236       CALL PB_TOPGET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP )
00237       CALL PB_TOPGET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP )
00238       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', ' ' )
00239       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', 'D-ring' )
00240 *
00241       K = MIN( M, N )
00242       DO 10 I = IA+K-1, IA, -1
00243          J = JA + I - IA
00244 *
00245 *        Generate elementary reflector H(i) to annihilate
00246 *        A(i+m-k,ja:j+n-k-1)
00247 *
00248          CALL PZLACGV( N-K+J-JA+1, A, I+M-K, JA, DESCA, DESCA( M_ ) )
00249          CALL PZLARFG( N-K+J-JA+1, AII, I+M-K, J+N-K, A, I+M-K, JA,
00250      $                 DESCA, DESCA( M_ ), TAU )
00251 *
00252 *        Apply H(i) to A(ia:i+m-k-1,ja:j+n-k) from the right
00253 *
00254          CALL PZELSET( A, I+M-K, J+N-K, DESCA, ONE )
00255          CALL PZLARF( 'Right', M-K+I-IA, N-K+J-JA+1, A, M-K+I, JA,
00256      $                DESCA, DESCA( M_ ), TAU, A, IA, JA, DESCA, WORK )
00257          CALL PZELSET( A, I+M-K, J+N-K, DESCA, AII )
00258          CALL PZLACGV( N-K+J-JA+1, A, I+M-K, JA, DESCA, DESCA( M_ ) )
00259 *
00260    10 CONTINUE
00261 *
00262       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Rowwise', ROWBTOP )
00263       CALL PB_TOPSET( ICTXT, 'Broadcast', 'Columnwise', COLBTOP )
00264 *
00265       WORK( 1 ) = DCMPLX( DBLE( LWMIN ) )
00266 *
00267       RETURN
00268 *
00269 *     End of PZGERQ2
00270 *
00271       END