Routine: PDSYEVX()  File: SRC\pdsyevx.f

 
 
# lines: 975
  # code: 975
  # comment: 0
  # blank:0
# Variables:121
# Callers:1
# Callings:9
# Words:521
# Keywords:321
 

 

..
     .. Array Arguments ..
     ..
  Purpose
  =======
  PDSYEVX computes selected eigenvalues and, optionally, eigenvectors
  of a real symmetric matrix A by calling the recommended sequence
  of ScaLAPACK routines.  Eigenvalues/vectors can be selected by
  specifying a range of values or a range of indices for the desired
  eigenvalues.
  Notes
  =====
  Each global data object is described by an associated description
  vector.  This vector stores the information required to establish
  the mapping between an object element and its corresponding process
  and memory location.
  Let A be a generic term for any 2D block cyclicly distributed array.
  Such a global array has an associated description vector DESCA.
  In the following comments, the character _ should be read as
  "of the global array".
  NOTATION        STORED IN      EXPLANATION
  --------------- -------------- --------------------------------------
  DTYPE_A(global) DESCA( DTYPE_ )The descriptor type.  In this case,
                                 DTYPE_A = 1.
  CTXT_A (global) DESCA( CTXT_ ) The BLACS context handle, indicating
                                 the BLACS process grid A is distribu-
                                 ted over. The context itself is glo-
                                 bal, but the handle (the integer
                                 value) may vary.
  M_A    (global) DESCA( M_ )    The number of rows in the global
                                 array A.
  N_A    (global) DESCA( N_ )    The number of columns in the global
                                 array A.
  MB_A   (global) DESCA( MB_ )   The blocking factor used to distribute
                                 the rows of the array.
  NB_A   (global) DESCA( NB_ )   The blocking factor used to distribute
                                 the columns of the array.
  RSRC_A (global) DESCA( RSRC_ ) The process row over which the first
                                 row of the array A is distributed.
  CSRC_A (global) DESCA( CSRC_ ) The process column over which the
                                 first column of the array A is
                                 distributed.
  LLD_A  (local)  DESCA( LLD_ )  The leading dimension of the local
                                 array.  LLD_A >= MAX(1,LOCr(M_A)).
  Let K be the number of rows or columns of a distributed matrix,
  and assume that its process grid has dimension p x q.
  LOCr( K ) denotes the number of elements of K that a process
  would receive if K were distributed over the p processes of its
  process column.
  Similarly, LOCc( K ) denotes the number of elements of K that a
  process would receive if K were distributed over the q processes of
  its process row.
  The values of LOCr() and LOCc() may be determined via a call to the
  ScaLAPACK tool function, NUMROC:
          LOCr( M ) = NUMROC( M, MB_A, MYROW, RSRC_A, NPROW ),
          LOCc( N ) = NUMROC( N, NB_A, MYCOL, CSRC_A, NPCOL ).
  An upper bound for these quantities may be computed by:
          LOCr( M ) <= ceil( ceil(M/MB_A)/NPROW )*MB_A
          LOCc( N ) <= ceil( ceil(N/NB_A)/NPCOL )*NB_A
  PDSYEVX assumes IEEE 754 standard compliant arithmetic.  To port
  to a system which does not have IEEE 754 arithmetic, modify
  the appropriate SLmake.inc file to include the compiler switch
  -DNO_IEEE.  This switch only affects the compilation of pdlaiect.c.
  Arguments
  =========
     NP = the number of rows local to a given process.
     NQ = the number of columns local to a given process.
  JOBZ    (global input) CHARACTER*1
          Specifies whether or not to compute the eigenvectors:
          = 'N':  Compute eigenvalues only.
          = 'V':  Compute eigenvalues and eigenvectors.
  RANGE   (global input) CHARACTER*1
          = 'A': all eigenvalues will be found.
          = 'V': all eigenvalues in the interval [VL,VU] will be found.
          = 'I': the IL-th through IU-th eigenvalues will be found.
  UPLO    (global input) CHARACTER*1
          Specifies whether the upper or lower triangular part of the
          symmetric matrix A is stored:
          = 'U':  Upper triangular
          = 'L':  Lower triangular
  N       (global input) INTEGER
          The number of rows and columns of the matrix A.  N >= 0.
  A       (local input/workspace) block cyclic DOUBLE PRECISION array,
          global dimension (N, N),
          local dimension ( LLD_A, LOCc(JA+N-1) )
          On entry, the symmetric matrix A.  If UPLO = 'U', only the
          upper triangular part of A is used to define the elements of
          the symmetric matrix.  If UPLO = 'L', only the lower
          triangular part of A is used to define the elements of the
          symmetric matrix.
          On exit, the lower triangle (if UPLO='L') or the upper
          triangle (if UPLO='U') of A, including the diagonal, is
          destroyed.
  IA      (global input) INTEGER
          A's global row index, which points to the beginning of the
          submatrix which is to be operated on.
  JA      (global input) INTEGER
          A's global column index, which points to the beginning of
          the submatrix which is to be operated on.
  DESCA   (global and local input) INTEGER array of dimension DLEN_.
          The array descriptor for the distributed matrix A.
          If DESCA( CTXT_ ) is incorrect, PDSYEVX cannot guarantee
          correct error reporting.
  VL      (global input) DOUBLE PRECISION
          If RANGE='V', the lower bound of the interval to be searched
          for eigenvalues.  Not referenced if RANGE = 'A' or 'I'.
  VU      (global input) DOUBLE PRECISION
          If RANGE='V', the upper bound of the interval to be searched
          for eigenvalues.  Not referenced if RANGE = 'A' or 'I'.
  IL      (global input) INTEGER
          If RANGE='I', the index (from smallest to largest) of the
          smallest eigenvalue to be returned.  IL >= 1.
          Not referenced if RANGE = 'A' or 'V'.
  IU      (global input) INTEGER
          If RANGE='I', the index (from smallest to largest) of the
          largest eigenvalue to be returned.  min(IL,N) <= IU <= N.
          Not referenced if RANGE = 'A' or 'V'.
  ABSTOL  (global input) DOUBLE PRECISION
          If JOBZ='V', setting ABSTOL to PDLAMCH( CONTEXT, 'U') yields
          the most orthogonal eigenvectors.
          The absolute error tolerance for the eigenvalues.
          An approximate eigenvalue is accepted as converged
          when it is determined to lie in an interval [a,b]
          of width less than or equal to
                  ABSTOL + EPS *   max( |a|,|b| ) ,
          where EPS is the machine precision.  If ABSTOL is less than
          or equal to zero, then EPS*norm(T) will be used in its place,
          where norm(T) is the 1-norm of the tridiagonal matrix
          obtained by reducing A to tridiagonal form.
          Eigenvalues will be computed most accurately when ABSTOL is
          set to twice the underflow threshold 2*PDLAMCH('S') not zero.
          If this routine returns with ((MOD(INFO,2).NE.0) .OR.
          (MOD(INFO/8,2).NE.0)), indicating that some eigenvalues or
          eigenvectors did not converge, try setting ABSTOL to
          2*PDLAMCH('S').
          See "Computing Small Singular Values of Bidiagonal Matrices
          with Guaranteed High Relative Accuracy," by Demmel and
          Kahan, LAPACK Working Note #3.
          See "On the correctness of Parallel Bisection in Floating
          Point" by Demmel, Dhillon and Ren, LAPACK Working Note #70
  M       (global output) INTEGER
          Total number of eigenvalues found.  0 <= M <= N.
  NZ      (global output) INTEGER
          Total number of eigenvectors computed.  0 <= NZ <= M.
          The number of columns of Z that are filled.
          If JOBZ .NE. 'V', NZ is not referenced.
          If JOBZ .EQ. 'V', NZ = M unless the user supplies
          insufficient space and PDSYEVX is not able to detect this
          before beginning computation.  To get all the eigenvectors
          requested, the user must supply both sufficient
          space to hold the eigenvectors in Z (M .LE. DESCZ(N_))
          and sufficient workspace to compute them.  (See LWORK below.)
          PDSYEVX is always able to detect insufficient space without
          computation unless RANGE .EQ. 'V'.
  W       (global output) DOUBLE PRECISION array, dimension (N)
          On normal exit, the first M entries contain the selected
          eigenvalues in ascending order.
  ORFAC   (global input) DOUBLE PRECISION
          Specifies which eigenvectors should be reorthogonalized.
          Eigenvectors that correspond to eigenvalues which are within
          tol=ORFAC*norm(A) of each other are to be reorthogonalized.
          However, if the workspace is insufficient (see LWORK),
          tol may be decreased until all eigenvectors to be
          reorthogonalized can be stored in one process.
          No reorthogonalization will be done if ORFAC equals zero.
          A default value of 10^-3 is used if ORFAC is negative.
          ORFAC should be identical on all processes.
  Z       (local output) DOUBLE PRECISION array,
          global dimension (N, N),
          local dimension ( LLD_Z, LOCc(JZ+N-1) )
          If JOBZ = 'V', then on normal exit the first M columns of Z
          contain the orthonormal eigenvectors of the matrix
          corresponding to the selected eigenvalues.  If an eigenvector
          fails to converge, then that column of Z contains the latest
          approximation to the eigenvector, and the index of the
          eigenvector is returned in IFAIL.
          If JOBZ = 'N', then Z is not referenced.
  IZ      (global input) INTEGER
          Z's global row index, which points to the beginning of the
          submatrix which is to be operated on.
  JZ      (global input) INTEGER
          Z's global column index, which points to the beginning of
          the submatrix which is to be operated on.
  DESCZ   (global and local input) INTEGER array of dimension DLEN_.
          The array descriptor for the distributed matrix Z.
          DESCZ( CTXT_ ) must equal DESCA( CTXT_ )
  WORK    (local workspace/output) DOUBLE PRECISION array,
          dimension max(3,LWORK)
          On return, WORK(1) contains the optimal amount of
          workspace required for efficient execution.
          if JOBZ='N' WORK(1) = optimal amount of workspace
             required to compute eigenvalues efficiently
          if JOBZ='V' WORK(1) = optimal amount of workspace
             required to compute eigenvalues and eigenvectors
             efficiently with no guarantee on orthogonality.
             If RANGE='V', it is assumed that all eigenvectors
             may be required.
  LWORK   (local input) INTEGER
          Size of WORK
          See below for definitions of variables used to define LWORK.
          If no eigenvectors are requested (JOBZ = 'N') then
             LWORK >= 5 * N + MAX( 5 * NN, NB * ( NP0 + 1 ) )
          If eigenvectors are requested (JOBZ = 'V' ) then
             the amount of workspace required to guarantee that all
             eigenvectors are computed is:
             LWORK >= 5*N + MAX( 5*NN, NP0 * MQ0 + 2 * NB * NB ) +
               ICEIL( NEIG, NPROW*NPCOL)*NN
             The computed eigenvectors may not be orthogonal if the
             minimal workspace is supplied and ORFAC is too small.
             If you want to guarantee orthogonality (at the cost
             of potentially poor performance) you should add
             the following to LWORK:
                (CLUSTERSIZE-1)*N
             where CLUSTERSIZE is the number of eigenvalues in the
             largest cluster, where a cluster is defined as a set of
             close eigenvalues: { W(K),...,W(K+CLUSTERSIZE-1) |
                                  W(J+1) <= W(J) + ORFAC*2*norm(A) }
          Variable definitions:
             NEIG = number of eigenvectors requested
             NB = DESCA( MB_ ) = DESCA( NB_ ) =
                  DESCZ( MB_ ) = DESCZ( NB_ )
             NN = MAX( N, NB, 2 )
             DESCA( RSRC_ ) = DESCA( NB_ ) = DESCZ( RSRC_ ) =
                              DESCZ( CSRC_ ) = 0
             NP0 = NUMROC( NN, NB, 0, 0, NPROW )
             MQ0 = NUMROC( MAX( NEIG, NB, 2 ), NB, 0, 0, NPCOL )
             ICEIL( X, Y ) is a ScaLAPACK function returning
             ceiling(X/Y)
          When LWORK is too small:
             If LWORK is too small to guarantee orthogonality,
             PDSYEVX attempts to maintain orthogonality in
             the clusters with the smallest
             spacing between the eigenvalues.
             If LWORK is too small to compute all the eigenvectors
             requested, no computation is performed and INFO=-23
             is returned.  Note that when RANGE='V', PDSYEVX does
             not know how many eigenvectors are requested until
             the eigenvalues are computed.  Therefore, when RANGE='V'
             and as long as LWORK is large enough to allow PDSYEVX to
             compute the eigenvalues, PDSYEVX will compute the
             eigenvalues and as many eigenvectors as it can.
          Relationship between workspace, orthogonality & performance:
             Greater performance can be achieved if adequate workspace
             is provided.  On the other hand, in some situations,
             performance can decrease as the workspace provided
             increases above the workspace amount shown below:
             For optimal performance, greater workspace may be
             needed, i.e.
                LWORK >=  MAX( LWORK, 5*N + NSYTRD_LWOPT )
                Where:
                  LWORK, as defined previously, depends upon the number
                     of eigenvectors requested, and
                  NSYTRD_LWOPT = N + 2*( ANB+1 )*( 4*NPS+2 ) +
                    ( NPS + 3 ) *  NPS
                  ANB = PJLAENV( DESCA( CTXT_), 3, 'PDSYTTRD', 'L',
                     0, 0, 0, 0)
                  SQNPC = INT( SQRT( DBLE( NPROW * NPCOL ) ) )
                  NPS = MAX( NUMROC( N, 1, 0, 0, SQNPC ), 2*ANB )
                  NUMROC is a ScaLAPACK tool functions;
                  PJLAENV is a ScaLAPACK envionmental inquiry function
                  MYROW, MYCOL, NPROW and NPCOL can be determined by
                    calling the subroutine BLACS_GRIDINFO.
                For large N, no extra workspace is needed, however the
                biggest boost in performance comes for small N, so it
                is wise to provide the extra workspace (typically less
                than a Megabyte per process).
             If CLUSTERSIZE >= N/SQRT(NPROW*NPCOL), then providing
             enough space to compute all the eigenvectors
             orthogonally will cause serious degradation in
             performance. In the limit (i.e. CLUSTERSIZE = N-1)
             PDSTEIN will perform no better than DSTEIN on 1
             processor.
             For CLUSTERSIZE = N/SQRT(NPROW*NPCOL) reorthogonalizing
             all eigenvectors will increase the total execution time
             by a factor of 2 or more.
             For CLUSTERSIZE > N/SQRT(NPROW*NPCOL) execution time will
             grow as the square of the cluster size, all other factors
             remaining equal and assuming enough workspace.  Less
             workspace means less reorthogonalization but faster
             execution.
          If LWORK = -1, then LWORK is global input and a workspace
          query is assumed; the routine only calculates the size
          required for optimal performance for all work arrays. Each of
          these values is returned in the first entry of the
          corresponding work arrays, and no error message is issued by
          PXERBLA.
  IWORK   (local workspace) INTEGER array
          On return, IWORK(1) contains the amount of integer workspace
          required.
  LIWORK  (local input) INTEGER
          size of IWORK
          LIWORK >= 6 * NNP
          Where:
            NNP = MAX( N, NPROW*NPCOL + 1, 4 )
          If LIWORK = -1, then LIWORK is global input and a workspace
          query is assumed; the routine only calculates the minimum
          and optimal size for all work arrays. Each of these
          values is returned in the first entry of the corresponding
          work array, and no error message is issued by PXERBLA.
  IFAIL   (global output) INTEGER array, dimension (N)
          If JOBZ = 'V', then on normal exit, the first M elements of
          IFAIL are zero.  If (MOD(INFO,2).NE.0) on exit, then
          IFAIL contains the
          indices of the eigenvectors that failed to converge.
          If JOBZ = 'N', then IFAIL is not referenced.
  ICLUSTR (global output) integer array, dimension (2*NPROW*NPCOL)
          This array contains indices of eigenvectors corresponding to
          a cluster of eigenvalues that could not be reorthogonalized
          due to insufficient workspace (see LWORK, ORFAC and INFO).
          Eigenvectors corresponding to clusters of eigenvalues indexed
          ICLUSTR(2*I-1) to ICLUSTR(2*I), could not be
          reorthogonalized due to lack of workspace. Hence the
          eigenvectors corresponding to these clusters may not be
          orthogonal.  ICLUSTR() is a zero terminated array.
          (ICLUSTR(2*K).NE.0 .AND. ICLUSTR(2*K+1).EQ.0) if and only if
          K is the number of clusters
          ICLUSTR is not referenced if JOBZ = 'N'
  GAP     (global output) DOUBLE PRECISION array,
             dimension (NPROW*NPCOL)
          This array contains the gap between eigenvalues whose
          eigenvectors could not be reorthogonalized. The output
          values in this array correspond to the clusters indicated
          by the array ICLUSTR. As a result, the dot product between
          eigenvectors correspoding to the I^th cluster may be as high
          as ( C * n ) / GAP(I) where C is a small constant.
  INFO    (global output) INTEGER
          = 0:  successful exit
          < 0:  If the i-th argument is an array and the j-entry had
                an illegal value, then INFO = -(i*100+j), if the i-th
                argument is a scalar and had an illegal value, then
                INFO = -i.
          > 0:  if (MOD(INFO,2).NE.0), then one or more eigenvectors
                  failed to converge.  Their indices are stored
                  in IFAIL.  Ensure ABSTOL=2.0*PDLAMCH( 'U' )
                  Send e-mail to scalapack@cs.utk.edu
                if (MOD(INFO/2,2).NE.0),then eigenvectors corresponding
                  to one or more clusters of eigenvalues could not be
                  reorthogonalized because of insufficient workspace.
                  The indices of the clusters are stored in the array
                  ICLUSTR.
                if (MOD(INFO/4,2).NE.0), then space limit prevented
                  PDSYEVX from computing all of the eigenvectors
                  between VL and VU.  The number of eigenvectors
                  computed is returned in NZ.
                if (MOD(INFO/8,2).NE.0), then PDSTEBZ failed to compute
                  eigenvalues.  Ensure ABSTOL=2.0*PDLAMCH( 'U' )
                  Send e-mail to scalapack@cs.utk.edu
  Alignment requirements
  ======================
  The distributed submatrices A(IA:*, JA:*) and C(IC:IC+M-1,JC:JC+N-1)
  must verify some alignment properties, namely the following
  expressions should be true:
  ( MB_A.EQ.NB_A.EQ.MB_Z .AND. IROFFA.EQ.IROFFZ .AND. IROFFA.EQ.0 .AND.
    IAROW.EQ.IZROW )
  where
  IROFFA = MOD( IA-1, MB_A ) and ICOFFA = MOD( JA-1, NB_A ).
  =====================================================================
  Differences between PDSYEVX and DSYEVX
  ======================================
  A, LDA -> A, IA, JA, DESCA
  Z, LDZ -> Z, IZ, JZ, DESCZ
  WORKSPACE needs are larger for PDSYEVX.
  LIWORK parameter added
  ORFAC, ICLUSTER() and GAP() parameters added
  meaning of INFO is changed
  Functional differences:
  PDSYEVX does not promise orthogonality for eigenvectors associated
  with tighly clustered eigenvalues.
  PDSYEVX does not reorthogonalize eigenvectors
  that are on different processes. The extent of reorthogonalization
  is controlled by the input parameter LWORK.
  Version 1.4 limitations:
     DESCA(MB_) = DESCA(NB_)
     DESCA(M_) = DESCZ(M_)
     DESCA(N_) = DESCZ(N_)
     DESCA(MB_) = DESCZ(MB_)
     DESCA(NB_) = DESCZ(NB_)
     DESCA(RSRC_) = DESCZ(RSRC_)
     .. Parameters ..

 
