Routine: PSSYEVX()  File: SRC\pssyevx.f

 
 
# lines: 976
  # code: 976
  # comment: 0
  # blank:0
# Variables:121
# Callers:1
# Callings:9
# Words:518
# Keywords:322
 

 

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