1       SUBROUTINE CPPT05( UPLO, N, NRHS, AP, B, LDB, X, LDX, XACT,
  2      $                   LDXACT, FERR, BERR, RESLTS )
  3 *
  4 *  -- LAPACK test routine (version 3.1) --
  5 *     Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd..
  6 *     November 2006
  7 *
  8 *     .. Scalar Arguments ..
  9       CHARACTER          UPLO
 10       INTEGER            LDB, LDX, LDXACT, N, NRHS
 11 *     ..
 12 *     .. Array Arguments ..
 13       REAL               BERR( * ), FERR( * ), RESLTS( * )
 14       COMPLEX            AP( * ), B( LDB, * ), X( LDX, * ),
 15      $                   XACT( LDXACT, * )
 16 *     ..
 17 *
 18 *  Purpose
 19 *  =======
 20 *
 21 *  CPPT05 tests the error bounds from iterative refinement for the
 22 *  computed solution to a system of equations A*X = B, where A is a
 23 *  Hermitian matrix in packed storage format.
 24 *
 25 *  RESLTS(1) = test of the error bound
 26 *            = norm(X - XACT) / ( norm(X) * FERR )
 27 *
 28 *  A large value is returned if this ratio is not less than one.
 29 *
 30 *  RESLTS(2) = residual from the iterative refinement routine
 31 *            = the maximum of BERR / ( (n+1)*EPS + (*) ), where
 32 *              (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
 33 *
 34 *  Arguments
 35 *  =========
 36 *
 37 *  UPLO    (input) CHARACTER*1
 38 *          Specifies whether the upper or lower triangular part of the
 39 *          Hermitian matrix A is stored.
 40 *          = 'U':  Upper triangular
 41 *          = 'L':  Lower triangular
 42 *
 43 *  N       (input) INTEGER
 44 *          The number of rows of the matrices X, B, and XACT, and the
 45 *          order of the matrix A.  N >= 0.
 46 *
 47 *  NRHS    (input) INTEGER
 48 *          The number of columns of the matrices X, B, and XACT.
 49 *          NRHS >= 0.
 50 *
 51 *  AP      (input) COMPLEX array, dimension (N*(N+1)/2)
 52 *          The upper or lower triangle of the Hermitian matrix A, packed
 53 *          columnwise in a linear array.  The j-th column of A is stored
 54 *          in the array AP as follows:
 55 *          if UPLO = 'U', AP(i + (j-1)*j/2) = A(i,j) for 1<=i<=j;
 56 *          if UPLO = 'L', AP(i + (j-1)*(2n-j)/2) = A(i,j) for j<=i<=n.
 57 *
 58 *  B       (input) COMPLEX array, dimension (LDB,NRHS)
 59 *          The right hand side vectors for the system of linear
 60 *          equations.
 61 *
 62 *  LDB     (input) INTEGER
 63 *          The leading dimension of the array B.  LDB >= max(1,N).
 64 *
 65 *  X       (input) COMPLEX array, dimension (LDX,NRHS)
 66 *          The computed solution vectors.  Each vector is stored as a
 67 *          column of the matrix X.
 68 *
 69 *  LDX     (input) INTEGER
 70 *          The leading dimension of the array X.  LDX >= max(1,N).
 71 *
 72 *  XACT    (input) COMPLEX array, dimension (LDX,NRHS)
 73 *          The exact solution vectors.  Each vector is stored as a
 74 *          column of the matrix XACT.
 75 *
 76 *  LDXACT  (input) INTEGER
 77 *          The leading dimension of the array XACT.  LDXACT >= max(1,N).
 78 *
 79 *  FERR    (input) REAL array, dimension (NRHS)
 80 *          The estimated forward error bounds for each solution vector
 81 *          X.  If XTRUE is the true solution, FERR bounds the magnitude
 82 *          of the largest entry in (X - XTRUE) divided by the magnitude
 83 *          of the largest entry in X.
 84 *
 85 *  BERR    (input) REAL array, dimension (NRHS)
 86 *          The componentwise relative backward error of each solution
 87 *          vector (i.e., the smallest relative change in any entry of A
 88 *          or B that makes X an exact solution).
 89 *
 90 *  RESLTS  (output) REAL array, dimension (2)
 91 *          The maximum over the NRHS solution vectors of the ratios:
 92 *          RESLTS(1) = norm(X - XACT) / ( norm(X) * FERR )
 93 *          RESLTS(2) = BERR / ( (n+1)*EPS + (*) )
 94 *
 95 *  =====================================================================
 96 *
 97 *     .. Parameters ..
 98       REAL               ZERO, ONE
 99       PARAMETER          ( ZERO = 0.0E+0, ONE = 1.0E+0 )
100 *     ..
101 *     .. Local Scalars ..
102       LOGICAL            UPPER
103       INTEGER            I, IMAX, J, JC, K
104       REAL               AXBI, DIFF, EPS, ERRBND, OVFL, TMP, UNFL, XNORM
105       COMPLEX            ZDUM
106 *     ..
107 *     .. External Functions ..
108       LOGICAL            LSAME
109       INTEGER            ICAMAX
110       REAL               SLAMCH
111       EXTERNAL           LSAME, ICAMAX, SLAMCH
112 *     ..
113 *     .. Intrinsic Functions ..
114       INTRINSIC          ABSAIMAGMAXMIN, REAL
115 *     ..
116 *     .. Statement Functions ..
117       REAL               CABS1
118 *     ..
119 *     .. Statement Function definitions ..
120       CABS1( ZDUM ) = ABSREAL( ZDUM ) ) + ABSAIMAG( ZDUM ) )
121 *     ..
122 *     .. Executable Statements ..
123 *
124 *     Quick exit if N = 0 or NRHS = 0.
125 *
126       IF( N.LE.0 .OR. NRHS.LE.0 ) THEN
127          RESLTS( 1 ) = ZERO
128          RESLTS( 2 ) = ZERO
129          RETURN
130       END IF
131 *
132       EPS = SLAMCH( 'Epsilon' )
133       UNFL = SLAMCH( 'Safe minimum' )
134       OVFL = ONE / UNFL
135       UPPER = LSAME( UPLO, 'U' )
136 *
137 *     Test 1:  Compute the maximum of
138 *        norm(X - XACT) / ( norm(X) * FERR )
139 *     over all the vectors X and XACT using the infinity-norm.
140 *
141       ERRBND = ZERO
142       DO 30 J = 1, NRHS
143          IMAX = ICAMAX( N, X( 1, J ), 1 )
144          XNORM = MAX( CABS1( X( IMAX, J ) ), UNFL )
145          DIFF = ZERO
146          DO 10 I = 1, N
147             DIFF = MAX( DIFF, CABS1( X( I, J )-XACT( I, J ) ) )
148    10    CONTINUE
149 *
150          IF( XNORM.GT.ONE ) THEN
151             GO TO 20
152          ELSE IF( DIFF.LE.OVFL*XNORM ) THEN
153             GO TO 20
154          ELSE
155             ERRBND = ONE / EPS
156             GO TO 30
157          END IF
158 *
159    20    CONTINUE
160          IF( DIFF / XNORM.LE.FERR( J ) ) THEN
161             ERRBND = MAX( ERRBND, ( DIFF / XNORM ) / FERR( J ) )
162          ELSE
163             ERRBND = ONE / EPS
164          END IF
165    30 CONTINUE
166       RESLTS( 1 ) = ERRBND
167 *
168 *     Test 2:  Compute the maximum of BERR / ( (n+1)*EPS + (*) ), where
169 *     (*) = (n+1)*UNFL / (min_i (abs(A)*abs(X) +abs(b))_i )
170 *
171       DO 90 K = 1, NRHS
172          DO 80 I = 1, N
173             TMP = CABS1( B( I, K ) )
174             IF( UPPER ) THEN
175                JC = ( ( I-1 )*I ) / 2
176                DO 40 J = 1, I - 1
177                   TMP = TMP + CABS1( AP( JC+J ) )*CABS1( X( J, K ) )
178    40          CONTINUE
179                TMP = TMP + ABSREAL( AP( JC+I ) ) )*CABS1( X( I, K ) )
180                JC = JC + I + I
181                DO 50 J = I + 1, N
182                   TMP = TMP + CABS1( AP( JC ) )*CABS1( X( J, K ) )
183                   JC = JC + J
184    50          CONTINUE
185             ELSE
186                JC = I
187                DO 60 J = 1, I - 1
188                   TMP = TMP + CABS1( AP( JC ) )*CABS1( X( J, K ) )
189                   JC = JC + N - J
190    60          CONTINUE
191                TMP = TMP + ABSREAL( AP( JC ) ) )*CABS1( X( I, K ) )
192                DO 70 J = I + 1, N
193                   TMP = TMP + CABS1( AP( JC+J-I ) )*CABS1( X( J, K ) )
194    70          CONTINUE
195             END IF
196             IF( I.EQ.1 ) THEN
197                AXBI = TMP
198             ELSE
199                AXBI = MIN( AXBI, TMP )
200             END IF
201    80    CONTINUE
202          TMP = BERR( K ) / ( ( N+1 )*EPS+( N+1 )*UNFL /
203      $         MAX( AXBI, ( N+1 )*UNFL ) )
204          IF( K.EQ.1 ) THEN
205             RESLTS( 2 ) = TMP
206          ELSE
207             RESLTS( 2 ) = MAX( RESLTS( 2 ), TMP )
208          END IF
209    90 CONTINUE
210 *
211       RETURN
212 *
213 *     End of CPPT05
214 *
215       END