Display dynamic version Find AutoScroll Reload FontSize: - + Hide Comments Hide Blanks Frame FullScreen MailPrint

 
001        SUBROUTINE PDSYEVX( JOBZ , RANGE , UPLO , N , A , IA , JA , DESCA , VL ,
002       $VU , IL , IU , ABSTOL , M , NZ , W , ORFAC , Z , IZ ,
003       $JZ , DESCZ , WORK , LWORK , IWORK , LIWORK , IFAIL ,
004       $ICLUSTR , GAP , INFO )
005  
006  *     -- ScaLAPACK routine(version 1.7) --
007  *     University of Tennessee , Knoxville , Oak Ridge National Laboratory ,
008  *     and University of California , Berkeley.
009  *     May 25 , 2001
010  
011  *     .. Scalar Arguments ..
012        CHARACTER JOBZ , RANGE , UPLO
013        INTEGER IA , IL , INFO , IU , IZ , JA , JZ , LIWORK , LWORK , M ,
014       $N , NZ
015        DOUBLE PRECISION ABSTOL , ORFAC , VL , VU
016        INTEGER BLOCK_CYCLIC_2D , DLEN_ , DTYPE_ , CTXT_ , M_ , N_ ,
017       $MB_ , NB_ , RSRC_ , CSRC_ , LLD_
018        PARAMETER( BLOCK_CYCLIC_2D = 1 , DLEN_ = 9 , DTYPE_ = 1 ,
019       $CTXT_ = 2 , M_ = 3 , N_ = 4 , MB_ = 5 , NB_ = 6 ,
020       $RSRC_ = 7 , CSRC_ = 8 , LLD_ = 9 )
021        DOUBLE PRECISION ZERO , ONE , TEN , FIVE
022        PARAMETER( ZERO = 0.0D + 0 , ONE = 1.0D + 0 , TEN = 10.0D + 0 ,
023       $FIVE = 5.0D + 0 )
024        INTEGER IERREIN , IERRCLS , IERRSPC , IERREBZ
025        PARAMETER( IERREIN = 1 , IERRCLS = 2 , IERRSPC = 4 ,
026       $IERREBZ = 8 )
027  *     ..
028  *     .. Local Scalars ..
029        LOGICAL ALLEIG , INDEIG , LOWER , LQUERY , QUICKRETURN ,
030       $VALEIG , WANTZ
031        CHARACTER ORDER
032        INTEGER ANB , CSRC_A , I , IAROW , ICOFFA , ICTXT , IINFO ,
033       $INDD , INDD2 , INDE , INDE2 , INDIBL , INDISP ,
034       $INDTAU , INDWORK , IROFFA , IROFFZ , ISCALE ,
035       $ISIZESTEBZ , ISIZESTEIN , IZROW , LALLWORK ,
036       $LIWMIN , LLWORK , LWMIN , LWOPT , MAXEIGS , MB_A ,
037       $MQ0 , MYCOL , MYROW , NB , NB_A , NEIG , NN , NNP ,
038       $NP0 , NPCOL , NPROCS , NPROW , NPS , NSPLIT ,
039       $NSYTRD_LWOPT , NZZ , OFFSET , RSRC_A , RSRC_Z ,
040       $SIZEORMTR , SIZESTEIN , SIZESYEVX , SQNPC
041        DOUBLE PRECISION ABSTLL , ANRM , BIGNUM , EPS , RMAX , RMIN , SAFMIN ,
042       $SIGMA , SMLNUM , VLL , VUU
043  *     ..
044  *     .. Local Arrays ..
045        INTEGER IDUM1( 4 ) , IDUM2( 4 )
046  *     ..
047  *     .. External Functions ..
048        LOGICAL LSAME
049        INTEGER ICEIL , INDXG2P , NUMROC , PJLAENV
050        DOUBLE PRECISION PDLAMCH , PDLANSY
051        EXTERNAL LSAME , ICEIL , INDXG2P , NUMROC , PJLAENV ,
052       $PDLAMCH , PDLANSY
053  *     ..
054  *     .. External Subroutines ..
055        EXTERNAL BLACS_GRIDINFO , CHK1MAT , DGEBR2D , DGEBS2D ,
056       $DLASRT , DSCAL , IGAMN2D , PCHK1MAT , PCHK2MAT ,
057       $PDELGET , PDLARED1D , PDLASCL , PDORMTR , PDSTEBZ ,
058       $PDSTEIN , PDSYNTRD , PXERBLA
059  *     ..
060  *     .. Intrinsic Functions ..
061        INTRINSIC ABS , DBLE , ICHAR , INT , MAX , MIN , MOD , SQRT
062  *     ..
063  *     .. Executable Statements ..
064  *     This is just to keep ftnchek and toolpack / 1 happy
065        IF( BLOCK_CYCLIC_2D*CSRC_*CTXT_*DLEN_*DTYPE_*LLD_*MB_*M_*NB_*N_*
066       $    RSRC_.LT.0 )RETURN
067  
068            QUICKRETURN =( N.EQ.0 )
069  
070  *         Test the input arguments.
071  
072            ICTXT = DESCA( CTXT_ )
073            CALL BLACS_GRIDINFO( ICTXT , NPROW , NPCOL , MYROW , MYCOL )
074            INFO = 0
075  
076            WANTZ = LSAME( JOBZ , 'V' )
077            IF( NPROW.EQ. - 1 ) THEN
078                INFO = - ( 800 + CTXT_ )
079            ELSE IF( WANTZ ) THEN
080                IF( ICTXT.NE.DESCZ( CTXT_ ) ) THEN
081                    INFO = - ( 2100 + CTXT_ )
082                END IF
083            END IF
084            IF( INFO.EQ.0 ) THEN
085                CALL CHK1MAT( N , 4 , N , 4 , IA , JA , DESCA , 8 , INFO )
086                IF( WANTZ )
087       $            CALL CHK1MAT( N , 4 , N , 4 , IZ , JZ , DESCZ , 21 , INFO )
088  
089                    IF( INFO.EQ.0 ) THEN
090  
091  *                     Get machine constants.
092  
093                        SAFMIN = PDLAMCH( ICTXT , 'Safe minimum' )
094                        EPS = PDLAMCH( ICTXT , 'Precision' )
095                        SMLNUM = SAFMIN / EPS
096                        BIGNUM = ONE / SMLNUM
097                        RMIN = SQRT( SMLNUM )
098                        RMAX = MIN( SQRT( BIGNUM ) , ONE / SQRT( SQRT( SAFMIN ) ) )
099  
100                        NPROCS = NPROW*NPCOL
101                        LOWER = LSAME( UPLO , 'L' )
102                        ALLEIG = LSAME( RANGE , 'A' )
103                        VALEIG = LSAME( RANGE , 'V' )
104                        INDEIG = LSAME( RANGE , 'I' )
105  
106  *                     Set up pointers into the WORK array
107  
108                        INDTAU = 1
109                        INDE = INDTAU + N
110                        INDD = INDE + N
111                        INDD2 = INDD + N
112                        INDE2 = INDD2 + N
113                        INDWORK = INDE2 + N
114                        LLWORK = LWORK - INDWORK + 1
115  
116  *                     Set up pointers into the IWORK array
117  
118                        ISIZESTEIN = 3*N + NPROCS + 1
119                        ISIZESTEBZ = MAX( 4*N , 14 , NPROCS )
120                        INDIBL =( MAX( ISIZESTEIN , ISIZESTEBZ ) ) + 1
121                        INDISP = INDIBL + N
122  
123  *                     Compute the total amount of space needed
124  
125                        LQUERY = .FALSE.
126                        IF( LWORK.EQ. - 1 .OR. LIWORK.EQ. - 1 )
127       $                    LQUERY = .TRUE.
128  
129                            NNP = MAX( N , NPROCS + 1 , 4 )
130                            LIWMIN = 6*NNP
131  
132                            NPROCS = NPROW*NPCOL
133                            NB_A = DESCA( NB_ )
134                            MB_A = DESCA( MB_ )
135                            NB = NB_A
136                            NN = MAX( N , NB , 2 )
137  
138                            RSRC_A = DESCA( RSRC_ )
139                            CSRC_A = DESCA( CSRC_ )
140                            IROFFA = MOD( IA - 1 , MB_A )
141                            ICOFFA = MOD( JA - 1 , NB_A )
142                            IAROW = INDXG2P( 1 , NB_A , MYROW , RSRC_A , NPROW )
143                            NP0 = NUMROC( N + IROFFA , NB , 0 , 0 , NPROW )
144                            MQ0 = NUMROC( N + ICOFFA , NB , 0 , 0 , NPCOL )
145                            IF( WANTZ ) THEN
146                                RSRC_Z = DESCZ( RSRC_ )
147                                IROFFZ = MOD( IZ - 1 , MB_A )
148                                IZROW = INDXG2P( 1 , NB_A , MYROW , RSRC_Z , NPROW )
149                            END IF
150  
151                            IF(( .NOT.WANTZ ) .OR.( VALEIG .AND.( .NOT.LQUERY ) ) )
152       $                        THEN
153                                LWMIN = 5*N + MAX( 5*NN , NB*( NP0 + 1 ) )
154                                IF( WANTZ ) THEN
155                                    MQ0 = NUMROC( MAX( N , NB , 2 ) , NB , 0 , 0 , NPCOL )
156                                    LWOPT = 5*N + MAX( 5*NN , NP0*MQ0 + 2*NB*NB )
157                                ELSE
158                                    LWOPT = LWMIN
159                                END IF
160                                NEIG = 0
161                            ELSE
162                                IF( ALLEIG .OR. VALEIG ) THEN
163                                    NEIG = N
164                                ELSE IF( INDEIG ) THEN
165                                    NEIG = IU - IL + 1
166                                END IF
167                                MQ0 = NUMROC( MAX( NEIG , NB , 2 ) , NB , 0 , 0 , NPCOL )
168                                LWMIN = 5*N + MAX( 5*NN , NP0*MQ0 + 2*NB*NB ) +
169       $                        ICEIL( NEIG , NPROW*NPCOL )*NN
170                                LWOPT = LWMIN
171  
172                            END IF
173  
174  *                         Compute how much workspace is needed to use the
175  *                         new TRD code
176  
177                            ANB = PJLAENV( ICTXT , 3 , 'PDSYTTRD' , 'L' , 0 , 0 , 0 , 0 )
178                            SQNPC = INT( SQRT( DBLE( NPROW*NPCOL ) ) )
179                            NPS = MAX( NUMROC( N , 1 , 0 , 0 , SQNPC ) , 2*ANB )
180                            NSYTRD_LWOPT = 2*( ANB + 1 )*( 4*NPS + 2 ) + ( NPS + 4 )*NPS
181                            LWOPT = MAX( LWOPT , 5*N + NSYTRD_LWOPT )
182  
183                        END IF
184                        IF( INFO.EQ.0 ) THEN
185                            IF( MYROW.EQ.0 .AND. MYCOL.EQ.0 ) THEN
186                                WORK( 1 ) = ABSTOL
187                                IF( VALEIG ) THEN
188                                    WORK( 2 ) = VL
189                                    WORK( 3 ) = VU
190                                ELSE
191                                    WORK( 2 ) = ZERO
192                                    WORK( 3 ) = ZERO
193                                END IF
194                                CALL DGEBS2D( ICTXT , 'ALL' , ' ' , 3 , 1 , WORK , 3 )
195                            ELSE
196                                CALL DGEBR2D( ICTXT , 'ALL' , ' ' , 3 , 1 , WORK , 3 , 0 , 0 )
197                            END IF
198                            IF( .NOT.( WANTZ .OR. LSAME( JOBZ , 'N' ) ) ) THEN
199                                INFO = - 1
200                            ELSE IF( .NOT.( ALLEIG .OR. VALEIG .OR. INDEIG ) ) THEN
201                                INFO = - 2
202                            ELSE IF( .NOT.( LOWER .OR. LSAME( UPLO , 'U' ) ) ) THEN
203                                INFO = - 3
204                            ELSE IF( VALEIG .AND. N.GT.0 .AND. VU.LE.VL ) THEN
205                                INFO = - 10
206                            ELSE IF( INDEIG .AND.( IL.LT.1 .OR. IL.GT.MAX( 1 , N ) ) )
207       $                        THEN
208                                INFO = - 11
209                            ELSE IF( INDEIG .AND.( IU.LT.MIN( N , IL ) .OR. IU.GT.N ) )
210       $                        THEN
211                                INFO = - 12
212                            ELSE IF( LWORK.LT.LWMIN .AND. LWORK.NE. - 1 ) THEN
213                                INFO = - 23
214                            ELSE IF( LIWORK.LT.LIWMIN .AND. LIWORK.NE. - 1 ) THEN
215                                INFO = - 25
216                            ELSE IF( VALEIG .AND.( ABS( WORK( 2 ) - VL ).GT.FIVE*EPS*
217       $                        ABS( VL ) ) ) THEN
218                                INFO = - 9
219                            ELSE IF( VALEIG .AND.( ABS( WORK( 3 ) - VU ).GT.FIVE*EPS*
220       $                        ABS( VU ) ) ) THEN
221                                INFO = - 10
222                            ELSE IF( ABS( WORK( 1 ) - ABSTOL ).GT.FIVE*EPS*ABS( ABSTOL ) )
223       $                        THEN
224                                INFO = - 13
225                            ELSE IF( IROFFA.NE.0 ) THEN
226                                INFO = - 6
227                            ELSE IF( DESCA( MB_ ).NE.DESCA( NB_ ) ) THEN
228                                INFO = - ( 800 + NB_ )
229                            END IF
230                            IF( WANTZ ) THEN
231                                IF( IROFFA.NE.IROFFZ ) THEN
232                                    INFO = - 19
233                                ELSE IF( IAROW.NE.IZROW ) THEN
234                                    INFO = - 19
235                                ELSE IF( DESCA( M_ ).NE.DESCZ( M_ ) ) THEN
236                                    INFO = - ( 2100 + M_ )
237                                ELSE IF( DESCA( N_ ).NE.DESCZ( N_ ) ) THEN
238                                    INFO = - ( 2100 + N_ )
239                                ELSE IF( DESCA( MB_ ).NE.DESCZ( MB_ ) ) THEN
240                                    INFO = - ( 2100 + MB_ )
241                                ELSE IF( DESCA( NB_ ).NE.DESCZ( NB_ ) ) THEN
242                                    INFO = - ( 2100 + NB_ )
243                                ELSE IF( DESCA( RSRC_ ).NE.DESCZ( RSRC_ ) ) THEN
244                                    INFO = - ( 2100 + RSRC_ )
245                                ELSE IF( DESCA( CSRC_ ).NE.DESCZ( CSRC_ ) ) THEN
246                                    INFO = - ( 2100 + CSRC_ )
247                                ELSE IF( ICTXT.NE.DESCZ( CTXT_ ) ) THEN
248                                    INFO = - ( 2100 + CTXT_ )
249                                END IF
250                            END IF
251                        END IF
252                        IF( WANTZ ) THEN
253                            IDUM1( 1 ) = ICHAR( 'V' )
254                        ELSE
255                            IDUM1( 1 ) = ICHAR( 'N' )
256                        END IF
257                        IDUM2( 1 ) = 1
258                        IF( LOWER ) THEN
259                            IDUM1( 2 ) = ICHAR( 'L' )
260                        ELSE
261                            IDUM1( 2 ) = ICHAR( 'U' )
262                        END IF
263                        IDUM2( 2 ) = 2
264                        IF( ALLEIG ) THEN
265                            IDUM1( 3 ) = ICHAR( 'A' )
266                        ELSE IF( INDEIG ) THEN
267                            IDUM1( 3 ) = ICHAR( 'I' )
268                        ELSE
269                            IDUM1( 3 ) = ICHAR( 'V' )
270                        END IF
271                        IDUM2( 3 ) = 3
272                        IF( LQUERY ) THEN
273                            IDUM1( 4 ) = - 1
274                        ELSE
275                            IDUM1( 4 ) = 1
276                        END IF
277                        IDUM2( 4 ) = 4
278                        IF( WANTZ ) THEN
279                            CALL PCHK2MAT( N , 4 , N , 4 , IA , JA , DESCA , 8 , N , 4 , N , 4 , IZ ,
280       $                    JZ , DESCZ , 21 , 4 , IDUM1 , IDUM2 , INFO )
281                        ELSE
282                            CALL PCHK1MAT( N , 4 , N , 4 , IA , JA , DESCA , 8 , 4 , IDUM1 ,
283       $                    IDUM2 , INFO )
284                        END IF
285                        WORK( 1 ) = DBLE( LWOPT )
286                        IWORK( 1 ) = LIWMIN
287                    END IF
288  
289                    IF( INFO.NE.0 ) THEN
290                        CALL PXERBLA( ICTXT , 'PDSYEVX' , - INFO )
291                        RETURN
292                    ELSE IF( LQUERY ) THEN
293                        RETURN
294                    END IF
295  
296  *                 Quick return if possible
297  
298                    IF( QUICKRETURN ) THEN
299                        IF( WANTZ ) THEN
300                            NZ = 0
301                            ICLUSTR( 1 ) = 0
302                        END IF
303                        M = 0
304                        WORK( 1 ) = DBLE( LWOPT )
305                        IWORK( 1 ) = LIWMIN
306                        RETURN
307                    END IF
308  
309  *                 Scale matrix to allowable range , if necessary.
310  
311                    ABSTLL = ABSTOL
312                    ISCALE = 0
313                    IF( VALEIG ) THEN
314                        VLL = VL
315                        VUU = VU
316                    ELSE
317                        VLL = ZERO
318                        VUU = ZERO
319                    END IF
320  
321                    ANRM = PDLANSY( 'M' , UPLO , N , A , IA , JA , DESCA , WORK( INDWORK ) )
322  
323                    IF( ANRM.GT.ZERO .AND. ANRM.LT.RMIN ) THEN
324                        ISCALE = 1
325                        SIGMA = RMIN / ANRM
326                        ANRM = ANRM*SIGMA
327                    ELSE IF( ANRM.GT.RMAX ) THEN
328                        ISCALE = 1
329                        SIGMA = RMAX / ANRM
330                        ANRM = ANRM*SIGMA
331                    END IF
332  
333                    IF( ISCALE.EQ.1 ) THEN
334                        CALL PDLASCL ( UPLO , ONE , SIGMA , N , N , A , IA , JA , DESCA , IINFO )
335                        IF( ABSTOL.GT.0 )
336       $                    ABSTLL = ABSTOL*SIGMA
337                            IF( VALEIG ) THEN
338                                VLL = VL*SIGMA
339                                VUU = VU*SIGMA
340                                IF( VUU.EQ.VLL ) THEN
341                                    VUU = VUU + 2*MAX( ABS( VUU )*EPS , SAFMIN )
342                                END IF
343                            END IF
344                        END IF
345  
346  *                     Call PDSYNTRD to reduce symmetric matrix to tridiagonal form.
347  
348                        LALLWORK = LLWORK
349  
350                        CALL PDSYNTRD ( UPLO , N , A , IA , JA , DESCA , WORK( INDD ) ,
351       $                WORK( INDE ) , WORK( INDTAU ) , WORK( INDWORK ) ,
352       $                LLWORK , IINFO )
353  
354  *                     Copy the values of D , E to all processes
355  
356  *                     Here PxLARED1D is used to redistribute the tridiagonal matrix.
357  *                     PxLARED1D , however , doesn't yet work with arbritary matrix
358  *                     distributions so we have PxELGET as a backup.
359  
360                        OFFSET = 0
361                        IF( IA.EQ.1 .AND. JA.EQ.1 .AND. RSRC_A.EQ.0 .AND. CSRC_A.EQ.0 )
362       $                    THEN
363                            CALL PDLARED1D ( N , IA , JA , DESCA , WORK( INDD ) , WORK( INDD2 ) ,
364       $                    WORK( INDWORK ) , LLWORK )
365  
366                            CALL PDLARED1D ( N , IA , JA , DESCA , WORK( INDE ) , WORK( INDE2 ) ,
367       $                    WORK( INDWORK ) , LLWORK )
368                            IF( .NOT.LOWER )
369       $                        OFFSET = 1
370                            ELSE
371                                DO 10 I = 1 , N
372                                    CALL PDELGET( 'A' , ' ' , WORK( INDD2 + I - 1 ) , A , I + IA - 1 ,
373       $                            I + JA - 1 , DESCA )
374     10                         CONTINUE
375                                IF( LSAME( UPLO , 'U' ) ) THEN
376                                    DO 20 I = 1 , N - 1
377                                        CALL PDELGET( 'A' , ' ' , WORK( INDE2 + I - 1 ) , A , I + IA - 1 ,
378       $                                I + JA , DESCA )
379     20                             CONTINUE
380                                ELSE
381                                    DO 30 I = 1 , N - 1
382                                        CALL PDELGET( 'A' , ' ' , WORK( INDE2 + I - 1 ) , A , I + IA ,
383       $                                I + JA - 1 , DESCA )
384     30                             CONTINUE
385                                END IF
386                            END IF
387  
388  *                         Call PDSTEBZ and , if eigenvectors are desired , PDSTEIN.
389  
390                            IF( WANTZ ) THEN
391                                ORDER = 'B'
392                            ELSE
393                                ORDER = 'E'
394                            END IF
395  
396                            CALL PDSTEBZ ( ICTXT , RANGE , ORDER , N , VLL , VUU , IL , IU , ABSTLL ,
397       $                    WORK( INDD2 ) , WORK( INDE2 + OFFSET ) , M , NSPLIT , W ,
398       $                    IWORK( INDIBL ) , IWORK( INDISP ) , WORK( INDWORK ) ,
399       $                    LLWORK , IWORK( 1 ) , ISIZESTEBZ , IINFO )
400  
401  *                         IF PDSTEBZ fails , the error propogates to INFO , but
402  *                         we do not propogate the eigenvalue(s) which failed because :
403  *                         1) This should never happen if the user specifies
404  *                         ABSTOL = 2 * PDLAMCH( 'U' )
405  *                         2) PDSTEIN will confirm / deny whether the eigenvalues are
406  *                         close enough.
407  
408                            IF( IINFO.NE.0 ) THEN
409                                INFO = INFO + IERREBZ
410                                DO 40 I = 1 , M
411                                    IWORK( INDIBL + I - 1 ) = ABS( IWORK( INDIBL + I - 1 ) )
412     40                         CONTINUE
413                            END IF
414                            IF( WANTZ ) THEN
415  
416                                IF( VALEIG ) THEN
417  
418  *                                 Compute the maximum number of eigenvalues that we can
419  *                                 compute in the
420  *                                 workspace that we have , and that we can store in Z.
421  
422  *                                 Loop through the possibilities looking for the largest
423  *                                 NZ that we can feed to PDSTEIN and PDORMTR
424  
425  *                                 Since all processes must end up with the same value
426  *                                 of NZ , we first compute the minimum of LALLWORK
427  
428                                    CALL IGAMN2D( ICTXT , 'A' , ' ' , 1 , 1 , LALLWORK , 1 , 1 , 1 , - 1 ,
429       $                            - 1 , - 1 )
430  
431                                    MAXEIGS = DESCZ( N_ )
432  
433                                    DO 50 NZ = MIN( MAXEIGS , M ) , 0 , - 1
434                                        MQ0 = NUMROC( NZ , NB , 0 , 0 , NPCOL )
435                                        SIZESTEIN = ICEIL( NZ , NPROCS )*N + MAX( 5*N , NP0*MQ0 )
436                                        SIZEORMTR = MAX(( NB*( NB - 1 ) ) / 2 ,( MQ0 + NP0 )*NB ) +
437       $                                NB*NB
438  
439                                        SIZESYEVX = MAX( SIZESTEIN , SIZEORMTR )
440                                        IF( SIZESYEVX.LE.LALLWORK )
441       $                                    GO TO 60
442     50                             CONTINUE
443     60 CONTINUE
444        ELSE
445            NZ = M
446        END IF
447        NZ = MAX( NZ , 0 )
448        IF( NZ.NE.M ) THEN
449            INFO = INFO + IERRSPC
450  
451            DO 70 I = 1 , M
452                IFAIL( I ) = 0
453     70     CONTINUE
454  
455  *         The following code handles a rare special case
456  *         - NZ .NE. M means that we don't have enough room to store
457  *         all the vectors.
458  *         - NSPLIT .GT. 1 means that the matrix split
459  *         In this case , we cannot simply take the first NZ eigenvalues
460  *         because PDSTEBZ sorts the eigenvalues by block when
461  *         a split occurs. So , we have to make another call to
462  *         PDSTEBZ with a new upper limit - VUU.
463  
464            IF( NSPLIT.GT.1 ) THEN
465                CALL DLASRT( 'I' , M , W , IINFO )
466                NZZ = 0
467                IF( NZ.GT.0 ) THEN
468  
469                    VUU = W( NZ ) - TEN*( EPS*ANRM + SAFMIN )
470                    IF( VLL.GE.VUU ) THEN
471                        NZZ = 0
472                    ELSE
473                        CALL PDSTEBZ ( ICTXT , RANGE , ORDER , N , VLL , VUU , IL ,
474       $                IU , ABSTLL , WORK( INDD2 ) ,
475       $                WORK( INDE2 + OFFSET ) , NZZ , NSPLIT , W ,
476       $                IWORK( INDIBL ) , IWORK( INDISP ) ,
477       $                WORK( INDWORK ) , LLWORK , IWORK( 1 ) ,
478       $                ISIZESTEBZ , IINFO )
479                    END IF
480  
481                    IF( MOD( INFO / IERREBZ , 1 ).EQ.0 ) THEN
482                        IF( NZZ.GT.NZ .OR. IINFO.NE.0 ) THEN
483                            INFO = INFO + IERREBZ
484                        END IF
485                    END IF
486                END IF
487                NZ = MIN( NZ , NZZ )
488  
489            END IF
490        END IF
491        CALL PDSTEIN ( N , WORK( INDD2 ) , WORK( INDE2 + OFFSET ) , NZ , W ,
492       $IWORK( INDIBL ) , IWORK( INDISP ) , ORFAC , Z , IZ ,
493       $JZ , DESCZ , WORK( INDWORK ) , LALLWORK , IWORK( 1 ) ,
494       $ISIZESTEIN , IFAIL , ICLUSTR , GAP , IINFO )
495  
496        IF( IINFO.GE.NZ + 1 )
497       $    INFO = INFO + IERRCLS
498            IF( MOD( IINFO , NZ + 1 ).NE.0 )
499       $        INFO = INFO + IERREIN
500  
501  *             Z = Q * Z
502  
503                IF( NZ.GT.0 ) THEN
504                    CALL PDORMTR ( 'L' , UPLO , 'N' , N , NZ , A , IA , JA , DESCA ,
505       $            WORK( INDTAU ) , Z , IZ , JZ , DESCZ ,
506       $            WORK( INDWORK ) , LLWORK , IINFO )
507                END IF
508  
509            END IF
510  
511  *         If matrix was scaled , then rescale eigenvalues appropriately.
512  
513            IF( ISCALE.EQ.1 ) THEN
514                CALL DSCAL( M , ONE / SIGMA , W , 1 )
515            END IF
516  
517            WORK( 1 ) = DBLE( LWOPT )
518            IWORK( 1 ) = LIWMIN
519  
520            RETURN
521  
522  *         End of PDSYEVX
523  
524        END