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.

dlatrs3.f 24 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673
  1. *> \brief \b DLATRS3 solves a triangular system of equations with the scale factors set to prevent overflow.
  2. *
  3. * Definition:
  4. * ===========
  5. *
  6. * SUBROUTINE DLATRS3( UPLO, TRANS, DIAG, NORMIN, N, NRHS, A, LDA,
  7. * X, LDX, SCALE, CNORM, WORK, LWORK, INFO )
  8. *
  9. * .. Scalar Arguments ..
  10. * CHARACTER DIAG, NORMIN, TRANS, UPLO
  11. * INTEGER INFO, LDA, LWORK, LDX, N, NRHS
  12. * ..
  13. * .. Array Arguments ..
  14. * DOUBLE PRECISION A( LDA, * ), CNORM( * ), SCALE( * ),
  15. * WORK( * ), X( LDX, * )
  16. * ..
  17. *
  18. *
  19. *> \par Purpose:
  20. * =============
  21. *>
  22. *> \verbatim
  23. *>
  24. *> DLATRS3 solves one of the triangular systems
  25. *>
  26. *> A * X = B * diag(scale) or A**T * X = B * diag(scale)
  27. *>
  28. *> with scaling to prevent overflow. Here A is an upper or lower
  29. *> triangular matrix, A**T denotes the transpose of A. X and B are
  30. *> n by nrhs matrices and scale is an nrhs element vector of scaling
  31. *> factors. A scaling factor scale(j) is usually less than or equal
  32. *> to 1, chosen such that X(:,j) is less than the overflow threshold.
  33. *> If the matrix A is singular (A(j,j) = 0 for some j), then
  34. *> a non-trivial solution to A*X = 0 is returned. If the system is
  35. *> so badly scaled that the solution cannot be represented as
  36. *> (1/scale(k))*X(:,k), then x(:,k) = 0 and scale(k) is returned.
  37. *>
  38. *> This is a BLAS-3 version of LATRS for solving several right
  39. *> hand sides simultaneously.
  40. *>
  41. *> \endverbatim
  42. *
  43. * Arguments:
  44. * ==========
  45. *
  46. *> \param[in] UPLO
  47. *> \verbatim
  48. *> UPLO is CHARACTER*1
  49. *> Specifies whether the matrix A is upper or lower triangular.
  50. *> = 'U': Upper triangular
  51. *> = 'L': Lower triangular
  52. *> \endverbatim
  53. *>
  54. *> \param[in] TRANS
  55. *> \verbatim
  56. *> TRANS is CHARACTER*1
  57. *> Specifies the operation applied to A.
  58. *> = 'N': Solve A * x = s*b (No transpose)
  59. *> = 'T': Solve A**T* x = s*b (Transpose)
  60. *> = 'C': Solve A**T* x = s*b (Conjugate transpose = Transpose)
  61. *> \endverbatim
  62. *>
  63. *> \param[in] DIAG
  64. *> \verbatim
  65. *> DIAG is CHARACTER*1
  66. *> Specifies whether or not the matrix A is unit triangular.
  67. *> = 'N': Non-unit triangular
  68. *> = 'U': Unit triangular
  69. *> \endverbatim
  70. *>
  71. *> \param[in] NORMIN
  72. *> \verbatim
  73. *> NORMIN is CHARACTER*1
  74. *> Specifies whether CNORM has been set or not.
  75. *> = 'Y': CNORM contains the column norms on entry
  76. *> = 'N': CNORM is not set on entry. On exit, the norms will
  77. *> be computed and stored in CNORM.
  78. *> \endverbatim
  79. *>
  80. *> \param[in] N
  81. *> \verbatim
  82. *> N is INTEGER
  83. *> The order of the matrix A. N >= 0.
  84. *> \endverbatim
  85. *>
  86. *> \param[in] NRHS
  87. *> \verbatim
  88. *> NRHS is INTEGER
  89. *> The number of columns of X. NRHS >= 0.
  90. *> \endverbatim
  91. *>
  92. *> \param[in] A
  93. *> \verbatim
  94. *> A is DOUBLE PRECISION array, dimension (LDA,N)
  95. *> The triangular matrix A. If UPLO = 'U', the leading n by n
  96. *> upper triangular part of the array A contains the upper
  97. *> triangular matrix, and the strictly lower triangular part of
  98. *> A is not referenced. If UPLO = 'L', the leading n by n lower
  99. *> triangular part of the array A contains the lower triangular
  100. *> matrix, and the strictly upper triangular part of A is not
  101. *> referenced. If DIAG = 'U', the diagonal elements of A are
  102. *> also not referenced and are assumed to be 1.
  103. *> \endverbatim
  104. *>
  105. *> \param[in] LDA
  106. *> \verbatim
  107. *> LDA is INTEGER
  108. *> The leading dimension of the array A. LDA >= max (1,N).
  109. *> \endverbatim
  110. *>
  111. *> \param[in,out] X
  112. *> \verbatim
  113. *> X is DOUBLE PRECISION array, dimension (LDX,NRHS)
  114. *> On entry, the right hand side B of the triangular system.
  115. *> On exit, X is overwritten by the solution matrix X.
  116. *> \endverbatim
  117. *>
  118. *> \param[in] LDX
  119. *> \verbatim
  120. *> LDX is INTEGER
  121. *> The leading dimension of the array X. LDX >= max (1,N).
  122. *> \endverbatim
  123. *>
  124. *> \param[out] SCALE
  125. *> \verbatim
  126. *> SCALE is DOUBLE PRECISION array, dimension (NRHS)
  127. *> The scaling factor s(k) is for the triangular system
  128. *> A * x(:,k) = s(k)*b(:,k) or A**T* x(:,k) = s(k)*b(:,k).
  129. *> If SCALE = 0, the matrix A is singular or badly scaled.
  130. *> If A(j,j) = 0 is encountered, a non-trivial vector x(:,k)
  131. *> that is an exact or approximate solution to A*x(:,k) = 0
  132. *> is returned. If the system so badly scaled that solution
  133. *> cannot be presented as x(:,k) * 1/s(k), then x(:,k) = 0
  134. *> is returned.
  135. *> \endverbatim
  136. *>
  137. *> \param[in,out] CNORM
  138. *> \verbatim
  139. *> CNORM is DOUBLE PRECISION array, dimension (N)
  140. *>
  141. *> If NORMIN = 'Y', CNORM is an input argument and CNORM(j)
  142. *> contains the norm of the off-diagonal part of the j-th column
  143. *> of A. If TRANS = 'N', CNORM(j) must be greater than or equal
  144. *> to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j)
  145. *> must be greater than or equal to the 1-norm.
  146. *>
  147. *> If NORMIN = 'N', CNORM is an output argument and CNORM(j)
  148. *> returns the 1-norm of the offdiagonal part of the j-th column
  149. *> of A.
  150. *> \endverbatim
  151. *>
  152. *> \param[out] WORK
  153. *> \verbatim
  154. *> WORK is DOUBLE PRECISION array, dimension (MAX(1,LWORK)).
  155. *> On exit, if INFO = 0, WORK(1) returns the optimal size of
  156. *> WORK.
  157. *> \endverbatim
  158. *>
  159. *> \param[in] LWORK
  160. *> \verbatim
  161. *> LWORK is INTEGER
  162. *> The dimension of the array WORK.
  163. *>
  164. *> If MIN(N,NRHS) = 0, LWORK >= 1, else
  165. *> LWORK >= MAX(1, 2*NBA * MAX(NBA, MIN(NRHS, 32)), where
  166. *> NBA = (N + NB - 1)/NB and NB is the optimal block size.
  167. *>
  168. *> If LWORK = -1, then a workspace query is assumed; the routine
  169. *> only calculates the optimal dimensions of the WORK array, returns
  170. *> this value as the first entry of the WORK array, and no error
  171. *> message related to LWORK is issued by XERBLA.
  172. *> \endverbatim
  173. *>
  174. *> \param[out] INFO
  175. *> \verbatim
  176. *> INFO is INTEGER
  177. *> = 0: successful exit
  178. *> < 0: if INFO = -k, the k-th argument had an illegal value
  179. *> \endverbatim
  180. *
  181. * Authors:
  182. * ========
  183. *
  184. *> \author Univ. of Tennessee
  185. *> \author Univ. of California Berkeley
  186. *> \author Univ. of Colorado Denver
  187. *> \author NAG Ltd.
  188. *
  189. *> \ingroup latrs3
  190. *> \par Further Details:
  191. * =====================
  192. * \verbatim
  193. * The algorithm follows the structure of a block triangular solve.
  194. * The diagonal block is solved with a call to the robust the triangular
  195. * solver LATRS for every right-hand side RHS = 1, ..., NRHS
  196. * op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS ),
  197. * where op( A ) = A or op( A ) = A**T.
  198. * The linear block updates operate on block columns of X,
  199. * B( I, K ) - op(A( I, J )) * X( J, K )
  200. * and use GEMM. To avoid overflow in the linear block update, the worst case
  201. * growth is estimated. For every RHS, a scale factor s <= 1.0 is computed
  202. * such that
  203. * || s * B( I, RHS )||_oo
  204. * + || op(A( I, J )) ||_oo * || s * X( J, RHS ) ||_oo <= Overflow threshold
  205. *
  206. * Once all columns of a block column have been rescaled (BLAS-1), the linear
  207. * update is executed with GEMM without overflow.
  208. *
  209. * To limit rescaling, local scale factors track the scaling of column segments.
  210. * There is one local scale factor s( I, RHS ) per block row I = 1, ..., NBA
  211. * per right-hand side column RHS = 1, ..., NRHS. The global scale factor
  212. * SCALE( RHS ) is chosen as the smallest local scale factor s( I, RHS )
  213. * I = 1, ..., NBA.
  214. * A triangular solve op(A( J, J )) * x( J, RHS ) = SCALOC * b( J, RHS )
  215. * updates the local scale factor s( J, RHS ) := s( J, RHS ) * SCALOC. The
  216. * linear update of potentially inconsistently scaled vector segments
  217. * s( I, RHS ) * b( I, RHS ) - op(A( I, J )) * ( s( J, RHS )* x( J, RHS ) )
  218. * computes a consistent scaling SCAMIN = MIN( s(I, RHS ), s(J, RHS) ) and,
  219. * if necessary, rescales the blocks prior to calling GEMM.
  220. *
  221. * \endverbatim
  222. * =====================================================================
  223. * References:
  224. * C. C. Kjelgaard Mikkelsen, A. B. Schwarz and L. Karlsson (2019).
  225. * Parallel robust solution of triangular linear systems. Concurrency
  226. * and Computation: Practice and Experience, 31(19), e5064.
  227. *
  228. * Contributor:
  229. * Angelika Schwarz, Umea University, Sweden.
  230. *
  231. * =====================================================================
  232. SUBROUTINE DLATRS3( UPLO, TRANS, DIAG, NORMIN, N, NRHS, A, LDA,
  233. $ X, LDX, SCALE, CNORM, WORK, LWORK, INFO )
  234. IMPLICIT NONE
  235. *
  236. * .. Scalar Arguments ..
  237. CHARACTER DIAG, TRANS, NORMIN, UPLO
  238. INTEGER INFO, LDA, LWORK, LDX, N, NRHS
  239. * ..
  240. * .. Array Arguments ..
  241. DOUBLE PRECISION A( LDA, * ), CNORM( * ), X( LDX, * ),
  242. $ SCALE( * ), WORK( * )
  243. * ..
  244. *
  245. * =====================================================================
  246. *
  247. * .. Parameters ..
  248. DOUBLE PRECISION ZERO, ONE
  249. PARAMETER ( ZERO = 0.0D+0, ONE = 1.0D+0 )
  250. INTEGER NBMAX, NBMIN, NBRHS, NRHSMIN
  251. PARAMETER ( NRHSMIN = 2, NBRHS = 32 )
  252. PARAMETER ( NBMIN = 8, NBMAX = 64 )
  253. * ..
  254. * .. Local Arrays ..
  255. DOUBLE PRECISION W( NBMAX ), XNRM( NBRHS )
  256. * ..
  257. * .. Local Scalars ..
  258. LOGICAL LQUERY, NOTRAN, NOUNIT, UPPER
  259. INTEGER AWRK, I, IFIRST, IINC, ILAST, II, I1, I2, J,
  260. $ JFIRST, JINC, JLAST, J1, J2, K, KK, K1, K2,
  261. $ LANRM, LDS, LSCALE, NB, NBA, NBX, RHS, LWMIN
  262. DOUBLE PRECISION ANRM, BIGNUM, BNRM, RSCAL, SCAL, SCALOC,
  263. $ SCAMIN, SMLNUM, TMAX
  264. * ..
  265. * .. External Functions ..
  266. LOGICAL LSAME
  267. INTEGER ILAENV
  268. DOUBLE PRECISION DLAMCH, DLANGE, DLARMM
  269. EXTERNAL DLAMCH, DLANGE, DLARMM, ILAENV, LSAME
  270. * ..
  271. * .. External Subroutines ..
  272. EXTERNAL DLATRS, DSCAL, XERBLA
  273. * ..
  274. * .. Intrinsic Functions ..
  275. INTRINSIC ABS, MAX, MIN
  276. * ..
  277. * .. Executable Statements ..
  278. *
  279. INFO = 0
  280. UPPER = LSAME( UPLO, 'U' )
  281. NOTRAN = LSAME( TRANS, 'N' )
  282. NOUNIT = LSAME( DIAG, 'N' )
  283. LQUERY = ( LWORK.EQ.-1 )
  284. *
  285. * Partition A and X into blocks
  286. *
  287. NB = MAX( 8, ILAENV( 1, 'DLATRS', '', N, N, -1, -1 ) )
  288. NB = MIN( NBMAX, NB )
  289. NBA = MAX( 1, (N + NB - 1) / NB )
  290. NBX = MAX( 1, (NRHS + NBRHS - 1) / NBRHS )
  291. *
  292. * Compute the workspace
  293. *
  294. * The workspace comprises two parts.
  295. * The first part stores the local scale factors. Each simultaneously
  296. * computed right-hand side requires one local scale factor per block
  297. * row. WORK( I+KK*LDS ) is the scale factor of the vector
  298. * segment associated with the I-th block row and the KK-th vector
  299. * in the block column.
  300. *
  301. LSCALE = NBA * MAX( NBA, MIN( NRHS, NBRHS ) )
  302. LDS = NBA
  303. *
  304. * The second part stores upper bounds of the triangular A. There are
  305. * a total of NBA x NBA blocks, of which only the upper triangular
  306. * part or the lower triangular part is referenced. The upper bound of
  307. * the block A( I, J ) is stored as WORK( AWRK + I + J * NBA ).
  308. *
  309. LANRM = NBA * NBA
  310. AWRK = LSCALE
  311. *
  312. IF( MIN( N, NRHS ).EQ.0 ) THEN
  313. LWMIN = 1
  314. ELSE
  315. LWMIN = LSCALE + LANRM
  316. END IF
  317. WORK( 1 ) = LWMIN
  318. *
  319. * Test the input parameters
  320. *
  321. IF( .NOT.UPPER .AND. .NOT.LSAME( UPLO, 'L' ) ) THEN
  322. INFO = -1
  323. ELSE IF( .NOT.NOTRAN .AND. .NOT.LSAME( TRANS, 'T' ) .AND. .NOT.
  324. $ LSAME( TRANS, 'C' ) ) THEN
  325. INFO = -2
  326. ELSE IF( .NOT.NOUNIT .AND. .NOT.LSAME( DIAG, 'U' ) ) THEN
  327. INFO = -3
  328. ELSE IF( .NOT.LSAME( NORMIN, 'Y' ) .AND. .NOT.
  329. $ LSAME( NORMIN, 'N' ) ) THEN
  330. INFO = -4
  331. ELSE IF( N.LT.0 ) THEN
  332. INFO = -5
  333. ELSE IF( NRHS.LT.0 ) THEN
  334. INFO = -6
  335. ELSE IF( LDA.LT.MAX( 1, N ) ) THEN
  336. INFO = -8
  337. ELSE IF( LDX.LT.MAX( 1, N ) ) THEN
  338. INFO = -10
  339. ELSE IF( .NOT.LQUERY .AND. LWORK.LT.LWMIN ) THEN
  340. INFO = -14
  341. END IF
  342. IF( INFO.NE.0 ) THEN
  343. CALL XERBLA( 'DLATRS3', -INFO )
  344. RETURN
  345. ELSE IF( LQUERY ) THEN
  346. RETURN
  347. END IF
  348. *
  349. * Initialize scaling factors
  350. *
  351. DO KK = 1, NRHS
  352. SCALE( KK ) = ONE
  353. END DO
  354. *
  355. * Quick return if possible
  356. *
  357. IF( MIN( N, NRHS ).EQ.0 )
  358. $ RETURN
  359. *
  360. * Determine machine dependent constant to control overflow.
  361. *
  362. BIGNUM = DLAMCH( 'Overflow' )
  363. SMLNUM = DLAMCH( 'Safe Minimum' )
  364. *
  365. * Use unblocked code for small problems
  366. *
  367. IF( NRHS.LT.NRHSMIN ) THEN
  368. CALL DLATRS( UPLO, TRANS, DIAG, NORMIN, N, A, LDA, X( 1, 1),
  369. $ SCALE( 1 ), CNORM, INFO )
  370. DO K = 2, NRHS
  371. CALL DLATRS( UPLO, TRANS, DIAG, 'Y', N, A, LDA, X( 1, K ),
  372. $ SCALE( K ), CNORM, INFO )
  373. END DO
  374. RETURN
  375. END IF
  376. *
  377. * Compute norms of blocks of A excluding diagonal blocks and find
  378. * the block with the largest norm TMAX.
  379. *
  380. TMAX = ZERO
  381. DO J = 1, NBA
  382. J1 = (J-1)*NB + 1
  383. J2 = MIN( J*NB, N ) + 1
  384. IF ( UPPER ) THEN
  385. IFIRST = 1
  386. ILAST = J - 1
  387. ELSE
  388. IFIRST = J + 1
  389. ILAST = NBA
  390. END IF
  391. DO I = IFIRST, ILAST
  392. I1 = (I-1)*NB + 1
  393. I2 = MIN( I*NB, N ) + 1
  394. *
  395. * Compute upper bound of A( I1:I2-1, J1:J2-1 ).
  396. *
  397. IF( NOTRAN ) THEN
  398. ANRM = DLANGE( 'I', I2-I1, J2-J1, A( I1, J1 ), LDA, W )
  399. WORK( AWRK + I+(J-1)*NBA ) = ANRM
  400. ELSE
  401. ANRM = DLANGE( '1', I2-I1, J2-J1, A( I1, J1 ), LDA, W )
  402. WORK( AWRK + J+(I-1)*NBA ) = ANRM
  403. END IF
  404. TMAX = MAX( TMAX, ANRM )
  405. END DO
  406. END DO
  407. *
  408. IF( .NOT. TMAX.LE.DLAMCH('Overflow') ) THEN
  409. *
  410. * Some matrix entries have huge absolute value. At least one upper
  411. * bound norm( A(I1:I2-1, J1:J2-1), 'I') is not a valid floating-point
  412. * number, either due to overflow in LANGE or due to Inf in A.
  413. * Fall back to LATRS. Set normin = 'N' for every right-hand side to
  414. * force computation of TSCAL in LATRS to avoid the likely overflow
  415. * in the computation of the column norms CNORM.
  416. *
  417. DO K = 1, NRHS
  418. CALL DLATRS( UPLO, TRANS, DIAG, 'N', N, A, LDA, X( 1, K ),
  419. $ SCALE( K ), CNORM, INFO )
  420. END DO
  421. RETURN
  422. END IF
  423. *
  424. * Every right-hand side requires workspace to store NBA local scale
  425. * factors. To save workspace, X is computed successively in block columns
  426. * of width NBRHS, requiring a total of NBA x NBRHS space. If sufficient
  427. * workspace is available, larger values of NBRHS or NBRHS = NRHS are viable.
  428. DO K = 1, NBX
  429. * Loop over block columns (index = K) of X and, for column-wise scalings,
  430. * over individual columns (index = KK).
  431. * K1: column index of the first column in X( J, K )
  432. * K2: column index of the first column in X( J, K+1 )
  433. * so the K2 - K1 is the column count of the block X( J, K )
  434. K1 = (K-1)*NBRHS + 1
  435. K2 = MIN( K*NBRHS, NRHS ) + 1
  436. *
  437. * Initialize local scaling factors of current block column X( J, K )
  438. *
  439. DO KK = 1, K2-K1
  440. DO I = 1, NBA
  441. WORK( I+KK*LDS ) = ONE
  442. END DO
  443. END DO
  444. *
  445. IF( NOTRAN ) THEN
  446. *
  447. * Solve A * X(:, K1:K2-1) = B * diag(scale(K1:K2-1))
  448. *
  449. IF( UPPER ) THEN
  450. JFIRST = NBA
  451. JLAST = 1
  452. JINC = -1
  453. ELSE
  454. JFIRST = 1
  455. JLAST = NBA
  456. JINC = 1
  457. END IF
  458. ELSE
  459. *
  460. * Solve A**T * X(:, K1:K2-1) = B * diag(scale(K1:K2-1))
  461. *
  462. IF( UPPER ) THEN
  463. JFIRST = 1
  464. JLAST = NBA
  465. JINC = 1
  466. ELSE
  467. JFIRST = NBA
  468. JLAST = 1
  469. JINC = -1
  470. END IF
  471. END IF
  472. *
  473. DO J = JFIRST, JLAST, JINC
  474. * J1: row index of the first row in A( J, J )
  475. * J2: row index of the first row in A( J+1, J+1 )
  476. * so that J2 - J1 is the row count of the block A( J, J )
  477. J1 = (J-1)*NB + 1
  478. J2 = MIN( J*NB, N ) + 1
  479. *
  480. * Solve op(A( J, J )) * X( J, RHS ) = SCALOC * B( J, RHS )
  481. * for all right-hand sides in the current block column,
  482. * one RHS at a time.
  483. *
  484. DO KK = 1, K2-K1
  485. RHS = K1 + KK - 1
  486. IF( KK.EQ.1 ) THEN
  487. CALL DLATRS( UPLO, TRANS, DIAG, 'N', J2-J1,
  488. $ A( J1, J1 ), LDA, X( J1, RHS ),
  489. $ SCALOC, CNORM, INFO )
  490. ELSE
  491. CALL DLATRS( UPLO, TRANS, DIAG, 'Y', J2-J1,
  492. $ A( J1, J1 ), LDA, X( J1, RHS ),
  493. $ SCALOC, CNORM, INFO )
  494. END IF
  495. * Find largest absolute value entry in the vector segment
  496. * X( J1:J2-1, RHS ) as an upper bound for the worst case
  497. * growth in the linear updates.
  498. XNRM( KK ) = DLANGE( 'I', J2-J1, 1, X( J1, RHS ),
  499. $ LDX, W )
  500. *
  501. IF( SCALOC .EQ. ZERO ) THEN
  502. * LATRS found that A is singular through A(j,j) = 0.
  503. * Reset the computation x(1:n) = 0, x(j) = 1, SCALE = 0
  504. * and compute A*x = 0 (or A**T*x = 0). Note that
  505. * X(J1:J2-1, KK) is set by LATRS.
  506. SCALE( RHS ) = ZERO
  507. DO II = 1, J1-1
  508. X( II, KK ) = ZERO
  509. END DO
  510. DO II = J2, N
  511. X( II, KK ) = ZERO
  512. END DO
  513. * Discard the local scale factors.
  514. DO II = 1, NBA
  515. WORK( II+KK*LDS ) = ONE
  516. END DO
  517. SCALOC = ONE
  518. ELSE IF( SCALOC * WORK( J+KK*LDS ) .EQ. ZERO ) THEN
  519. * LATRS computed a valid scale factor, but combined with
  520. * the current scaling the solution does not have a
  521. * scale factor > 0.
  522. *
  523. * Set WORK( J+KK*LDS ) to smallest valid scale
  524. * factor and increase SCALOC accordingly.
  525. SCAL = WORK( J+KK*LDS ) / SMLNUM
  526. SCALOC = SCALOC * SCAL
  527. WORK( J+KK*LDS ) = SMLNUM
  528. * If LATRS overestimated the growth, x may be
  529. * rescaled to preserve a valid combined scale
  530. * factor WORK( J, KK ) > 0.
  531. RSCAL = ONE / SCALOC
  532. IF( XNRM( KK ) * RSCAL .LE. BIGNUM ) THEN
  533. XNRM( KK ) = XNRM( KK ) * RSCAL
  534. CALL DSCAL( J2-J1, RSCAL, X( J1, RHS ), 1 )
  535. SCALOC = ONE
  536. ELSE
  537. * The system op(A) * x = b is badly scaled and its
  538. * solution cannot be represented as (1/scale) * x.
  539. * Set x to zero. This approach deviates from LATRS
  540. * where a completely meaningless non-zero vector
  541. * is returned that is not a solution to op(A) * x = b.
  542. SCALE( RHS ) = ZERO
  543. DO II = 1, N
  544. X( II, KK ) = ZERO
  545. END DO
  546. * Discard the local scale factors.
  547. DO II = 1, NBA
  548. WORK( II+KK*LDS ) = ONE
  549. END DO
  550. SCALOC = ONE
  551. END IF
  552. END IF
  553. SCALOC = SCALOC * WORK( J+KK*LDS )
  554. WORK( J+KK*LDS ) = SCALOC
  555. END DO
  556. *
  557. * Linear block updates
  558. *
  559. IF( NOTRAN ) THEN
  560. IF( UPPER ) THEN
  561. IFIRST = J - 1
  562. ILAST = 1
  563. IINC = -1
  564. ELSE
  565. IFIRST = J + 1
  566. ILAST = NBA
  567. IINC = 1
  568. END IF
  569. ELSE
  570. IF( UPPER ) THEN
  571. IFIRST = J + 1
  572. ILAST = NBA
  573. IINC = 1
  574. ELSE
  575. IFIRST = J - 1
  576. ILAST = 1
  577. IINC = -1
  578. END IF
  579. END IF
  580. *
  581. DO I = IFIRST, ILAST, IINC
  582. * I1: row index of the first column in X( I, K )
  583. * I2: row index of the first column in X( I+1, K )
  584. * so the I2 - I1 is the row count of the block X( I, K )
  585. I1 = (I-1)*NB + 1
  586. I2 = MIN( I*NB, N ) + 1
  587. *
  588. * Prepare the linear update to be executed with GEMM.
  589. * For each column, compute a consistent scaling, a
  590. * scaling factor to survive the linear update, and
  591. * rescale the column segments, if necessary. Then
  592. * the linear update is safely executed.
  593. *
  594. DO KK = 1, K2-K1
  595. RHS = K1 + KK - 1
  596. * Compute consistent scaling
  597. SCAMIN = MIN( WORK( I + KK*LDS), WORK( J + KK*LDS ) )
  598. *
  599. * Compute scaling factor to survive the linear update
  600. * simulating consistent scaling.
  601. *
  602. BNRM = DLANGE( 'I', I2-I1, 1, X( I1, RHS ), LDX, W )
  603. BNRM = BNRM*( SCAMIN / WORK( I+KK*LDS ) )
  604. XNRM( KK ) = XNRM( KK )*(SCAMIN / WORK( J+KK*LDS ))
  605. ANRM = WORK( AWRK + I+(J-1)*NBA )
  606. SCALOC = DLARMM( ANRM, XNRM( KK ), BNRM )
  607. *
  608. * Simultaneously apply the robust update factor and the
  609. * consistency scaling factor to B( I, KK ) and B( J, KK ).
  610. *
  611. SCAL = ( SCAMIN / WORK( I+KK*LDS) )*SCALOC
  612. IF( SCAL.NE.ONE ) THEN
  613. CALL DSCAL( I2-I1, SCAL, X( I1, RHS ), 1 )
  614. WORK( I+KK*LDS ) = SCAMIN*SCALOC
  615. END IF
  616. *
  617. SCAL = ( SCAMIN / WORK( J+KK*LDS ) )*SCALOC
  618. IF( SCAL.NE.ONE ) THEN
  619. CALL DSCAL( J2-J1, SCAL, X( J1, RHS ), 1 )
  620. WORK( J+KK*LDS ) = SCAMIN*SCALOC
  621. END IF
  622. END DO
  623. *
  624. IF( NOTRAN ) THEN
  625. *
  626. * B( I, K ) := B( I, K ) - A( I, J ) * X( J, K )
  627. *
  628. CALL DGEMM( 'N', 'N', I2-I1, K2-K1, J2-J1, -ONE,
  629. $ A( I1, J1 ), LDA, X( J1, K1 ), LDX,
  630. $ ONE, X( I1, K1 ), LDX )
  631. ELSE
  632. *
  633. * B( I, K ) := B( I, K ) - A( J, I )**T * X( J, K )
  634. *
  635. CALL DGEMM( 'T', 'N', I2-I1, K2-K1, J2-J1, -ONE,
  636. $ A( J1, I1 ), LDA, X( J1, K1 ), LDX,
  637. $ ONE, X( I1, K1 ), LDX )
  638. END IF
  639. END DO
  640. END DO
  641. *
  642. * Reduce local scaling factors
  643. *
  644. DO KK = 1, K2-K1
  645. RHS = K1 + KK - 1
  646. DO I = 1, NBA
  647. SCALE( RHS ) = MIN( SCALE( RHS ), WORK( I+KK*LDS ) )
  648. END DO
  649. END DO
  650. *
  651. * Realize consistent scaling
  652. *
  653. DO KK = 1, K2-K1
  654. RHS = K1 + KK - 1
  655. IF( SCALE( RHS ).NE.ONE .AND. SCALE( RHS ).NE. ZERO ) THEN
  656. DO I = 1, NBA
  657. I1 = (I-1)*NB + 1
  658. I2 = MIN( I*NB, N ) + 1
  659. SCAL = SCALE( RHS ) / WORK( I+KK*LDS )
  660. IF( SCAL.NE.ONE )
  661. $ CALL DSCAL( I2-I1, SCAL, X( I1, RHS ), 1 )
  662. END DO
  663. END IF
  664. END DO
  665. END DO
  666. *
  667. WORK( 1 ) = LWMIN
  668. *
  669. RETURN
  670. *
  671. * End of DLATRS3
  672. *
  673. END