LAPACK  3.4.2
LAPACK: Linear Algebra PACKage
 All Files Functions Groups
sla_gbrfsx_extended.f
Go to the documentation of this file.
1 *> \brief \b SLA_GBRFSX_EXTENDED improves the computed solution to a system of linear equations for general banded matrices by performing extra-precise iterative refinement and provides error bounds and backward error estimates for the solution.
2 *
3 * =========== DOCUMENTATION ===========
4 *
5 * Online html documentation available at
6 * http://www.netlib.org/lapack/explore-html/
7 *
8 *> \htmlonly
9 *> Download SLA_GBRFSX_EXTENDED + dependencies
10 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.tgz?format=tgz&filename=/lapack/lapack_routine/sla_gbrfsx_extended.f">
11 *> [TGZ]</a>
12 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.zip?format=zip&filename=/lapack/lapack_routine/sla_gbrfsx_extended.f">
13 *> [ZIP]</a>
14 *> <a href="http://www.netlib.org/cgi-bin/netlibfiles.txt?format=txt&filename=/lapack/lapack_routine/sla_gbrfsx_extended.f">
15 *> [TXT]</a>
16 *> \endhtmlonly
17 *
18 * Definition:
19 * ===========
20 *
21 * SUBROUTINE SLA_GBRFSX_EXTENDED( PREC_TYPE, TRANS_TYPE, N, KL, KU,
22 * NRHS, AB, LDAB, AFB, LDAFB, IPIV,
23 * COLEQU, C, B, LDB, Y, LDY,
24 * BERR_OUT, N_NORMS, ERR_BNDS_NORM,
25 * ERR_BNDS_COMP, RES, AYB, DY,
26 * Y_TAIL, RCOND, ITHRESH, RTHRESH,
27 * DZ_UB, IGNORE_CWISE, INFO )
28 *
29 * .. Scalar Arguments ..
30 * INTEGER INFO, LDAB, LDAFB, LDB, LDY, N, KL, KU, NRHS,
31 * $ PREC_TYPE, TRANS_TYPE, N_NORMS, ITHRESH
32 * LOGICAL COLEQU, IGNORE_CWISE
33 * REAL RTHRESH, DZ_UB
34 * ..
35 * .. Array Arguments ..
36 * INTEGER IPIV( * )
37 * REAL AB( LDAB, * ), AFB( LDAFB, * ), B( LDB, * ),
38 * $ Y( LDY, * ), RES(*), DY(*), Y_TAIL(*)
39 * REAL C( * ), AYB(*), RCOND, BERR_OUT(*),
40 * $ ERR_BNDS_NORM( NRHS, * ),
41 * $ ERR_BNDS_COMP( NRHS, * )
42 * ..
43 *
44 *
45 *> \par Purpose:
46 * =============
47 *>
48 *> \verbatim
49 *>
50 *> SLA_GBRFSX_EXTENDED improves the computed solution to a system of
51 *> linear equations by performing extra-precise iterative refinement
52 *> and provides error bounds and backward error estimates for the solution.
53 *> This subroutine is called by SGBRFSX to perform iterative refinement.
54 *> In addition to normwise error bound, the code provides maximum
55 *> componentwise error bound if possible. See comments for ERR_BNDS_NORM
56 *> and ERR_BNDS_COMP for details of the error bounds. Note that this
57 *> subroutine is only resonsible for setting the second fields of
58 *> ERR_BNDS_NORM and ERR_BNDS_COMP.
59 *> \endverbatim
60 *
61 * Arguments:
62 * ==========
63 *
64 *> \param[in] PREC_TYPE
65 *> \verbatim
66 *> PREC_TYPE is INTEGER
67 *> Specifies the intermediate precision to be used in refinement.
68 *> The value is defined by ILAPREC(P) where P is a CHARACTER and
69 *> P = 'S': Single
70 *> = 'D': Double
71 *> = 'I': Indigenous
72 *> = 'X', 'E': Extra
73 *> \endverbatim
74 *>
75 *> \param[in] TRANS_TYPE
76 *> \verbatim
77 *> TRANS_TYPE is INTEGER
78 *> Specifies the transposition operation on A.
79 *> The value is defined by ILATRANS(T) where T is a CHARACTER and
80 *> T = 'N': No transpose
81 *> = 'T': Transpose
82 *> = 'C': Conjugate transpose
83 *> \endverbatim
84 *>
85 *> \param[in] N
86 *> \verbatim
87 *> N is INTEGER
88 *> The number of linear equations, i.e., the order of the
89 *> matrix A. N >= 0.
90 *> \endverbatim
91 *>
92 *> \param[in] KL
93 *> \verbatim
94 *> KL is INTEGER
95 *> The number of subdiagonals within the band of A. KL >= 0.
96 *> \endverbatim
97 *>
98 *> \param[in] KU
99 *> \verbatim
100 *> KU is INTEGER
101 *> The number of superdiagonals within the band of A. KU >= 0
102 *> \endverbatim
103 *>
104 *> \param[in] NRHS
105 *> \verbatim
106 *> NRHS is INTEGER
107 *> The number of right-hand-sides, i.e., the number of columns of the
108 *> matrix B.
109 *> \endverbatim
110 *>
111 *> \param[in] AB
112 *> \verbatim
113 *> AB is REAL array, dimension (LDAB,N)
114 *> On entry, the N-by-N matrix AB.
115 *> \endverbatim
116 *>
117 *> \param[in] LDAB
118 *> \verbatim
119 *> LDAB is INTEGER
120 *> The leading dimension of the array AB. LDAB >= max(1,N).
121 *> \endverbatim
122 *>
123 *> \param[in] AFB
124 *> \verbatim
125 *> AFB is REAL array, dimension (LDAFB,N)
126 *> The factors L and U from the factorization
127 *> A = P*L*U as computed by SGBTRF.
128 *> \endverbatim
129 *>
130 *> \param[in] LDAFB
131 *> \verbatim
132 *> LDAFB is INTEGER
133 *> The leading dimension of the array AF. LDAFB >= max(1,N).
134 *> \endverbatim
135 *>
136 *> \param[in] IPIV
137 *> \verbatim
138 *> IPIV is INTEGER array, dimension (N)
139 *> The pivot indices from the factorization A = P*L*U
140 *> as computed by SGBTRF; row i of the matrix was interchanged
141 *> with row IPIV(i).
142 *> \endverbatim
143 *>
144 *> \param[in] COLEQU
145 *> \verbatim
146 *> COLEQU is LOGICAL
147 *> If .TRUE. then column equilibration was done to A before calling
148 *> this routine. This is needed to compute the solution and error
149 *> bounds correctly.
150 *> \endverbatim
151 *>
152 *> \param[in] C
153 *> \verbatim
154 *> C is REAL array, dimension (N)
155 *> The column scale factors for A. If COLEQU = .FALSE., C
156 *> is not accessed. If C is input, each element of C should be a power
157 *> of the radix to ensure a reliable solution and error estimates.
158 *> Scaling by powers of the radix does not cause rounding errors unless
159 *> the result underflows or overflows. Rounding errors during scaling
160 *> lead to refining with a matrix that is not equivalent to the
161 *> input matrix, producing error estimates that may not be
162 *> reliable.
163 *> \endverbatim
164 *>
165 *> \param[in] B
166 *> \verbatim
167 *> B is REAL array, dimension (LDB,NRHS)
168 *> The right-hand-side matrix B.
169 *> \endverbatim
170 *>
171 *> \param[in] LDB
172 *> \verbatim
173 *> LDB is INTEGER
174 *> The leading dimension of the array B. LDB >= max(1,N).
175 *> \endverbatim
176 *>
177 *> \param[in,out] Y
178 *> \verbatim
179 *> Y is REAL array, dimension (LDY,NRHS)
180 *> On entry, the solution matrix X, as computed by SGBTRS.
181 *> On exit, the improved solution matrix Y.
182 *> \endverbatim
183 *>
184 *> \param[in] LDY
185 *> \verbatim
186 *> LDY is INTEGER
187 *> The leading dimension of the array Y. LDY >= max(1,N).
188 *> \endverbatim
189 *>
190 *> \param[out] BERR_OUT
191 *> \verbatim
192 *> BERR_OUT is REAL array, dimension (NRHS)
193 *> On exit, BERR_OUT(j) contains the componentwise relative backward
194 *> error for right-hand-side j from the formula
195 *> max(i) ( abs(RES(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
196 *> where abs(Z) is the componentwise absolute value of the matrix
197 *> or vector Z. This is computed by SLA_LIN_BERR.
198 *> \endverbatim
199 *>
200 *> \param[in] N_NORMS
201 *> \verbatim
202 *> N_NORMS is INTEGER
203 *> Determines which error bounds to return (see ERR_BNDS_NORM
204 *> and ERR_BNDS_COMP).
205 *> If N_NORMS >= 1 return normwise error bounds.
206 *> If N_NORMS >= 2 return componentwise error bounds.
207 *> \endverbatim
208 *>
209 *> \param[in,out] ERR_BNDS_NORM
210 *> \verbatim
211 *> ERR_BNDS_NORM is REAL array, dimension
212 *> (NRHS, N_ERR_BNDS)
213 *> For each right-hand side, this array contains information about
214 *> various error bounds and condition numbers corresponding to the
215 *> normwise relative error, which is defined as follows:
216 *>
217 *> Normwise relative error in the ith solution vector:
218 *> max_j (abs(XTRUE(j,i) - X(j,i)))
219 *> ------------------------------
220 *> max_j abs(X(j,i))
221 *>
222 *> The array is indexed by the type of error information as described
223 *> below. There currently are up to three pieces of information
224 *> returned.
225 *>
226 *> The first index in ERR_BNDS_NORM(i,:) corresponds to the ith
227 *> right-hand side.
228 *>
229 *> The second index in ERR_BNDS_NORM(:,err) contains the following
230 *> three fields:
231 *> err = 1 "Trust/don't trust" boolean. Trust the answer if the
232 *> reciprocal condition number is less than the threshold
233 *> sqrt(n) * slamch('Epsilon').
234 *>
235 *> err = 2 "Guaranteed" error bound: The estimated forward error,
236 *> almost certainly within a factor of 10 of the true error
237 *> so long as the next entry is greater than the threshold
238 *> sqrt(n) * slamch('Epsilon'). This error bound should only
239 *> be trusted if the previous boolean is true.
240 *>
241 *> err = 3 Reciprocal condition number: Estimated normwise
242 *> reciprocal condition number. Compared with the threshold
243 *> sqrt(n) * slamch('Epsilon') to determine if the error
244 *> estimate is "guaranteed". These reciprocal condition
245 *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
246 *> appropriately scaled matrix Z.
247 *> Let Z = S*A, where S scales each row by a power of the
248 *> radix so all absolute row sums of Z are approximately 1.
249 *>
250 *> This subroutine is only responsible for setting the second field
251 *> above.
252 *> See Lapack Working Note 165 for further details and extra
253 *> cautions.
254 *> \endverbatim
255 *>
256 *> \param[in,out] ERR_BNDS_COMP
257 *> \verbatim
258 *> ERR_BNDS_COMP is REAL array, dimension
259 *> (NRHS, N_ERR_BNDS)
260 *> For each right-hand side, this array contains information about
261 *> various error bounds and condition numbers corresponding to the
262 *> componentwise relative error, which is defined as follows:
263 *>
264 *> Componentwise relative error in the ith solution vector:
265 *> abs(XTRUE(j,i) - X(j,i))
266 *> max_j ----------------------
267 *> abs(X(j,i))
268 *>
269 *> The array is indexed by the right-hand side i (on which the
270 *> componentwise relative error depends), and the type of error
271 *> information as described below. There currently are up to three
272 *> pieces of information returned for each right-hand side. If
273 *> componentwise accuracy is not requested (PARAMS(3) = 0.0), then
274 *> ERR_BNDS_COMP is not accessed. If N_ERR_BNDS .LT. 3, then at most
275 *> the first (:,N_ERR_BNDS) entries are returned.
276 *>
277 *> The first index in ERR_BNDS_COMP(i,:) corresponds to the ith
278 *> right-hand side.
279 *>
280 *> The second index in ERR_BNDS_COMP(:,err) contains the following
281 *> three fields:
282 *> err = 1 "Trust/don't trust" boolean. Trust the answer if the
283 *> reciprocal condition number is less than the threshold
284 *> sqrt(n) * slamch('Epsilon').
285 *>
286 *> err = 2 "Guaranteed" error bound: The estimated forward error,
287 *> almost certainly within a factor of 10 of the true error
288 *> so long as the next entry is greater than the threshold
289 *> sqrt(n) * slamch('Epsilon'). This error bound should only
290 *> be trusted if the previous boolean is true.
291 *>
292 *> err = 3 Reciprocal condition number: Estimated componentwise
293 *> reciprocal condition number. Compared with the threshold
294 *> sqrt(n) * slamch('Epsilon') to determine if the error
295 *> estimate is "guaranteed". These reciprocal condition
296 *> numbers are 1 / (norm(Z^{-1},inf) * norm(Z,inf)) for some
297 *> appropriately scaled matrix Z.
298 *> Let Z = S*(A*diag(x)), where x is the solution for the
299 *> current right-hand side and S scales each row of
300 *> A*diag(x) by a power of the radix so all absolute row
301 *> sums of Z are approximately 1.
302 *>
303 *> This subroutine is only responsible for setting the second field
304 *> above.
305 *> See Lapack Working Note 165 for further details and extra
306 *> cautions.
307 *> \endverbatim
308 *>
309 *> \param[in] RES
310 *> \verbatim
311 *> RES is REAL array, dimension (N)
312 *> Workspace to hold the intermediate residual.
313 *> \endverbatim
314 *>
315 *> \param[in] AYB
316 *> \verbatim
317 *> AYB is REAL array, dimension (N)
318 *> Workspace. This can be the same workspace passed for Y_TAIL.
319 *> \endverbatim
320 *>
321 *> \param[in] DY
322 *> \verbatim
323 *> DY is REAL array, dimension (N)
324 *> Workspace to hold the intermediate solution.
325 *> \endverbatim
326 *>
327 *> \param[in] Y_TAIL
328 *> \verbatim
329 *> Y_TAIL is REAL array, dimension (N)
330 *> Workspace to hold the trailing bits of the intermediate solution.
331 *> \endverbatim
332 *>
333 *> \param[in] RCOND
334 *> \verbatim
335 *> RCOND is REAL
336 *> Reciprocal scaled condition number. This is an estimate of the
337 *> reciprocal Skeel condition number of the matrix A after
338 *> equilibration (if done). If this is less than the machine
339 *> precision (in particular, if it is zero), the matrix is singular
340 *> to working precision. Note that the error may still be small even
341 *> if this number is very small and the matrix appears ill-
342 *> conditioned.
343 *> \endverbatim
344 *>
345 *> \param[in] ITHRESH
346 *> \verbatim
347 *> ITHRESH is INTEGER
348 *> The maximum number of residual computations allowed for
349 *> refinement. The default is 10. For 'aggressive' set to 100 to
350 *> permit convergence using approximate factorizations or
351 *> factorizations other than LU. If the factorization uses a
352 *> technique other than Gaussian elimination, the guarantees in
353 *> ERR_BNDS_NORM and ERR_BNDS_COMP may no longer be trustworthy.
354 *> \endverbatim
355 *>
356 *> \param[in] RTHRESH
357 *> \verbatim
358 *> RTHRESH is REAL
359 *> Determines when to stop refinement if the error estimate stops
360 *> decreasing. Refinement will stop when the next solution no longer
361 *> satisfies norm(dx_{i+1}) < RTHRESH * norm(dx_i) where norm(Z) is
362 *> the infinity norm of Z. RTHRESH satisfies 0 < RTHRESH <= 1. The
363 *> default value is 0.5. For 'aggressive' set to 0.9 to permit
364 *> convergence on extremely ill-conditioned matrices. See LAWN 165
365 *> for more details.
366 *> \endverbatim
367 *>
368 *> \param[in] DZ_UB
369 *> \verbatim
370 *> DZ_UB is REAL
371 *> Determines when to start considering componentwise convergence.
372 *> Componentwise convergence is only considered after each component
373 *> of the solution Y is stable, which we definte as the relative
374 *> change in each component being less than DZ_UB. The default value
375 *> is 0.25, requiring the first bit to be stable. See LAWN 165 for
376 *> more details.
377 *> \endverbatim
378 *>
379 *> \param[in] IGNORE_CWISE
380 *> \verbatim
381 *> IGNORE_CWISE is LOGICAL
382 *> If .TRUE. then ignore componentwise convergence. Default value
383 *> is .FALSE..
384 *> \endverbatim
385 *>
386 *> \param[out] INFO
387 *> \verbatim
388 *> INFO is INTEGER
389 *> = 0: Successful exit.
390 *> < 0: if INFO = -i, the ith argument to SGBTRS had an illegal
391 *> value
392 *> \endverbatim
393 *
394 * Authors:
395 * ========
396 *
397 *> \author Univ. of Tennessee
398 *> \author Univ. of California Berkeley
399 *> \author Univ. of Colorado Denver
400 *> \author NAG Ltd.
401 *
402 *> \date September 2012
403 *
404 *> \ingroup realGBcomputational
405 *
406 * =====================================================================
407  SUBROUTINE sla_gbrfsx_extended( PREC_TYPE, TRANS_TYPE, N, KL, KU,
408  $ nrhs, ab, ldab, afb, ldafb, ipiv,
409  $ colequ, c, b, ldb, y, ldy,
410  $ berr_out, n_norms, err_bnds_norm,
411  $ err_bnds_comp, res, ayb, dy,
412  $ y_tail, rcond, ithresh, rthresh,
413  $ dz_ub, ignore_cwise, info )
414 *
415 * -- LAPACK computational routine (version 3.4.2) --
416 * -- LAPACK is a software package provided by Univ. of Tennessee, --
417 * -- Univ. of California Berkeley, Univ. of Colorado Denver and NAG Ltd..--
418 * September 2012
419 *
420 * .. Scalar Arguments ..
421  INTEGER info, ldab, ldafb, ldb, ldy, n, kl, ku, nrhs,
422  $ prec_type, trans_type, n_norms, ithresh
423  LOGICAL colequ, ignore_cwise
424  REAL rthresh, dz_ub
425 * ..
426 * .. Array Arguments ..
427  INTEGER ipiv( * )
428  REAL ab( ldab, * ), afb( ldafb, * ), b( ldb, * ),
429  $ y( ldy, * ), res(*), dy(*), y_tail(*)
430  REAL c( * ), ayb(*), rcond, berr_out(*),
431  $ err_bnds_norm( nrhs, * ),
432  $ err_bnds_comp( nrhs, * )
433 * ..
434 *
435 * =====================================================================
436 *
437 * .. Local Scalars ..
438  CHARACTER trans
439  INTEGER cnt, i, j, m, x_state, z_state, y_prec_state
440  REAL yk, dyk, ymin, normy, normx, normdx, dxrat,
441  $ dzrat, prevnormdx, prev_dz_z, dxratmax,
442  $ dzratmax, dx_x, dz_z, final_dx_x, final_dz_z,
443  $ eps, hugeval, incr_thresh
444  LOGICAL incr_prec
445 * ..
446 * .. Parameters ..
447  INTEGER unstable_state, working_state, conv_state,
448  $ noprog_state, base_residual, extra_residual,
449  $ extra_y
450  parameter( unstable_state = 0, working_state = 1,
451  $ conv_state = 2, noprog_state = 3 )
452  parameter( base_residual = 0, extra_residual = 1,
453  $ extra_y = 2 )
454  INTEGER final_nrm_err_i, final_cmp_err_i, berr_i
455  INTEGER rcond_i, nrm_rcond_i, nrm_err_i, cmp_rcond_i
456  INTEGER cmp_err_i, piv_growth_i
457  parameter( final_nrm_err_i = 1, final_cmp_err_i = 2,
458  $ berr_i = 3 )
459  parameter( rcond_i = 4, nrm_rcond_i = 5, nrm_err_i = 6 )
460  parameter( cmp_rcond_i = 7, cmp_err_i = 8,
461  $ piv_growth_i = 9 )
462  INTEGER la_linrx_itref_i, la_linrx_ithresh_i,
463  $ la_linrx_cwise_i
464  parameter( la_linrx_itref_i = 1,
465  $ la_linrx_ithresh_i = 2 )
466  parameter( la_linrx_cwise_i = 3 )
467  INTEGER la_linrx_trust_i, la_linrx_err_i,
468  $ la_linrx_rcond_i
469  parameter( la_linrx_trust_i = 1, la_linrx_err_i = 2 )
470  parameter( la_linrx_rcond_i = 3 )
471 * ..
472 * .. External Subroutines ..
473  EXTERNAL saxpy, scopy, sgbtrs, sgbmv, blas_sgbmv_x,
474  $ blas_sgbmv2_x, sla_gbamv, sla_wwaddw, slamch,
476  REAL slamch
477  CHARACTER chla_transtype
478 * ..
479 * .. Intrinsic Functions ..
480  INTRINSIC abs, max, min
481 * ..
482 * .. Executable Statements ..
483 *
484  IF (info.NE.0) return
485  trans = chla_transtype(trans_type)
486  eps = slamch( 'Epsilon' )
487  hugeval = slamch( 'Overflow' )
488 * Force HUGEVAL to Inf
489  hugeval = hugeval * hugeval
490 * Using HUGEVAL may lead to spurious underflows.
491  incr_thresh = REAL( N ) * eps
492  m = kl+ku+1
493 
494  DO j = 1, nrhs
495  y_prec_state = extra_residual
496  IF ( y_prec_state .EQ. extra_y ) THEN
497  DO i = 1, n
498  y_tail( i ) = 0.0
499  END DO
500  END IF
501 
502  dxrat = 0.0
503  dxratmax = 0.0
504  dzrat = 0.0
505  dzratmax = 0.0
506  final_dx_x = hugeval
507  final_dz_z = hugeval
508  prevnormdx = hugeval
509  prev_dz_z = hugeval
510  dz_z = hugeval
511  dx_x = hugeval
512 
513  x_state = working_state
514  z_state = unstable_state
515  incr_prec = .false.
516 
517  DO cnt = 1, ithresh
518 *
519 * Compute residual RES = B_s - op(A_s) * Y,
520 * op(A) = A, A**T, or A**H depending on TRANS (and type).
521 *
522  CALL scopy( n, b( 1, j ), 1, res, 1 )
523  IF ( y_prec_state .EQ. base_residual ) THEN
524  CALL sgbmv( trans, m, n, kl, ku, -1.0, ab, ldab,
525  $ y( 1, j ), 1, 1.0, res, 1 )
526  ELSE IF ( y_prec_state .EQ. extra_residual ) THEN
527  CALL blas_sgbmv_x( trans_type, n, n, kl, ku,
528  $ -1.0, ab, ldab, y( 1, j ), 1, 1.0, res, 1,
529  $ prec_type )
530  ELSE
531  CALL blas_sgbmv2_x( trans_type, n, n, kl, ku, -1.0,
532  $ ab, ldab, y( 1, j ), y_tail, 1, 1.0, res, 1,
533  $ prec_type )
534  END IF
535 
536 ! XXX: RES is no longer needed.
537  CALL scopy( n, res, 1, dy, 1 )
538  CALL sgbtrs( trans, n, kl, ku, 1, afb, ldafb, ipiv, dy, n,
539  $ info )
540 *
541 * Calculate relative changes DX_X, DZ_Z and ratios DXRAT, DZRAT.
542 *
543  normx = 0.0
544  normy = 0.0
545  normdx = 0.0
546  dz_z = 0.0
547  ymin = hugeval
548 
549  DO i = 1, n
550  yk = abs( y( i, j ) )
551  dyk = abs( dy( i ) )
552 
553  IF ( yk .NE. 0.0 ) THEN
554  dz_z = max( dz_z, dyk / yk )
555  ELSE IF ( dyk .NE. 0.0 ) THEN
556  dz_z = hugeval
557  END IF
558 
559  ymin = min( ymin, yk )
560 
561  normy = max( normy, yk )
562 
563  IF ( colequ ) THEN
564  normx = max( normx, yk * c( i ) )
565  normdx = max( normdx, dyk * c( i ) )
566  ELSE
567  normx = normy
568  normdx = max( normdx, dyk )
569  END IF
570  END DO
571 
572  IF ( normx .NE. 0.0 ) THEN
573  dx_x = normdx / normx
574  ELSE IF ( normdx .EQ. 0.0 ) THEN
575  dx_x = 0.0
576  ELSE
577  dx_x = hugeval
578  END IF
579 
580  dxrat = normdx / prevnormdx
581  dzrat = dz_z / prev_dz_z
582 *
583 * Check termination criteria.
584 *
585  IF ( .NOT.ignore_cwise
586  $ .AND. ymin*rcond .LT. incr_thresh*normy
587  $ .AND. y_prec_state .LT. extra_y )
588  $ incr_prec = .true.
589 
590  IF ( x_state .EQ. noprog_state .AND. dxrat .LE. rthresh )
591  $ x_state = working_state
592  IF ( x_state .EQ. working_state ) THEN
593  IF ( dx_x .LE. eps ) THEN
594  x_state = conv_state
595  ELSE IF ( dxrat .GT. rthresh ) THEN
596  IF ( y_prec_state .NE. extra_y ) THEN
597  incr_prec = .true.
598  ELSE
599  x_state = noprog_state
600  END IF
601  ELSE
602  IF ( dxrat .GT. dxratmax ) dxratmax = dxrat
603  END IF
604  IF ( x_state .GT. working_state ) final_dx_x = dx_x
605  END IF
606 
607  IF ( z_state .EQ. unstable_state .AND. dz_z .LE. dz_ub )
608  $ z_state = working_state
609  IF ( z_state .EQ. noprog_state .AND. dzrat .LE. rthresh )
610  $ z_state = working_state
611  IF ( z_state .EQ. working_state ) THEN
612  IF ( dz_z .LE. eps ) THEN
613  z_state = conv_state
614  ELSE IF ( dz_z .GT. dz_ub ) THEN
615  z_state = unstable_state
616  dzratmax = 0.0
617  final_dz_z = hugeval
618  ELSE IF ( dzrat .GT. rthresh ) THEN
619  IF ( y_prec_state .NE. extra_y ) THEN
620  incr_prec = .true.
621  ELSE
622  z_state = noprog_state
623  END IF
624  ELSE
625  IF ( dzrat .GT. dzratmax ) dzratmax = dzrat
626  END IF
627  IF ( z_state .GT. working_state ) final_dz_z = dz_z
628  END IF
629 *
630 * Exit if both normwise and componentwise stopped working,
631 * but if componentwise is unstable, let it go at least two
632 * iterations.
633 *
634  IF ( x_state.NE.working_state ) THEN
635  IF ( ignore_cwise ) goto 666
636  IF ( z_state.EQ.noprog_state .OR. z_state.EQ.conv_state )
637  $ goto 666
638  IF ( z_state.EQ.unstable_state .AND. cnt.GT.1 ) goto 666
639  END IF
640 
641  IF ( incr_prec ) THEN
642  incr_prec = .false.
643  y_prec_state = y_prec_state + 1
644  DO i = 1, n
645  y_tail( i ) = 0.0
646  END DO
647  END IF
648 
649  prevnormdx = normdx
650  prev_dz_z = dz_z
651 *
652 * Update soluton.
653 *
654  IF (y_prec_state .LT. extra_y) THEN
655  CALL saxpy( n, 1.0, dy, 1, y(1,j), 1 )
656  ELSE
657  CALL sla_wwaddw( n, y(1,j), y_tail, dy )
658  END IF
659 
660  END DO
661 * Target of "IF (Z_STOP .AND. X_STOP)". Sun's f77 won't EXIT.
662  666 continue
663 *
664 * Set final_* when cnt hits ithresh.
665 *
666  IF ( x_state .EQ. working_state ) final_dx_x = dx_x
667  IF ( z_state .EQ. working_state ) final_dz_z = dz_z
668 *
669 * Compute error bounds.
670 *
671  IF ( n_norms .GE. 1 ) THEN
672  err_bnds_norm( j, la_linrx_err_i ) =
673  $ final_dx_x / (1 - dxratmax)
674  END IF
675  IF (n_norms .GE. 2) THEN
676  err_bnds_comp( j, la_linrx_err_i ) =
677  $ final_dz_z / (1 - dzratmax)
678  END IF
679 *
680 * Compute componentwise relative backward error from formula
681 * max(i) ( abs(R(i)) / ( abs(op(A_s))*abs(Y) + abs(B_s) )(i) )
682 * where abs(Z) is the componentwise absolute value of the matrix
683 * or vector Z.
684 *
685 * Compute residual RES = B_s - op(A_s) * Y,
686 * op(A) = A, A**T, or A**H depending on TRANS (and type).
687 *
688  CALL scopy( n, b( 1, j ), 1, res, 1 )
689  CALL sgbmv(trans, n, n, kl, ku, -1.0, ab, ldab, y(1,j),
690  $ 1, 1.0, res, 1 )
691 
692  DO i = 1, n
693  ayb( i ) = abs( b( i, j ) )
694  END DO
695 *
696 * Compute abs(op(A_s))*abs(Y) + abs(B_s).
697 *
698  CALL sla_gbamv( trans_type, n, n, kl, ku, 1.0,
699  $ ab, ldab, y(1, j), 1, 1.0, ayb, 1 )
700 
701  CALL sla_lin_berr( n, n, 1, res, ayb, berr_out( j ) )
702 *
703 * End of loop for each RHS
704 *
705  END DO
706 *
707  return
708  END