ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pchetrd.f
Go to the documentation of this file.
00001       SUBROUTINE PCHETRD( UPLO, N, A, IA, JA, DESCA, D, E, TAU, WORK,
00002      $                    LWORK, 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 1, 1997
00008 *
00009 *     .. Scalar Arguments ..
00010       CHARACTER          UPLO
00011       INTEGER            IA, INFO, JA, LWORK, N
00012 *     ..
00013 *     .. Array Arguments ..
00014       INTEGER            DESCA( * )
00015       REAL               D( * ), E( * )
00016       COMPLEX            A( * ), TAU( * ), WORK( * )
00017 *     ..
00018 *
00019 *  Purpose
00020 *  =======
00021 *
00022 *  PCHETRD reduces a complex Hermitian matrix sub( A ) to Hermitian
00023 *  tridiagonal form T by an unitary similarity transformation:
00024 *  Q' * sub( A ) * Q = T, where sub( A ) = A(IA:IA+N-1,JA:JA+N-1).
00025 *
00026 *  Notes
00027 *  =====
00028 *
00029 *  Each global data object is described by an associated description
00030 *  vector.  This vector stores the information required to establish
00031 *  the mapping between an object element and its corresponding process
00032 *  and memory location.
00033 *
00034 *  Let A be a generic term for any 2D block cyclicly distributed array.
00035 *  Such a global array has an associated description vector DESCA.
00036 *  In the following comments, the character _ should be read as
00037 *  "of the global array".
00038 *
00039 *  NOTATION        STORED IN      EXPLANATION
00040 *  --------------- -------------- --------------------------------------
00041 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00042 *                                 DTYPE_A = 1.
00043 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00044 *                                 the BLACS process grid A is distribu-
00045 *                                 ted over. The context itself is glo-
00046 *                                 bal, but the handle (the integer
00047 *                                 value) may vary.
00048 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00049 *                                 array A.
00050 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00051 *                                 array A.
00052 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00053 *                                 the rows of the array.
00054 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00055 *                                 the columns of the array.
00056 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00057 *                                 row of the array A is distributed.
00058 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00059 *                                 first column of the array A is
00060 *                                 distributed.
00061 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00062 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00063 *
00064 *  Let K be the number of rows or columns of a distributed matrix,
00065 *  and assume that its process grid has dimension p x q.
00066 *  LOCr( K ) denotes the number of elements of K that a process
00067 *  would receive if K were distributed over the p processes of its
00068 *  process column.
00069 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00070 *  process would receive if K were distributed over the q processes of
00071 *  its process row.
00072 *  The values of LOCr() and LOCc() may be determined via a call to the
00073 *  ScaLAPACK tool function, NUMROC:
00074 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00075 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00076 *  An upper bound for these quantities may be computed by:
00077 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00078 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00079 *
00080 *  Arguments
00081 *  =========
00082 *
00083 *  UPLO    (global input) CHARACTER
00084 *          Specifies whether the upper or lower triangular part of the
00085 *          Hermitian matrix sub( A ) is stored:
00086 *          = 'U':  Upper triangular
00087 *          = 'L':  Lower triangular
00088 *
00089 *  N       (global input) INTEGER
00090 *          The number of rows and columns to be operated on, i.e. the
00091 *          order of the distributed submatrix sub( A ). N >= 0.
00092 *
00093 *  A       (local input/local output) COMPLEX pointer into the
00094 *          local memory to an array of dimension (LLD_A,LOCc(JA+N-1)).
00095 *          On entry, this array contains the local pieces of the
00096 *          Hermitian distributed matrix sub( A ).  If UPLO = 'U', the
00097 *          leading N-by-N upper triangular part of sub( A ) contains
00098 *          the upper triangular part of the matrix, and its strictly
00099 *          lower triangular part is not referenced. If UPLO = 'L', the
00100 *          leading N-by-N lower triangular part of sub( A ) contains the
00101 *          lower triangular part of the matrix, and its strictly upper
00102 *          triangular part is not referenced. On exit, if UPLO = 'U',
00103 *          the diagonal and first superdiagonal of sub( A ) are over-
00104 *          written by the corresponding elements of the tridiagonal
00105 *          matrix T, and the elements above the first superdiagonal,
00106 *          with the array TAU, represent the unitary matrix Q as a
00107 *          product of elementary reflectors; if UPLO = 'L', the diagonal
00108 *          and first subdiagonal of sub( A ) are overwritten by the
00109 *          corresponding elements of the tridiagonal matrix T, and the
00110 *          elements below the first subdiagonal, with the array TAU,
00111 *          represent the unitary matrix Q as a product of elementary
00112 *          reflectors. See Further Details.
00113 *
00114 *  IA      (global input) INTEGER
00115 *          The row index in the global array A indicating the first
00116 *          row of sub( A ).
00117 *
00118 *  JA      (global input) INTEGER
00119 *          The column index in the global array A indicating the
00120 *          first column of sub( A ).
00121 *
00122 *  DESCA   (global and local input) INTEGER array of dimension DLEN_.
00123 *          The array descriptor for the distributed matrix A.
00124 *
00125 *  D       (local output) REAL array, dimension LOCc(JA+N-1)
00126 *          The diagonal elements of the tridiagonal matrix T:
00127 *          D(i) = A(i,i). D is tied to the distributed matrix A.
00128 *
00129 *  E       (local output) REAL array, dimension LOCc(JA+N-1)
00130 *          if UPLO = 'U', LOCc(JA+N-2) otherwise. The off-diagonal
00131 *          elements of the tridiagonal matrix T: E(i) = A(i,i+1) if
00132 *          UPLO = 'U', E(i) = A(i+1,i) if UPLO = 'L'. E is tied to the
00133 *          distributed matrix A.
00134 *
00135 *  TAU     (local output) COMPLEX, array, dimension
00136 *          LOCc(JA+N-1). This array contains the scalar factors TAU of
00137 *          the elementary reflectors. TAU is tied to the distributed
00138 *          matrix A.
00139 *
00140 *  WORK    (local workspace/local output) COMPLEX array,
00141 *                                                  dimension (LWORK)
00142 *          On exit, WORK( 1 ) returns the minimal and optimal LWORK.
00143 *
00144 *  LWORK   (local or global input) INTEGER
00145 *          The dimension of the array WORK.
00146 *          LWORK is local input and must be at least
00147 *          LWORK >= MAX( NB * ( NP +1 ), 3 * NB )
00148 *
00149 *          where NB = MB_A = NB_A,
00150 *          NP = NUMROC( N, NB, MYROW, IAROW, NPROW ),
00151 *          IAROW = INDXG2P( IA, NB, MYROW, RSRC_A, NPROW ).
00152 *
00153 *          INDXG2P and NUMROC are ScaLAPACK tool functions;
00154 *          MYROW, MYCOL, NPROW and NPCOL can be determined by calling
00155 *          the subroutine BLACS_GRIDINFO.
00156 *
00157 *          If LWORK = -1, then LWORK is global input and a workspace
00158 *          query is assumed; the routine only calculates the minimum
00159 *          and optimal size for all work arrays. Each of these
00160 *          values is returned in the first entry of the corresponding
00161 *          work array, and no error message is issued by PXERBLA.
00162 *
00163 *  INFO    (global output) INTEGER
00164 *          = 0:  successful exit
00165 *          < 0:  If the i-th argument is an array and the j-entry had
00166 *                an illegal value, then INFO = -(i*100+j), if the i-th
00167 *                argument is a scalar and had an illegal value, then
00168 *                INFO = -i.
00169 *
00170 *  Further Details
00171 *  ===============
00172 *
00173 *  If UPLO = 'U', the matrix Q is represented as a product of elementary
00174 *  reflectors
00175 *
00176 *     Q = H(n-1) . . . H(2) H(1).
00177 *
00178 *  Each H(i) has the form
00179 *
00180 *     H(i) = I - tau * v * v'
00181 *
00182 *  where tau is a complex scalar, and v is a complex vector with
00183 *  v(i+1:n) = 0 and v(i) = 1; v(1:i-1) is stored on exit in
00184 *  A(ia:ia+i-2,ja+i), and tau in TAU(ja+i-1).
00185 *
00186 *  If UPLO = 'L', the matrix Q is represented as a product of elementary
00187 *  reflectors
00188 *
00189 *     Q = H(1) H(2) . . . H(n-1).
00190 *
00191 *  Each H(i) has the form
00192 *
00193 *     H(i) = I - tau * v * v'
00194 *
00195 *  where tau is a complex scalar, and v is a complex vector with
00196 *  v(1:i) = 0 and v(i+1) = 1; v(i+2:n) is stored on exit in
00197 *  A(ia+i+1:ia+n-1,ja+i-1), and tau in TAU(ja+i-1).
00198 *
00199 *  The contents of sub( A ) on exit are illustrated by the following
00200 *  examples with n = 5:
00201 *
00202 *  if UPLO = 'U':                       if UPLO = 'L':
00203 *
00204 *    (  d   e   v2  v3  v4 )              (  d                  )
00205 *    (      d   e   v3  v4 )              (  e   d              )
00206 *    (          d   e   v4 )              (  v1  e   d          )
00207 *    (              d   e  )              (  v1  v2  e   d      )
00208 *    (                  d  )              (  v1  v2  v3  e   d  )
00209 *
00210 *  where d and e denote diagonal and off-diagonal elements of T, and vi
00211 *  denotes an element of the vector defining H(i).
00212 *
00213 *  Alignment requirements
00214 *  ======================
00215 *
00216 *  The distributed submatrix sub( A ) must verify some alignment proper-
00217 *  ties, namely the following expression should be true:
00218 *  ( MB_A.EQ.NB_A .AND. IROFFA.EQ.ICOFFA .AND. IROFFA.EQ.0 ) with
00219 *  IROFFA = MOD( IA-1, MB_A ) and ICOFFA = MOD( JA-1, NB_A ).
00220 *
00221 *  =====================================================================
00222 *
00223 *     .. Parameters ..
00224       INTEGER            BLOCK_CYCLIC_2D, CSRC_, CTXT_, DLEN_, DTYPE_,
00225      $                   LLD_, MB_, M_, NB_, N_, RSRC_
00226       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00227      $                     CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00228      $                     RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00229       REAL               ONE
00230       PARAMETER          ( ONE = 1.0E+0 )
00231       COMPLEX            CONE
00232       PARAMETER          ( CONE = ( 1.0E+0, 0.0E+0 ) )
00233 *     ..
00234 *     .. Local Scalars ..
00235       LOGICAL            LQUERY, UPPER
00236       CHARACTER          COLCTOP, ROWCTOP
00237       INTEGER            I, IACOL, IAROW, ICOFFA, ICTXT, IINFO, IPW,
00238      $                   IROFFA, J, JB, JX, K, KK, LWMIN, MYCOL, MYROW,
00239      $                   NB, NP, NPCOL, NPROW, NQ
00240 *     ..
00241 *     .. Local Arrays ..
00242       INTEGER            DESCW( DLEN_ ), IDUM1( 2 ), IDUM2( 2 )
00243 *     ..
00244 *     .. External Subroutines ..
00245       EXTERNAL           BLACS_GRIDINFO, CHK1MAT, DESCSET, PCHER2K,
00246      $                   PCHETD2, PCHK1MAT, PCLATRD, PB_TOPGET,
00247      $                   PB_TOPSET, PXERBLA
00248 *     ..
00249 *     .. External Functions ..
00250       LOGICAL            LSAME
00251       INTEGER            INDXG2L, INDXG2P, NUMROC
00252       EXTERNAL           LSAME, INDXG2L, INDXG2P, NUMROC
00253 *     ..
00254 *     .. Intrinsic Functions ..
00255       INTRINSIC          CMPLX, ICHAR, MAX, MIN, MOD, REAL
00256 *     ..
00257 *     .. Executable Statements ..
00258 *
00259 *     Get grid parameters
00260 *
00261       ICTXT = DESCA( CTXT_ )
00262       CALL BLACS_GRIDINFO( ICTXT, NPROW, NPCOL, MYROW, MYCOL )
00263 *
00264 *     Test the input parameters
00265 *
00266       INFO = 0
00267       IF( NPROW.EQ.-1 ) THEN
00268          INFO = -(600+CTXT_)
00269       ELSE
00270          CALL CHK1MAT( N, 2, N, 2, IA, JA, DESCA, 6, INFO )
00271          UPPER = LSAME( UPLO, 'U' )
00272          IF( INFO.EQ.0 ) THEN
00273             NB = DESCA( NB_ )
00274             IROFFA = MOD( IA-1, DESCA( MB_ ) )
00275             ICOFFA = MOD( JA-1, DESCA( NB_ ) )
00276             IAROW = INDXG2P( IA, NB, MYROW, DESCA( RSRC_ ), NPROW )
00277             IACOL = INDXG2P( JA, NB, MYCOL, DESCA( CSRC_ ), NPCOL )
00278             NP = NUMROC( N, NB, MYROW, IAROW, NPROW )
00279             NQ = MAX( 1, NUMROC( N+JA-1, NB, MYCOL, DESCA( CSRC_ ),
00280      $                NPCOL ) )
00281             LWMIN = MAX( (NP+1)*NB, 3*NB )
00282 *
00283             WORK( 1 ) = CMPLX( REAL( LWMIN ) )
00284             LQUERY = ( LWORK.EQ.-1 )
00285             IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
00286                INFO = -1
00287             ELSE IF( IROFFA.NE.ICOFFA .OR. ICOFFA.NE.0 ) THEN
00288                INFO = -5
00289             ELSE IF( DESCA( MB_ ).NE.DESCA( NB_ ) ) THEN
00290                INFO = -(600+NB_)
00291             ELSE IF( LWORK.LT.LWMIN .AND. .NOT.LQUERY ) THEN
00292                INFO = -11
00293             END IF
00294          END IF
00295          IF( UPPER ) THEN
00296             IDUM1( 1 ) = ICHAR( 'U' )
00297          ELSE
00298             IDUM1( 1 ) = ICHAR( 'L' )
00299          END IF
00300          IDUM2( 1 ) = 1
00301          IF( LWORK.EQ.-1 ) THEN
00302             IDUM1( 2 ) = -1
00303          ELSE
00304             IDUM1( 2 ) = 1
00305          END IF
00306          IDUM2( 2 ) = 11
00307          CALL PCHK1MAT( N, 2, N, 2, IA, JA, DESCA, 6, 2, IDUM1, IDUM2,
00308      $                  INFO )
00309       END IF
00310 *
00311       IF( INFO.NE.0 ) THEN
00312          CALL PXERBLA( ICTXT, 'PCHETRD', -INFO )
00313          RETURN
00314       ELSE IF( LQUERY ) THEN
00315          RETURN
00316       END IF
00317 *
00318 *     Quick return if possible
00319 *
00320       IF( N.EQ.0 )
00321      $   RETURN
00322 *
00323       CALL PB_TOPGET( ICTXT, 'Combine', 'Columnwise', COLCTOP )
00324       CALL PB_TOPGET( ICTXT, 'Combine', 'Rowwise',    ROWCTOP )
00325       CALL PB_TOPSET( ICTXT, 'Combine', 'Columnwise', '1-tree' )
00326       CALL PB_TOPSET( ICTXT, 'Combine', 'Rowwise',    '1-tree' )
00327 *
00328       IPW = NP * NB + 1
00329 *
00330       IF( UPPER ) THEN
00331 *
00332 *        Reduce the upper triangle of sub( A ).
00333 *
00334          KK = MOD( JA+N-1, NB )
00335          IF( KK.EQ.0 )
00336      $      KK = NB
00337          CALL DESCSET( DESCW, N, NB, NB, NB, IAROW, INDXG2P( JA+N-KK,
00338      $                 NB, MYCOL, DESCA( CSRC_ ), NPCOL ), ICTXT,
00339      $                 MAX( 1, NP ) )
00340 *
00341          DO 10 K = N-KK+1, NB+1, -NB
00342             JB = MIN( N-K+1, NB )
00343             I = IA + K - 1
00344             J = JA + K - 1
00345 *
00346 *           Reduce columns I:I+NB-1 to tridiagonal form and form
00347 *           the matrix W which is needed to update the unreduced part of
00348 *           the matrix
00349 *
00350             CALL PCLATRD( UPLO, K+JB-1, JB, A, IA, JA, DESCA, D, E, TAU,
00351      $                    WORK, 1, 1, DESCW, WORK( IPW ) )
00352 *
00353 *           Update the unreduced submatrix A(IA:I-1,JA:J-1), using an
00354 *           update of the form:
00355 *           A(IA:I-1,JA:J-1) := A(IA:I-1,JA:J-1) - V*W' - W*V'
00356 *
00357             CALL PCHER2K( UPLO, 'No transpose', K-1, JB, -CONE, A, IA,
00358      $                    J, DESCA, WORK, 1, 1, DESCW, ONE, A, IA, JA,
00359      $                    DESCA )
00360 *
00361 *           Copy last superdiagonal element back into sub( A )
00362 *
00363             JX = MIN( INDXG2L( J, NB, 0, IACOL, NPCOL ), NQ )
00364             CALL PCELSET( A, I-1, J, DESCA, CMPLX( E( JX ) ) )
00365 *
00366             DESCW( CSRC_ ) = MOD( DESCW( CSRC_ ) + NPCOL - 1, NPCOL )
00367 *
00368    10    CONTINUE
00369 *
00370 *        Use unblocked code to reduce the last or only block
00371 *
00372          CALL PCHETD2( UPLO, MIN( N, NB ), A, IA, JA, DESCA, D, E,
00373      $                 TAU, WORK, LWORK, IINFO )
00374 *
00375       ELSE
00376 *
00377 *        Reduce the lower triangle of sub( A )
00378 *
00379          KK = MOD( JA+N-1, NB )
00380          IF( KK.EQ.0 )
00381      $      KK = NB
00382          CALL DESCSET( DESCW, N, NB, NB, NB, IAROW, IACOL, ICTXT,
00383      $                 MAX( 1, NP ) )
00384 *
00385          DO 20 K = 1, N-NB, NB
00386             I = IA + K - 1
00387             J = JA + K - 1
00388 *
00389 *           Reduce columns I:I+NB-1 to tridiagonal form and form
00390 *           the matrix W which is needed to update the unreduced part
00391 *           of the matrix
00392 *
00393             CALL PCLATRD( UPLO, N-K+1, NB, A, I, J, DESCA, D, E, TAU,
00394      $                    WORK, K, 1, DESCW, WORK( IPW ) )
00395 *
00396 *           Update the unreduced submatrix A(I+NB:IA+N-1,I+NB:IA+N-1),
00397 *           using an update of the form: A(I+NB:IA+N-1,I+NB:IA+N-1) :=
00398 *           A(I+NB:IA+N-1,I+NB:IA+N-1) - V*W' - W*V'
00399 *
00400             CALL PCHER2K( UPLO, 'No transpose', N-K-NB+1, NB, -CONE, A,
00401      $                    I+NB, J, DESCA, WORK, K+NB, 1, DESCW, ONE, A,
00402      $                    I+NB, J+NB, DESCA )
00403 *
00404 *           Copy last subdiagonal element back into sub( A )
00405 *
00406             JX = MIN( INDXG2L( J+NB-1, NB, 0, IACOL, NPCOL ), NQ )
00407             CALL PCELSET( A, I+NB, J+NB-1, DESCA, CMPLX( E( JX ) ) )
00408 *
00409             DESCW( CSRC_ ) = MOD( DESCW( CSRC_ ) + 1, NPCOL )
00410 *
00411    20    CONTINUE
00412 *
00413 *        Use unblocked code to reduce the last or only block
00414 *
00415          CALL PCHETD2( UPLO, KK, A, IA+K-1, JA+K-1, DESCA, D, E,
00416      $                 TAU, WORK, LWORK, IINFO )
00417       END IF
00418 *
00419       CALL PB_TOPSET( ICTXT, 'Combine', 'Columnwise', COLCTOP )
00420       CALL PB_TOPSET( ICTXT, 'Combine', 'Rowwise',    ROWCTOP )
00421 *
00422       WORK( 1 ) = CMPLX( REAL( LWMIN ) )
00423 *
00424       RETURN
00425 *
00426 *     End of PCHETRD
00427 *
00428       END