001:       SUBROUTINE CLA_HERFSX_EXTENDED( PREC_TYPE, UPLO, N, NRHS, A, LDA,
002:      $                                AF, LDAF, IPIV, COLEQU, C, B, LDB,
003:      $                                Y, LDY, BERR_OUT, N_NORMS,
004:      $                                ERR_BNDS_NORM, ERR_BNDS_COMP, RES,
005:      $                                AYB, DY, Y_TAIL, RCOND, ITHRESH,
006:      $                                RTHRESH, DZ_UB, IGNORE_CWISE,
007:      $                                INFO )
008: *
009: *     -- LAPACK routine (version 3.2.1)                                 --
010: *     -- Contributed by James Demmel, Deaglan Halligan, Yozo Hida and --
011: *     -- Jason Riedy of Univ. of California Berkeley.                 --
012: *     -- April 2009                                                   --
013: *
014: *     -- LAPACK is a software package provided by Univ. of Tennessee, --
015: *     -- Univ. of California Berkeley and NAG Ltd.                    --
016: *
017:       IMPLICIT NONE
018: *     ..
019: *     .. Scalar Arguments ..
020:       INTEGER            INFO, LDA, LDAF, LDB, LDY, N, NRHS, PREC_TYPE,
021:      $                   N_NORMS, ITHRESH
022:       CHARACTER          UPLO
023:       LOGICAL            COLEQU, IGNORE_CWISE
024:       REAL               RTHRESH, DZ_UB
025: *     ..
026: *     .. Array Arguments ..
027:       INTEGER            IPIV( * )
028:       COMPLEX            A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
029:      $                   Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * )
030:       REAL               C( * ), AYB( * ), RCOND, BERR_OUT( * ),
031:      $                   ERR_BNDS_NORM( NRHS, * ),
032:      $                   ERR_BNDS_COMP( NRHS, * )
033: *     ..
034: *
035: *  Purpose
036: *  =======
037: *
038: *  CLA_HERFSX_EXTENDED improves the computed solution to a system of
039: *  linear equations by performing extra-precise iterative refinement
040: *  and provides error bounds and backward error estimates for the solution.
041: *  This subroutine is called by CHERFSX to perform iterative refinement.
042: *  In addition to normwise error bound, the code provides maximum
043: *  componentwise error bound if possible. See comments for ERR_BNDS_NORM
044: *  and ERR_BNDS_COMP for details of the error bounds. Note that this
045: *  subroutine is only resonsible for setting the second fields of
046: *  ERR_BNDS_NORM and ERR_BNDS_COMP.
047: *
048: *  Arguments
049: *  =========
050: *
051: *     PREC_TYPE      (input) INTEGER
052: *     Specifies the intermediate precision to be used in refinement.
053: *     The value is defined by ILAPREC(P) where P is a CHARACTER and
054: *     P    = 'S':  Single
055: *          = 'D':  Double
056: *          = 'I':  Indigenous
057: *          = 'X', 'E':  Extra
058: *
059: *     UPLO    (input) CHARACTER*1
060: *       = 'U':  Upper triangle of A is stored;
061: *       = 'L':  Lower triangle of A is stored.
062: *
063: *     N              (input) INTEGER
064: *     The number of linear equations, i.e., the order of the
065: *     matrix A.  N >= 0.
066: *
067: *     NRHS           (input) INTEGER
068: *     The number of right-hand-sides, i.e., the number of columns of the
069: *     matrix B.
070: *
071: *     A              (input) COMPLEX array, dimension (LDA,N)
072: *     On entry, the N-by-N matrix A.
073: *
074: *     LDA            (input) INTEGER
075: *     The leading dimension of the array A.  LDA >= max(1,N).
076: *
077: *     AF             (input) COMPLEX array, dimension (LDAF,N)
078: *     The block diagonal matrix D and the multipliers used to
079: *     obtain the factor U or L as computed by CHETRF.
080: *
081: *     LDAF           (input) INTEGER
082: *     The leading dimension of the array AF.  LDAF >= max(1,N).
083: *
084: *     IPIV           (input) INTEGER array, dimension (N)
085: *     Details of the interchanges and the block structure of D
086: *     as determined by CHETRF.
087: *
088: *     COLEQU         (input) LOGICAL
089: *     If .TRUE. then column equilibration was done to A before calling
090: *     this routine. This is needed to compute the solution and error
091: *     bounds correctly.
092: *
093: *     C              (input) REAL array, dimension (N)
094: *     The column scale factors for A. If COLEQU = .FALSE., C
095: *     is not accessed. If C is input, each element of C should be a power
096: *     of the radix to ensure a reliable solution and error estimates.
097: *     Scaling by powers of the radix does not cause rounding errors unless
098: *     the result underflows or overflows. Rounding errors during scaling
099: *     lead to refining with a matrix that is not equivalent to the
100: *     input matrix, producing error estimates that may not be
101: *     reliable.
102: *
103: *     B              (input) COMPLEX array, dimension (LDB,NRHS)
104: *     The right-hand-side matrix B.
105: *
106: *     LDB            (input) INTEGER
107: *     The leading dimension of the array B.  LDB >= max(1,N).
108: *
109: *     Y              (input/output) COMPLEX array, dimension
110: *                    (LDY,NRHS)
111: *     On entry, the solution matrix X, as computed by CHETRS.
112: *     On exit, the improved solution matrix Y.
113: *
114: *     LDY            (input) INTEGER
115: *     The leading dimension of the array Y.  LDY >= max(1,N).
116: *
117: *     BERR_OUT       (output) REAL array, dimension (NRHS)
118: *     On exit, BERR_OUT(j) contains the componentwise relative backward
119: *     error for right-hand-side j from the formula
120: *         max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
121: *     where abs(Z) is the componentwise absolute value of the matrix
122: *     or vector Z. This is computed by CLA_LIN_BERR.
123: *
124: *     N_NORMS        (input) INTEGER
125: *     Determines which error bounds to return (see ERR_BNDS_NORM
126: *     and ERR_BNDS_COMP).
127: *     If N_NORMS >= 1 return normwise error bounds.
128: *     If N_NORMS >= 2 return componentwise error bounds.
129: *
130: *     ERR_BNDS_NORM  (input/output) REAL array, dimension
131: *                    (NRHS, N_ERR_BNDS)
132: *     For each right-hand side, this array contains information about
133: *     various error bounds and condition numbers corresponding to the
134: *     normwise relative error, which is defined as follows:
135: *
136: *     Normwise relative error in the ith solution vector:
137: *             max_j (abs(XTRUE(j,i) - X(j,i)))
138: *            ------------------------------
139: *                  max_j abs(X(j,i))
140: *
141: *     The array is indexed by the type of error information as described
142: *     below. There currently are up to three pieces of information
143: *     returned.
144: *
145: *     The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
146: *     right-hand side.
147: *
148: *     The second index in ERR_BNDS_NORM(:,err) contains the following
149: *     three fields:
150: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
151: *              reciprocal condition number is less than the threshold
152: *              sqrt(n) * slamch('Epsilon').
153: *
154: *     err = 2 "Guaranteed" error bound: The estimated forward error,
155: *              almost certainly within a factor of 10 of the true error
156: *              so long as the next entry is greater than the threshold
157: *              sqrt(n) * slamch('Epsilon'). This error bound should only
158: *              be trusted if the previous boolean is true.
159: *
160: *     err = 3  Reciprocal condition number: Estimated normwise
161: *              reciprocal condition number.  Compared with the threshold
162: *              sqrt(n) * slamch('Epsilon') to determine if the error
163: *              estimate is "guaranteed". These reciprocal condition
164: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
165: *              appropriately scaled matrix Z.
166: *              Let Z = S*A, where S scales each row by a power of the
167: *              radix so all absolute row sums of Z are approximately 1.
168: *
169: *     This subroutine is only responsible for setting the second field
170: *     above.
171: *     See Lapack Working Note 165 for further details and extra
172: *     cautions.
173: *
174: *     ERR_BNDS_COMP  (input/output) REAL array, dimension
175: *                    (NRHS, N_ERR_BNDS)
176: *     For each right-hand side, this array contains information about
177: *     various error bounds and condition numbers corresponding to the
178: *     componentwise relative error, which is defined as follows:
179: *
180: *     Componentwise relative error in the ith solution vector:
181: *                    abs(XTRUE(j,i) - X(j,i))
182: *             max_j ----------------------
183: *                         abs(X(j,i))
184: *
185: *     The array is indexed by the right-hand side i (on which the
186: *     componentwise relative error depends), and the type of error
187: *     information as described below. There currently are up to three
188: *     pieces of information returned for each right-hand side. If
189: *     componentwise accuracy is not requested (PARAMS(3) = 0.0), then
190: *     ERR_BNDS_COMP is not accessed.  If N_ERR_BNDS .LT. 3, then at most
191: *     the first (:,N_ERR_BNDS) entries are returned.
192: *
193: *     The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
194: *     right-hand side.
195: *
196: *     The second index in ERR_BNDS_COMP(:,err) contains the following
197: *     three fields:
198: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
199: *              reciprocal condition number is less than the threshold
200: *              sqrt(n) * slamch('Epsilon').
201: *
202: *     err = 2 "Guaranteed" error bound: The estimated forward error,
203: *              almost certainly within a factor of 10 of the true error
204: *              so long as the next entry is greater than the threshold
205: *              sqrt(n) * slamch('Epsilon'). This error bound should only
206: *              be trusted if the previous boolean is true.
207: *
208: *     err = 3  Reciprocal condition number: Estimated componentwise
209: *              reciprocal condition number.  Compared with the threshold
210: *              sqrt(n) * slamch('Epsilon') to determine if the error
211: *              estimate is "guaranteed". These reciprocal condition
212: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
213: *              appropriately scaled matrix Z.
214: *              Let Z = S*(A*diag(x)), where x is the solution for the
215: *              current right-hand side and S scales each row of
216: *              A*diag(x) by a power of the radix so all absolute row
217: *              sums of Z are approximately 1.
218: *
219: *     This subroutine is only responsible for setting the second field
220: *     above.
221: *     See Lapack Working Note 165 for further details and extra
222: *     cautions.
223: *
224: *     RES            (input) COMPLEX array, dimension (N)
225: *     Workspace to hold the intermediate residual.
226: *
227: *     AYB            (input) REAL array, dimension (N)
228: *     Workspace.
229: *
230: *     DY             (input) COMPLEX array, dimension (N)
231: *     Workspace to hold the intermediate solution.
232: *
233: *     Y_TAIL         (input) COMPLEX array, dimension (N)
234: *     Workspace to hold the trailing bits of the intermediate solution.
235: *
236: *     RCOND          (input) REAL
237: *     Reciprocal scaled condition number.  This is an estimate of the
238: *     reciprocal Skeel condition number of the matrix A after
239: *     equilibration (if done).  If this is less than the machine
240: *     precision (in particular, if it is zero), the matrix is singular
241: *     to working precision.  Note that the error may still be small even
242: *     if this number is very small and the matrix appears ill-
243: *     conditioned.
244: *
245: *     ITHRESH        (input) INTEGER
246: *     The maximum number of residual computations allowed for
247: *     refinement. The default is 10. For 'aggressive' set to 100 to
248: *     permit convergence using approximate factorizations or
249: *     factorizations other than LU. If the factorization uses a
250: *     technique other than Gaussian elimination, the guarantees in
251: *     ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy.
252: *
253: *     RTHRESH        (input) REAL
254: *     Determines when to stop refinement if the error estimate stops
255: *     decreasing. Refinement will stop when the next solution no longer
256: *     satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is
257: *     the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The
258: *     default value is 0.5. For 'aggressive' set to 0.9 to permit
259: *     convergence on extremely ill-conditioned matrices. See LAWN 165
260: *     for more details.
261: *
262: *     DZ_UB          (input) REAL
263: *     Determines when to start considering componentwise convergence.
264: *     Componentwise convergence is only considered after each component
265: *     of the solution Y is stable, which we definte as the relative
266: *     change in each component being less than DZ_UB. The default value
267: *     is 0.25, requiring the first bit to be stable. See LAWN 165 for
268: *     more details.
269: *
270: *     IGNORE_CWISE   (input) LOGICAL
271: *     If .TRUE. then ignore componentwise convergence. Default value
272: *     is .FALSE..
273: *
274: *     INFO           (output) INTEGER
275: *       = 0:  Successful exit.
276: *       < 0:  if INFO = -i, the ith argument to CHETRS had an illegal
277: *             value
278: *
279: *  =====================================================================
280: *
281: *     .. Local Scalars ..
282:       INTEGER            UPLO2, CNT, I, J, X_STATE, Z_STATE,
283:      $                   Y_PREC_STATE
284:       REAL               YK, DYK, YMIN, NORMY, NORMX, NORMDX, DXRAT,
285:      $                   DZRAT, PREVNORMDX, PREV_DZ_Z, DXRATMAX,
286:      $                   DZRATMAX, DX_X, DZ_Z, FINAL_DX_X, FINAL_DZ_Z,
287:      $                   EPS, HUGEVAL, INCR_THRESH
288:       LOGICAL            INCR_PREC
289:       COMPLEX            ZDUM
290: *     ..
291: *     .. Parameters ..
292:       INTEGER            UNSTABLE_STATE, WORKING_STATE, CONV_STATE,
293:      $                   NOPROG_STATE, BASE_RESIDUAL, EXTRA_RESIDUAL,
294:      $                   EXTRA_Y
295:       PARAMETER          ( UNSTABLE_STATE = 0, WORKING_STATE = 1,
296:      $                   CONV_STATE = 2, NOPROG_STATE = 3 )
297:       PARAMETER          ( BASE_RESIDUAL = 0, EXTRA_RESIDUAL = 1,
298:      $                   EXTRA_Y = 2 )
299:       INTEGER            FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I
300:       INTEGER            RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I
301:       INTEGER            CMP_ERR_I, PIV_GROWTH_I
302:       PARAMETER          ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2,
303:      $                   BERR_I = 3 )
304:       PARAMETER          ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 )
305:       PARAMETER          ( CMP_RCOND_I = 7, CMP_ERR_I = 8,
306:      $                   PIV_GROWTH_I = 9 )
307:       INTEGER            LA_LINRX_ITREF_I, LA_LINRX_ITHRESH_I,
308:      $                   LA_LINRX_CWISE_I
309:       PARAMETER          ( LA_LINRX_ITREF_I = 1,
310:      $                   LA_LINRX_ITHRESH_I = 2 )
311:       PARAMETER          ( LA_LINRX_CWISE_I = 3 )
312:       INTEGER            LA_LINRX_TRUST_I, LA_LINRX_ERR_I,
313:      $                   LA_LINRX_RCOND_I
314:       PARAMETER          ( LA_LINRX_TRUST_I = 1, LA_LINRX_ERR_I = 2 )
315:       PARAMETER          ( LA_LINRX_RCOND_I = 3 )
316: *     ..
317: *     .. External Functions ..
318:       LOGICAL            LSAME
319:       EXTERNAL           ILAUPLO
320:       INTEGER            ILAUPLO
321: *     ..
322: *     .. External Subroutines ..
323:       EXTERNAL           CAXPY, CCOPY, CHETRS, CHEMV, BLAS_CHEMV_X,
324:      $                   BLAS_CHEMV2_X, CLA_HEAMV, CLA_WWADDW,
325:      $                   CLA_LIN_BERR
326:       REAL               SLAMCH
327: *     ..
328: *     .. Intrinsic Functions ..
329:       INTRINSIC          ABS, REAL, AIMAG, MAX, MIN
330: *     ..
331: *     .. Statement Functions ..
332:       REAL               CABS1
333: *     ..
334: *     .. Statement Function Definitions ..
335:       CABS1( ZDUM ) = ABS( REAL( ZDUM ) ) + ABS( AIMAG( ZDUM ) )
336: *     ..
337: *     .. Executable Statements ..
338: *
339:       IF (INFO.NE.0) RETURN
340:       EPS = SLAMCH( 'Epsilon' )
341:       HUGEVAL = SLAMCH( 'Overflow' )
342: *     Force HUGEVAL to Inf
343:       HUGEVAL = HUGEVAL * HUGEVAL
344: *     Using HUGEVAL may lead to spurious underflows.
345:       INCR_THRESH = REAL( N ) * EPS
346: 
347:       IF ( LSAME ( UPLO, 'L' ) ) THEN
348:          UPLO2 = ILAUPLO( 'L' )
349:       ELSE
350:          UPLO2 = ILAUPLO( 'U' )
351:       ENDIF
352: 
353:       DO J = 1, NRHS
354:          Y_PREC_STATE = EXTRA_RESIDUAL
355:          IF ( Y_PREC_STATE .EQ. EXTRA_Y ) THEN
356:             DO I = 1, N
357:                Y_TAIL( I ) = 0.0
358:             END DO
359:          END IF
360: 
361:          DXRAT = 0.0
362:          DXRATMAX = 0.0
363:          DZRAT = 0.0
364:          DZRATMAX = 0.0
365:          FINAL_DX_X = HUGEVAL
366:          FINAL_DZ_Z = HUGEVAL
367:          PREVNORMDX = HUGEVAL
368:          PREV_DZ_Z = HUGEVAL
369:          DZ_Z = HUGEVAL
370:          DX_X = HUGEVAL
371: 
372:          X_STATE = WORKING_STATE
373:          Z_STATE = UNSTABLE_STATE
374:          INCR_PREC = .FALSE.
375: 
376:          DO CNT = 1, ITHRESH
377: *
378: *         Compute residual RES = B_s - op(A_s) * Y,
379: *             op(A) = A, A**T, or A**H depending on TRANS (and type).
380: *
381:             CALL CCOPY( N, B( 1, J ), 1, RES, 1 )
382:             IF ( Y_PREC_STATE .EQ. BASE_RESIDUAL ) THEN
383:                CALL CHEMV( UPLO, N, CMPLX(-1.0), A, LDA, Y( 1, J ), 1,
384:      $              CMPLX(1.0), RES, 1 )
385:             ELSE IF ( Y_PREC_STATE .EQ. EXTRA_RESIDUAL ) THEN
386:                CALL BLAS_CHEMV_X( UPLO2, N, CMPLX(-1.0), A, LDA,
387:      $              Y( 1, J ), 1, CMPLX(1.0), RES, 1, PREC_TYPE)
388:             ELSE
389:                CALL BLAS_CHEMV2_X(UPLO2, N, CMPLX(-1.0), A, LDA,
390:      $              Y(1, J), Y_TAIL, 1, CMPLX(1.0), RES, 1, PREC_TYPE)
391:             END IF
392: 
393: !         XXX: RES is no longer needed.
394:             CALL CCOPY( N, RES, 1, DY, 1 )
395:             CALL CHETRS( UPLO, N, NRHS, AF, LDAF, IPIV, DY, N, INFO )
396: *
397: *         Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
398: *
399:             NORMX = 0.0
400:             NORMY = 0.0
401:             NORMDX = 0.0
402:             DZ_Z = 0.0
403:             YMIN = HUGEVAL
404: 
405:             DO I = 1, N
406:                YK = CABS1( Y( I, J ) )
407:                DYK = CABS1( DY( I ) )
408: 
409:                IF (YK .NE. 0.0) THEN
410:                   DZ_Z = MAX( DZ_Z, DYK / YK )
411:                ELSE IF ( DYK .NE. 0.0 ) THEN
412:                   DZ_Z = HUGEVAL
413:                END IF
414: 
415:                YMIN = MIN( YMIN, YK )
416: 
417:                NORMY = MAX( NORMY, YK )
418: 
419:                IF ( COLEQU ) THEN
420:                   NORMX = MAX( NORMX, YK * C( I ) )
421:                   NORMDX = MAX( NORMDX, DYK * C( I ) )
422:                ELSE
423:                   NORMX = NORMY
424:                   NORMDX = MAX( NORMDX, DYK )
425:                END IF
426:             END DO
427: 
428:             IF ( NORMX .NE. 0.0 ) THEN
429:                DX_X = NORMDX / NORMX
430:             ELSE IF ( NORMDX .EQ. 0.0 ) THEN
431:                DX_X = 0.0
432:             ELSE
433:                DX_X = HUGEVAL
434:             END IF
435: 
436:             DXRAT = NORMDX / PREVNORMDX
437:             DZRAT = DZ_Z / PREV_DZ_Z
438: *
439: *         Check termination criteria.
440: *
441:             IF ( YMIN*RCOND .LT. INCR_THRESH*NORMY
442:      $           .AND. Y_PREC_STATE .LT. EXTRA_Y )
443:      $           INCR_PREC = .TRUE.
444: 
445:             IF ( X_STATE .EQ. NOPROG_STATE .AND. DXRAT .LE. RTHRESH )
446:      $           X_STATE = WORKING_STATE
447:             IF ( X_STATE .EQ. WORKING_STATE ) THEN
448:                IF ( DX_X .LE. EPS ) THEN
449:                   X_STATE = CONV_STATE
450:                ELSE IF ( DXRAT .GT. RTHRESH ) THEN
451:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
452:                      INCR_PREC = .TRUE.
453:                   ELSE
454:                      X_STATE = NOPROG_STATE
455:                   END IF
456:                ELSE
457:                   IF (DXRAT .GT. DXRATMAX) DXRATMAX = DXRAT
458:                END IF
459:                IF ( X_STATE .GT. WORKING_STATE ) FINAL_DX_X = DX_X
460:             END IF
461: 
462:             IF ( Z_STATE .EQ. UNSTABLE_STATE .AND. DZ_Z .LE. DZ_UB )
463:      $           Z_STATE = WORKING_STATE
464:             IF ( Z_STATE .EQ. NOPROG_STATE .AND. DZRAT .LE. RTHRESH )
465:      $           Z_STATE = WORKING_STATE
466:             IF ( Z_STATE .EQ. WORKING_STATE ) THEN
467:                IF ( DZ_Z .LE. EPS ) THEN
468:                   Z_STATE = CONV_STATE
469:                ELSE IF ( DZ_Z .GT. DZ_UB ) THEN
470:                   Z_STATE = UNSTABLE_STATE
471:                   DZRATMAX = 0.0
472:                   FINAL_DZ_Z = HUGEVAL
473:                ELSE IF ( DZRAT .GT. RTHRESH ) THEN
474:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
475:                      INCR_PREC = .TRUE.
476:                   ELSE
477:                      Z_STATE = NOPROG_STATE
478:                   END IF
479:                ELSE
480:                   IF ( DZRAT .GT. DZRATMAX ) DZRATMAX = DZRAT
481:                END IF
482:                IF ( Z_STATE .GT. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
483:             END IF
484: 
485:             IF ( X_STATE.NE.WORKING_STATE.AND.
486:      $           ( IGNORE_CWISE.OR.Z_STATE.NE.WORKING_STATE ) )
487:      $           GOTO 666
488: 
489:             IF ( INCR_PREC ) THEN
490:                INCR_PREC = .FALSE.
491:                Y_PREC_STATE = Y_PREC_STATE + 1
492:                DO I = 1, N
493:                   Y_TAIL( I ) = 0.0
494:                END DO
495:             END IF
496: 
497:             PREVNORMDX = NORMDX
498:             PREV_DZ_Z = DZ_Z
499: *
500: *           Update soluton.
501: *
502:             IF ( Y_PREC_STATE .LT. EXTRA_Y ) THEN
503:                CALL CAXPY( N, CMPLX(1.0), DY, 1, Y(1,J), 1 )
504:             ELSE
505:                CALL CLA_WWADDW( N, Y(1,J), Y_TAIL, DY )
506:             END IF
507: 
508:          END DO
509: *        Target of "IF (Z_STOP .AND. X_STOP)".  Sun's f77 won't EXIT.
510:  666     CONTINUE
511: *
512: *     Set final_* when cnt hits ithresh.
513: *
514:          IF ( X_STATE .EQ. WORKING_STATE ) FINAL_DX_X = DX_X
515:          IF ( Z_STATE .EQ. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
516: *
517: *     Compute error bounds.
518: *
519:          IF ( N_NORMS .GE. 1 ) THEN
520:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) =
521:      $           FINAL_DX_X / (1 - DXRATMAX)
522:          END IF
523:          IF (N_NORMS .GE. 2) THEN
524:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) =
525:      $           FINAL_DZ_Z / (1 - DZRATMAX)
526:          END IF
527: *
528: *     Compute componentwise relative backward error from formula
529: *         max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
530: *     where abs(Z) is the componentwise absolute value of the matrix
531: *     or vector Z.
532: *
533: *         Compute residual RES = B_s - op(A_s) * Y,
534: *             op(A) = A, A**T, or A**H depending on TRANS (and type).
535: *
536:          CALL CCOPY( N, B( 1, J ), 1, RES, 1 )
537:          CALL CHEMV( UPLO, N, CMPLX(-1.0), A, LDA, Y(1,J), 1,
538:      $        CMPLX(1.0), RES, 1 )
539: 
540:          DO I = 1, N
541:             AYB( I ) = CABS1( B( I, J ) )
542:          END DO
543: *
544: *     Compute abs(op(A_s))*abs(Y) + abs(B_s).
545: *
546:          CALL CLA_HEAMV( UPLO2, N, 1.0,
547:      $        A, LDA, Y(1, J), 1, 1.0, AYB, 1 )
548: 
549:          CALL CLA_LIN_BERR( N, N, 1, RES, AYB, BERR_OUT( J ) )
550: *
551: *     End of loop for each RHS.
552: *
553:       END DO
554: *
555:       RETURN
556:       END
557: