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