You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dla_gbrfsx_extended.f 26 kB

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