001:       SUBROUTINE SLA_GERFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, NRHS, A,
002:      $                                LDA, AF, LDAF, IPIV, COLEQU, C, B,
003:      $                                LDB, 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:      $                   TRANS_TYPE, N_NORMS, ITHRESH
022:       LOGICAL            COLEQU, IGNORE_CWISE
023:       REAL               RTHRESH, DZ_UB
024: *     ..
025: *     .. Array Arguments ..
026:       INTEGER            IPIV( * )
027:       REAL               A( LDA, * ), AF( LDAF, * ), B( LDB, * ),
028:      $                   Y( LDY, * ), RES( * ), DY( * ), Y_TAIL( * )
029:       REAL               C( * ), AYB( * ), RCOND, BERR_OUT( * ),
030:      $                   ERR_BNDS_NORM( NRHS, * ),
031:      $                   ERR_BNDS_COMP( NRHS, * )
032: *     ..
033: *
034: *  Purpose
035: *  =======
036: *
037: *  SLA_GERFSX_EXTENDED improves the computed solution to a system of
038: *  linear equations by performing extra-precise iterative refinement
039: *  and provides error bounds and backward error estimates for the solution.
040: *  This subroutine is called by SGERFSX to perform iterative refinement.
041: *  In addition to normwise error bound, the code provides maximum
042: *  componentwise error bound if possible. See comments for ERR_BNDS_NORM
043: *  and ERR_BNDS_COMP for details of the error bounds. Note that this
044: *  subroutine is only resonsible for setting the second fields of
045: *  ERR_BNDS_NORM and ERR_BNDS_COMP.
046: *
047: *  Arguments
048: *  =========
049: *
050: *     PREC_TYPE      (input) INTEGER
051: *     Specifies the intermediate precision to be used in refinement.
052: *     The value is defined by ILAPREC(P) where P is a CHARACTER and
053: *     P    = 'S':  Single
054: *          = 'D':  Double
055: *          = 'I':  Indigenous
056: *          = 'X', 'E':  Extra
057: *
058: *     TRANS_TYPE     (input) INTEGER
059: *     Specifies the transposition operation on A.
060: *     The value is defined by ILATRANS(T) where T is a CHARACTER and
061: *     T    = 'N':  No transpose
062: *          = 'T':  Transpose
063: *          = 'C':  Conjugate transpose
064: *
065: *     N              (input) INTEGER
066: *     The number of linear equations, i.e., the order of the
067: *     matrix A.  N >= 0.
068: *
069: *     NRHS           (input) INTEGER
070: *     The number of right-hand-sides, i.e., the number of columns of the
071: *     matrix B.
072: *
073: *     A              (input) REAL array, dimension (LDA,N)
074: *     On entry, the N-by-N matrix A.
075: *
076: *     LDA            (input) INTEGER
077: *     The leading dimension of the array A.  LDA >= max(1,N).
078: *
079: *     AF             (input) REAL array, dimension (LDAF,N)
080: *     The factors L and U from the factorization
081: *     A = P*L*U as computed by SGETRF.
082: *
083: *     LDAF           (input) INTEGER
084: *     The leading dimension of the array AF.  LDAF >= max(1,N).
085: *
086: *     IPIV           (input) INTEGER array, dimension (N)
087: *     The pivot indices from the factorization A = P*L*U
088: *     as computed by SGETRF; row i of the matrix was interchanged
089: *     with row IPIV(i).
090: *
091: *     COLEQU         (input) LOGICAL
092: *     If .TRUE. then column equilibration was done to A before calling
093: *     this routine. This is needed to compute the solution and error
094: *     bounds correctly.
095: *
096: *     C              (input) REAL array, dimension (N)
097: *     The column scale factors for A. If COLEQU = .FALSE., C
098: *     is not accessed. If C is input, each element of C should be a power
099: *     of the radix to ensure a reliable solution and error estimates.
100: *     Scaling by powers of the radix does not cause rounding errors unless
101: *     the result underflows or overflows. Rounding errors during scaling
102: *     lead to refining with a matrix that is not equivalent to the
103: *     input matrix, producing error estimates that may not be
104: *     reliable.
105: *
106: *     B              (input) REAL array, dimension (LDB,NRHS)
107: *     The right-hand-side matrix B.
108: *
109: *     LDB            (input) INTEGER
110: *     The leading dimension of the array B.  LDB >= max(1,N).
111: *
112: *     Y              (input/output) REAL array, dimension (LDY,NRHS)
113: *     On entry, the solution matrix X, as computed by SGETRS.
114: *     On exit, the improved solution matrix Y.
115: *
116: *     LDY            (input) INTEGER
117: *     The leading dimension of the array Y.  LDY >= max(1,N).
118: *
119: *     BERR_OUT       (output) REAL array, dimension (NRHS)
120: *     On exit, BERR_OUT(j) contains the componentwise relative backward
121: *     error for right-hand-side j from the formula
122: *         max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
123: *     where abs(Z) is the componentwise absolute value of the matrix
124: *     or vector Z. This is computed by SLA_LIN_BERR.
125: *
126: *     N_NORMS        (input) INTEGER
127: *     Determines which error bounds to return (see ERR_BNDS_NORM
128: *     and ERR_BNDS_COMP).
129: *     If N_NORMS >= 1 return normwise error bounds.
130: *     If N_NORMS >= 2 return componentwise error bounds.
131: *
132: *     ERR_BNDS_NORM  (input/output) REAL array, dimension (NRHS, N_ERR_BNDS)
133: *     For each right-hand side, this array contains information about
134: *     various error bounds and condition numbers corresponding to the
135: *     normwise relative error, which is defined as follows:
136: *
137: *     Normwise relative error in the ith solution vector:
138: *             max_j (abs(XTRUE(j,i) - X(j,i)))
139: *            ------------------------------
140: *                  max_j abs(X(j,i))
141: *
142: *     The array is indexed by the type of error information as described
143: *     below. There currently are up to three pieces of information
144: *     returned.
145: *
146: *     The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
147: *     right-hand side.
148: *
149: *     The second index in ERR_BNDS_NORM(:,err) contains the following
150: *     three fields:
151: *     err = 1 "Trust/don't trust" boolean. Trust the answer if the
152: *              reciprocal condition number is less than the threshold
153: *              sqrt(n) * slamch('Epsilon').
154: *
155: *     err = 2 "Guaranteed" error bound: The estimated forward error,
156: *              almost certainly within a factor of 10 of the true error
157: *              so long as the next entry is greater than the threshold
158: *              sqrt(n) * slamch('Epsilon'). This error bound should only
159: *              be trusted if the previous boolean is true.
160: *
161: *     err = 3  Reciprocal condition number: Estimated normwise
162: *              reciprocal condition number.  Compared with the threshold
163: *              sqrt(n) * slamch('Epsilon') to determine if the error
164: *              estimate is "guaranteed". These reciprocal condition
165: *              numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
166: *              appropriately scaled matrix Z.
167: *              Let Z = S*A, where S scales each row by a power of the
168: *              radix so all absolute row sums of Z are approximately 1.
169: *
170: *     This subroutine is only responsible for setting the second field
171: *     above.
172: *     See Lapack Working Note 165 for further details and extra
173: *     cautions.
174: *
175: *     ERR_BNDS_COMP  (input/output) REAL array, dimension (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) REAL array, dimension (N)
225: *     Workspace to hold the intermediate residual.
226: *
227: *     AYB            (input) REAL array, dimension (N)
228: *     Workspace. This can be the same workspace passed for Y_TAIL.
229: *
230: *     DY             (input) REAL array, dimension (N)
231: *     Workspace to hold the intermediate solution.
232: *
233: *     Y_TAIL         (input) REAL 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 SGETRS had an illegal
277: *             value
278: *
279: *  =====================================================================
280: *
281: *     .. Local Scalars ..
282:       CHARACTER          TRANS
283:       INTEGER            CNT, I, J, X_STATE, Z_STATE, 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: *     ..
290: *     .. Parameters ..
291:       INTEGER            UNSTABLE_STATE, WORKING_STATE, CONV_STATE,
292:      $                   NOPROG_STATE, BASE_RESIDUAL, EXTRA_RESIDUAL,
293:      $                   EXTRA_Y
294:       PARAMETER          ( UNSTABLE_STATE = 0, WORKING_STATE = 1,
295:      $                   CONV_STATE = 2, NOPROG_STATE = 3 )
296:       PARAMETER          ( BASE_RESIDUAL = 0, EXTRA_RESIDUAL = 1,
297:      $                   EXTRA_Y = 2 )
298:       INTEGER            FINAL_NRM_ERR_I, FINAL_CMP_ERR_I, BERR_I
299:       INTEGER            RCOND_I, NRM_RCOND_I, NRM_ERR_I, CMP_RCOND_I
300:       INTEGER            CMP_ERR_I, PIV_GROWTH_I
301:       PARAMETER          ( FINAL_NRM_ERR_I = 1, FINAL_CMP_ERR_I = 2,
302:      $                   BERR_I = 3 )
303:       PARAMETER          ( RCOND_I = 4, NRM_RCOND_I = 5, NRM_ERR_I = 6 )
304:       PARAMETER          ( CMP_RCOND_I = 7, CMP_ERR_I = 8,
305:      $                   PIV_GROWTH_I = 9 )
306:       INTEGER            LA_LINRX_ITREF_I, LA_LINRX_ITHRESH_I,
307:      $                   LA_LINRX_CWISE_I
308:       PARAMETER          ( LA_LINRX_ITREF_I = 1,
309:      $                   LA_LINRX_ITHRESH_I = 2 )
310:       PARAMETER          ( LA_LINRX_CWISE_I = 3 )
311:       INTEGER            LA_LINRX_TRUST_I, LA_LINRX_ERR_I,
312:      $                   LA_LINRX_RCOND_I
313:       PARAMETER          ( LA_LINRX_TRUST_I = 1, LA_LINRX_ERR_I = 2 )
314:       PARAMETER          ( LA_LINRX_RCOND_I = 3 )
315: *     ..
316: *     .. External Subroutines ..
317:       EXTERNAL           SAXPY, SCOPY, SGETRS, SGEMV, BLAS_SGEMV_X,
318:      $                   BLAS_SGEMV2_X, SLA_GEAMV, SLA_WWADDW, SLAMCH,
319:      $                   CHLA_TRANSTYPE, SLA_LIN_BERR
320:       REAL               SLAMCH
321:       CHARACTER          CHLA_TRANSTYPE
322: *     ..
323: *     .. Intrinsic Functions ..
324:       INTRINSIC          ABS, MAX, MIN
325: *     ..
326: *     .. Executable Statements ..
327: *
328:       IF ( INFO.NE.0 ) RETURN
329:       TRANS = CHLA_TRANSTYPE(TRANS_TYPE)
330:       EPS = SLAMCH( 'Epsilon' )
331:       HUGEVAL = SLAMCH( 'Overflow' )
332: *     Force HUGEVAL to Inf
333:       HUGEVAL = HUGEVAL * HUGEVAL
334: *     Using HUGEVAL may lead to spurious underflows.
335:       INCR_THRESH = REAL( N ) * EPS
336: *
337:       DO J = 1, NRHS
338:          Y_PREC_STATE = EXTRA_RESIDUAL
339:          IF ( Y_PREC_STATE .EQ. EXTRA_Y ) THEN
340:             DO I = 1, N
341:                Y_TAIL( I ) = 0.0
342:             END DO
343:          END IF
344: 
345:          DXRAT = 0.0
346:          DXRATMAX = 0.0
347:          DZRAT = 0.0
348:          DZRATMAX = 0.0
349:          FINAL_DX_X = HUGEVAL
350:          FINAL_DZ_Z = HUGEVAL
351:          PREVNORMDX = HUGEVAL
352:          PREV_DZ_Z = HUGEVAL
353:          DZ_Z = HUGEVAL
354:          DX_X = HUGEVAL
355: 
356:          X_STATE = WORKING_STATE
357:          Z_STATE = UNSTABLE_STATE
358:          INCR_PREC = .FALSE.
359: 
360:          DO CNT = 1, ITHRESH
361: *
362: *         Compute residual RES = B_s - op(A_s) * Y,
363: *             op(A) = A, A**T, or A**H depending on TRANS (and type).
364: *
365:             CALL SCOPY( N, B( 1, J ), 1, RES, 1 )
366:             IF ( Y_PREC_STATE .EQ. BASE_RESIDUAL ) THEN
367:                CALL SGEMV( TRANS, N, N, -1.0, A, LDA, Y( 1, J ), 1,
368:      $              1.0, RES, 1 )
369:             ELSE IF ( Y_PREC_STATE .EQ. EXTRA_RESIDUAL ) THEN
370:                CALL BLAS_SGEMV_X( TRANS_TYPE, N, N, -1.0, A, LDA,
371:      $              Y( 1, J ), 1, 1.0, RES, 1, PREC_TYPE )
372:             ELSE
373:                CALL BLAS_SGEMV2_X( TRANS_TYPE, N, N, -1.0, A, LDA,
374:      $              Y( 1, J ), Y_TAIL, 1, 1.0, RES, 1, PREC_TYPE )
375:             END IF
376: 
377: !        XXX: RES is no longer needed.
378:             CALL SCOPY( N, RES, 1, DY, 1 )
379:             CALL SGETRS( TRANS, N, 1, AF, LDAF, IPIV, DY, N, INFO )
380: *
381: *         Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
382: *
383:             NORMX = 0.0
384:             NORMY = 0.0
385:             NORMDX = 0.0
386:             DZ_Z = 0.0
387:             YMIN = HUGEVAL
388: *
389:             DO I = 1, N
390:                YK = ABS( Y( I, J ) )
391:                DYK = ABS( DY( I ) )
392: 
393:                IF ( YK .NE. 0.0 ) THEN
394:                   DZ_Z = MAX( DZ_Z, DYK / YK )
395:                ELSE IF ( DYK .NE. 0.0 ) THEN
396:                   DZ_Z = HUGEVAL
397:                END IF
398: 
399:                YMIN = MIN( YMIN, YK )
400: 
401:                NORMY = MAX( NORMY, YK )
402: 
403:                IF ( COLEQU ) THEN
404:                   NORMX = MAX( NORMX, YK * C( I ) )
405:                   NORMDX = MAX( NORMDX, DYK * C( I ) )
406:                ELSE
407:                   NORMX = NORMY
408:                   NORMDX = MAX( NORMDX, DYK )
409:                END IF
410:             END DO
411: 
412:             IF ( NORMX .NE. 0.0 ) THEN
413:                DX_X = NORMDX / NORMX
414:             ELSE IF ( NORMDX .EQ. 0.0 ) THEN
415:                DX_X = 0.0
416:             ELSE
417:                DX_X = HUGEVAL
418:             END IF
419: 
420:             DXRAT = NORMDX / PREVNORMDX
421:             DZRAT = DZ_Z / PREV_DZ_Z
422: *
423: *         Check termination criteria
424: *
425:             IF (.NOT.IGNORE_CWISE
426:      $           .AND. YMIN*RCOND .LT. INCR_THRESH*NORMY
427:      $           .AND. Y_PREC_STATE .LT. EXTRA_Y)
428:      $           INCR_PREC = .TRUE.
429: 
430:             IF ( X_STATE .EQ. NOPROG_STATE .AND. DXRAT .LE. RTHRESH )
431:      $           X_STATE = WORKING_STATE
432:             IF ( X_STATE .EQ. WORKING_STATE ) THEN
433:                IF ( DX_X .LE. EPS ) THEN
434:                   X_STATE = CONV_STATE
435:                ELSE IF ( DXRAT .GT. RTHRESH ) THEN
436:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
437:                      INCR_PREC = .TRUE.
438:                   ELSE
439:                      X_STATE = NOPROG_STATE
440:                   END IF
441:                ELSE
442:                   IF ( DXRAT .GT. DXRATMAX ) DXRATMAX = DXRAT
443:                END IF
444:                IF ( X_STATE .GT. WORKING_STATE ) FINAL_DX_X = DX_X
445:             END IF
446: 
447:             IF ( Z_STATE .EQ. UNSTABLE_STATE .AND. DZ_Z .LE. DZ_UB )
448:      $           Z_STATE = WORKING_STATE
449:             IF ( Z_STATE .EQ. NOPROG_STATE .AND. DZRAT .LE. RTHRESH )
450:      $           Z_STATE = WORKING_STATE
451:             IF ( Z_STATE .EQ. WORKING_STATE ) THEN
452:                IF ( DZ_Z .LE. EPS ) THEN
453:                   Z_STATE = CONV_STATE
454:                ELSE IF ( DZ_Z .GT. DZ_UB ) THEN
455:                   Z_STATE = UNSTABLE_STATE
456:                   DZRATMAX = 0.0
457:                   FINAL_DZ_Z = HUGEVAL
458:                ELSE IF ( DZRAT .GT. RTHRESH ) THEN
459:                   IF ( Y_PREC_STATE .NE. EXTRA_Y ) THEN
460:                      INCR_PREC = .TRUE.
461:                   ELSE
462:                      Z_STATE = NOPROG_STATE
463:                   END IF
464:                ELSE
465:                   IF ( DZRAT .GT. DZRATMAX ) DZRATMAX = DZRAT
466:                END IF
467:                IF ( Z_STATE .GT. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
468:             END IF
469: *
470: *           Exit if both normwise and componentwise stopped working,
471: *           but if componentwise is unstable, let it go at least two
472: *           iterations.
473: *
474:             IF ( X_STATE.NE.WORKING_STATE ) THEN
475:                IF ( IGNORE_CWISE) GOTO 666
476:                IF ( Z_STATE.EQ.NOPROG_STATE .OR. Z_STATE.EQ.CONV_STATE )
477:      $              GOTO 666
478:                IF ( Z_STATE.EQ.UNSTABLE_STATE .AND. CNT.GT.1 ) GOTO 666
479:             END IF
480: 
481:             IF ( INCR_PREC ) THEN
482:                INCR_PREC = .FALSE.
483:                Y_PREC_STATE = Y_PREC_STATE + 1
484:                DO I = 1, N
485:                   Y_TAIL( I ) = 0.0
486:                END DO
487:             END IF
488: 
489:             PREVNORMDX = NORMDX
490:             PREV_DZ_Z = DZ_Z
491: *
492: *           Update soluton.
493: *
494:             IF ( Y_PREC_STATE .LT. EXTRA_Y ) THEN
495:                CALL SAXPY( N, 1.0, DY, 1, Y( 1, J ), 1 )
496:             ELSE
497:                CALL SLA_WWADDW( N, Y( 1, J ), Y_TAIL, DY )
498:             END IF
499: 
500:          END DO
501: *        Target of "IF (Z_STOP .AND. X_STOP)".  Sun's f77 won't EXIT.
502:  666     CONTINUE
503: *
504: *     Set final_* when cnt hits ithresh.
505: *
506:          IF ( X_STATE .EQ. WORKING_STATE ) FINAL_DX_X = DX_X
507:          IF ( Z_STATE .EQ. WORKING_STATE ) FINAL_DZ_Z = DZ_Z
508: *
509: *     Compute error bounds
510: *
511:          IF (N_NORMS .GE. 1) THEN
512:             ERR_BNDS_NORM( J, LA_LINRX_ERR_I ) =
513:      $           FINAL_DX_X / (1 - DXRATMAX)
514:          END IF
515:          IF ( N_NORMS .GE. 2 ) THEN
516:             ERR_BNDS_COMP( J, LA_LINRX_ERR_I ) =
517:      $           FINAL_DZ_Z / (1 - DZRATMAX)
518:          END IF
519: *
520: *     Compute componentwise relative backward error from formula
521: *         max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
522: *     where abs(Z) is the componentwise absolute value of the matrix
523: *     or vector Z.
524: *
525: *         Compute residual RES = B_s - op(A_s) * Y,
526: *             op(A) = A, A**T, or A**H depending on TRANS (and type).
527: *
528:          CALL SCOPY( N, B( 1, J ), 1, RES, 1 )
529:          CALL SGEMV( TRANS, N, N, -1.0, A, LDA, Y(1,J), 1, 1.0, RES, 1 )
530: 
531:          DO I = 1, N
532:             AYB( I ) = ABS( B( I, J ) )
533:          END DO
534: *
535: *     Compute abs(op(A_s))*abs(Y) + abs(B_s).
536: *
537:          CALL SLA_GEAMV ( TRANS_TYPE, N, N, 1.0,
538:      $        A, LDA, Y(1, J), 1, 1.0, AYB, 1 )
539: 
540:          CALL SLA_LIN_BERR ( N, N, 1, RES, AYB, BERR_OUT( J ) )
541: *
542: *     End of loop for each RHS.
543: *
544:       END DO
545: *
546:       RETURN
547:       END
548: