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