ScaLAPACK  2.0.2
ScaLAPACK: Scalable Linear Algebra PACKage
pzlagsy.f
Go to the documentation of this file.
00001 *
00002 *
00003       SUBROUTINE PZLAGHE( N, K, D, A, IA, JA, DESCA, ISEED, ORDER, WORK,
00004      $                    LWORK, INFO )
00005 *
00006 *
00007 *  -- ScaLAPACK routine (version 1.7) --
00008 *     University of Tennessee, Knoxville, Oak Ridge National Laboratory,
00009 *     and University of California, Berkeley.
00010 *     May 1, 1997
00011 *
00012 *     .. Scalar Arguments ..
00013       INTEGER            IA, INFO, JA, K, LWORK, N, ORDER
00014 *     ..
00015 *     .. Array Arguments ..
00016       INTEGER            DESCA( * ), ISEED( 4 )
00017       DOUBLE PRECISION   D( * )
00018       COMPLEX*16         A( * ), WORK( * )
00019 *     ..
00020 *
00021 *  Notes
00022 *  =====
00023 *
00024 *  Each global data object is described by an associated description
00025 *  vector.  This vector stores the information required to establish
00026 *  the mapping between an object element and its corresponding process
00027 *  and memory location.
00028 *
00029 *  Let A be a generic term for any 2D block cyclicly distributed array.
00030 *  Such a global array has an associated description vector DESCA.
00031 *  In the following comments, the character _ should be read as
00032 *  "of the global array".
00033 *
00034 *  NOTATION        STORED IN      EXPLANATION
00035 *  --------------- -------------- --------------------------------------
00036 *  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
00037 *                                 DTYPE_A = 1.
00038 *  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
00039 *                                 the BLACS process grid A is distribu-
00040 *                                 ted over. The context itself is glo-
00041 *                                 bal, but the handle (the integer
00042 *                                 value) may vary.
00043 *  M_A    (global) DESCA( M_ )    The number of rows in the global
00044 *                                 array A.
00045 *  N_A    (global) DESCA( N_ )    The number of columns in the global
00046 *                                 array A.
00047 *  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
00048 *                                 the rows of the array.
00049 *  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
00050 *                                 the columns of the array.
00051 *  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
00052 *                                 row of the array A is distributed.
00053 *  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
00054 *                                 first column of the array A is
00055 *                                 distributed.
00056 *  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
00057 *                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
00058 *
00059 *  Let K be the number of rows or columns of a distributed matrix,
00060 *  and assume that its process grid has dimension p x q.
00061 *  LOCr( K ) denotes the number of elements of K that a process
00062 *  would receive if K were distributed over the p processes of its
00063 *  process column.
00064 *  Similarly, LOCc( K ) denotes the number of elements of K that a
00065 *  process would receive if K were distributed over the q processes of
00066 *  its process row.
00067 *  The values of LOCr() and LOCc() may be determined via a call to the
00068 *  ScaLAPACK tool function, NUMROC:
00069 *          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
00070 *          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
00071 *  An upper bound for these quantities may be computed by:
00072 *          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
00073 *          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
00074 *
00075 *  Purpose
00076 *  =======
00077 *
00078 *  PZLAGHE generates a real Hermitian matrix A, by pre- and post-
00079 *  multiplying a real diagonal matrix D with a random orthogonal matrix:
00080 *  A = U*D*U'.
00081 *
00082 *  This is just a quick implementation which will be replaced in the
00083 *  future.  The random orthogonal matrix is computed by creating a
00084 *  random matrix and running QR on it.  This requires vastly more
00085 *  computation than necessary, but not significantly more communication
00086 *  than is used in the rest of this rouinte, and hence is not that much
00087 *  slower than an efficient solution.
00088 *
00089 *  Arguments
00090 *  =========
00091 *
00092 *  N       (global input) INTEGER
00093 *          The size of the matrix A.  N >= 0.
00094 *
00095 *  K       (global input) INTEGER
00096 *          The number of nonzero subdiagonals within the band of A.
00097 *          0 <= K <= N-1.
00098 *          ### K must be 0 or N-1, 0 < K < N-1 is not supported yet.
00099 *
00100 *  D       (global input) COMPLEX*16 array, dimension (N)
00101 *          The diagonal elements of the diagonal matrix D.
00102 *
00103 *  A       (local output) COMPLEX*16 array
00104 *          Global dimension (N, N), local dimension (NP, NQ)
00105 *          The generated n by n Hermitian matrix A (the full matrix is
00106 *          stored).
00107 *
00108 *  IA      (global input) INTEGER
00109 *          A's global row index, which points to the beginning of the
00110 *          submatrix which is to be operated on.
00111 *
00112 *  JA      (global input) INTEGER
00113 *          A's global column index, which points to the beginning of
00114 *          the submatrix which is to be operated on.
00115 *
00116 *  DESCA   (global and local input) INTEGER array of dimension DLEN_.
00117 *          The array descriptor for the distributed matrix A.
00118 *
00119 *  ISEED   (global input/output) INTEGER array, dimension (4)
00120 *          On entry, the seed of the random number generator; the array
00121 *          elements must be between 0 and 4095, and ISEED(4) must be
00122 *          odd.
00123 *          On exit, the seed is updated and will remain identical on
00124 *          all processes in the context.
00125 *
00126 *  ORDER   (global input) INTEGER
00127 *          Number of reflectors in the matrix Q
00128 *          At present, ORDER .NE. N is not supported
00129 *
00130 *  WORK    (local workspace) COMPLEX*16 array, dimension (LWORK)
00131 *
00132 *  LWORK   (local input) INTEGER dimension of WORK
00133 *        LWORK >= SIZETMS as returned by PZLASIZESEP
00134 *
00135 *
00136 *  INFO    (local output) INTEGER
00137 *          = 0:  successful exit
00138 *          < 0:  If the i-th argument is an array and the j-entry had
00139 *                an illegal value, then INFO = -(i*100+j), if the i-th
00140 *                argument is a scalar and had an illegal value, then
00141 *                INFO = -i.
00142 *
00143 *
00144 *     .. Parameters ..
00145       INTEGER            BLOCK_CYCLIC_2D, DLEN_, DTYPE_, CTXT_, M_, N_,
00146      $                   MB_, NB_, RSRC_, CSRC_, LLD_
00147       PARAMETER          ( BLOCK_CYCLIC_2D = 1, DLEN_ = 9, DTYPE_ = 1,
00148      $                   CTXT_ = 2, M_ = 3, N_ = 4, MB_ = 5, NB_ = 6,
00149      $                   RSRC_ = 7, CSRC_ = 8, LLD_ = 9 )
00150       COMPLEX*16         ZZERO
00151       PARAMETER          ( ZZERO = 0.0D+0 )
00152 *     ..
00153 *     .. Local Scalars ..
00154       INTEGER            CSRC_A, I, IACOL, IAROW, ICOFFA, II, IIROW,
00155      $                   INDAA, INDTAU, INDWORK, IPOSTPAD, IPREPAD,
00156      $                   IROFFA, ISIZEHEEVX, ISIZESUBTST, ISIZETST,
00157      $                   JJCOL, LDAA, LII, LIII, LJJ, LJJJ, LWMIN, MAXI,
00158      $                   MB_A, MYCOL, MYROW, NB_A, NP, NPCOL, NPROW, NQ,
00159      $                   RSIZECHK, RSIZEHEEVX, RSIZEQTQ, RSIZESUBTST,
00160      $                   RSIZETST, RSRC_A, SIZEHEEVX, SIZEMQRLEFT,
00161      $                   SIZEMQRRIGHT, SIZEQRF, SIZESUBTST, SIZETMS,
00162      $                   SIZETST,SIZEHEEVD, RSIZEHEEVD, ISIZEHEEVD
00163 *     ..
00164 *     .. External Subroutines ..
00165       EXTERNAL           BLACS_GRIDINFO, CHK1MAT, PXERBLA, PZGEQRF,
00166      $                   PZLASIZESEP, PZMATGEN, PZUNMQR, ZLASET
00167 *     ..
00168 *     .. External Functions ..
00169       INTEGER            INDXG2P, NUMROC
00170       EXTERNAL           INDXG2P, NUMROC
00171 *     ..
00172 *     .. Intrinsic Functions ..
00173 *
00174       INTRINSIC          MAX, MIN, MOD
00175 *     ..
00176 *     .. Executable Statements ..
00177 *       This is just to keep ftnchek happy
00178       IF( BLOCK_CYCLIC_2D*CSRC_*CTXT_*DLEN_*DTYPE_*LLD_*MB_*M_*NB_*N_*
00179      $    RSRC_.LT.0 )RETURN
00180 *
00181 *     Initialize grid information
00182 *
00183       CALL BLACS_GRIDINFO( DESCA( CTXT_ ), NPROW, NPCOL, MYROW, MYCOL )
00184 *
00185 *     Check LWORK
00186 *
00187       INFO = 0
00188       IF( NPROW.EQ.-1 ) THEN
00189          INFO = -( 700+CTXT_ )
00190       ELSE
00191          CALL CHK1MAT( N, 1, N, 1, IA, JA, DESCA, 7, INFO )
00192       END IF
00193 *
00194       LDAA = DESCA( LLD_ )
00195       MB_A = DESCA( MB_ )
00196       NB_A = DESCA( NB_ )
00197       RSRC_A = DESCA( RSRC_ )
00198       CSRC_A = DESCA( CSRC_ )
00199       IAROW = INDXG2P( IA, MB_A, MYROW, RSRC_A, NPROW )
00200       IACOL = INDXG2P( JA, NB_A, MYCOL, CSRC_A, NPCOL )
00201       IROFFA = MOD( IA-1, MB_A )
00202       ICOFFA = MOD( JA-1, NB_A )
00203       NP = NUMROC( N+IROFFA, MB_A, MYROW, IAROW, NPROW )
00204       NQ = NUMROC( N+ICOFFA, NB_A, MYCOL, IACOL, NPCOL )
00205       IPREPAD = 0
00206       IPOSTPAD = 0
00207       CALL PZLASIZESEP( DESCA, IPREPAD, IPOSTPAD, SIZEMQRLEFT,
00208      $                  SIZEMQRRIGHT, SIZEQRF, SIZETMS, RSIZEQTQ,
00209      $                  RSIZECHK, SIZEHEEVX, RSIZEHEEVX, ISIZEHEEVX,
00210      $                  SIZEHEEVD, RSIZEHEEVD, ISIZEHEEVD, 
00211      $                  SIZESUBTST, RSIZESUBTST, ISIZESUBTST, SIZETST,
00212      $                  RSIZETST, ISIZETST )
00213       LWMIN = SIZETMS
00214 *
00215 *     Test the input arguments
00216 *
00217       IF( INFO.EQ.0 ) THEN
00218          IF( K.LT.0 .OR. K.GT.N-1 ) THEN
00219             INFO = -2
00220          ELSE IF( N.NE.ORDER ) THEN
00221             INFO = -9
00222          ELSE IF( LWORK.LT.LWMIN ) THEN
00223             INFO = -11
00224          END IF
00225       END IF
00226       IF( INFO.LT.0 ) THEN
00227          CALL PXERBLA( DESCA( CTXT_ ), 'PZLAGHE', -INFO )
00228          RETURN
00229       END IF
00230 *
00231       INDAA = 1
00232       INDTAU = INDAA + LDAA*MAX( 1, NQ )
00233       INDWORK = INDTAU + MAX( 1, NQ )
00234 *
00235       IF( K.NE.0 ) THEN
00236          CALL ZLASET( 'A', LDAA, NQ, ZZERO, ZZERO, WORK( INDAA ), LDAA )
00237 *
00238 *
00239 *        Build a random matrix
00240 *
00241 *
00242          CALL PZMATGEN( DESCA( CTXT_ ), 'N', 'N', N, ORDER,
00243      $                  DESCA( MB_ ), DESCA( NB_ ), WORK( INDAA ),
00244      $                  DESCA( LLD_ ), DESCA( RSRC_ ), DESCA( CSRC_ ),
00245      $                  ISEED( 1 ), 0, NP, 0, NQ, MYROW, MYCOL, NPROW,
00246      $                  NPCOL )
00247          CALL PZGEQRF( N, ORDER, WORK( INDAA ), IA, JA, DESCA,
00248      $                 WORK( INDTAU ), WORK( INDWORK ), SIZEQRF, INFO )
00249 *
00250       END IF
00251 *
00252 *     Build a diagonal matrix A with the eigenvalues specified in D
00253 *
00254       CALL ZLASET( 'A', NP, NQ, ZZERO, ZZERO, A, DESCA( LLD_ ) )
00255 *
00256       IIROW = 0
00257       JJCOL = 0
00258       LII = 1
00259       LJJ = 1
00260 *
00261       DO 20 II = 1, N, DESCA( MB_ )
00262          MAXI = MIN( N, II+DESCA( MB_ )-1 )
00263          IF( ( MYROW.EQ.IIROW ) .AND. ( MYCOL.EQ.JJCOL ) ) THEN
00264             LIII = LII
00265             LJJJ = LJJ
00266             DO 10 I = II, MAXI
00267                A( LIII+( LJJJ-1 )*DESCA( LLD_ ) ) = D( I )
00268                LIII = LIII + 1
00269                LJJJ = LJJJ + 1
00270    10       CONTINUE
00271          END IF
00272          IF( MYROW.EQ.IIROW )
00273      $      LII = LII + DESCA( MB_ )
00274          IF( MYCOL.EQ.JJCOL )
00275      $      LJJ = LJJ + DESCA( MB_ )
00276          IIROW = MOD( IIROW+1, NPROW )
00277          JJCOL = MOD( JJCOL+1, NPCOL )
00278    20 CONTINUE
00279 *
00280 *     A = Q * A
00281 *
00282       IF( K.NE.0 ) THEN
00283 *
00284          CALL PZUNMQR( 'L', 'Conjugate transpose', N, N, ORDER,
00285      $                 WORK( INDAA ), IA, JA, DESCA, WORK( INDTAU ), A,
00286      $                 IA, JA, DESCA, WORK( INDWORK ), SIZEMQRLEFT,
00287      $                 INFO )
00288 *
00289 *
00290 *        A = A * Q'
00291 *
00292 *
00293          CALL PZUNMQR( 'R', 'N', N, N, ORDER, WORK( INDAA ), IA, JA,
00294      $                 DESCA, WORK( INDTAU ), A, IA, JA, DESCA,
00295      $                 WORK( INDWORK ), SIZEMQRRIGHT, INFO )
00296 *
00297       END IF
00298 *
00299 *     End of PZLAGHE
00300 *
00301       END