dlatbs.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  1. /* dlatbs.f -- translated by f2c (version 20061008).
  2. You must link the resulting object file with libf2c:
  3. on Microsoft Windows system, link with libf2c.lib;
  4. on Linux or Unix systems, link with .../path/to/libf2c.a -lm
  5. or, if you install libf2c.a in a standard place, with -lf2c -lm
  6. -- in that order, at the end of the command line, as in
  7. cc *.o -lf2c -lm
  8. Source for libf2c is in /netlib/f2c/libf2c.zip, e.g.,
  9. http://www.netlib.org/f2c/libf2c.zip
  10. */
  11. #include "f2c.h"
  12. #include "blaswrap.h"
  13. /* Table of constant values */
  14. static integer c__1 = 1;
  15. static doublereal c_b36 = .5;
  16. /* Subroutine */ int _starpu_dlatbs_(char *uplo, char *trans, char *diag, char *
  17. normin, integer *n, integer *kd, doublereal *ab, integer *ldab,
  18. doublereal *x, doublereal *scale, doublereal *cnorm, integer *info)
  19. {
  20. /* System generated locals */
  21. integer ab_dim1, ab_offset, i__1, i__2, i__3, i__4;
  22. doublereal d__1, d__2, d__3;
  23. /* Local variables */
  24. integer i__, j;
  25. doublereal xj, rec, tjj;
  26. integer jinc, jlen;
  27. extern doublereal _starpu_ddot_(integer *, doublereal *, integer *, doublereal *,
  28. integer *);
  29. doublereal xbnd;
  30. integer imax;
  31. doublereal tmax, tjjs, xmax, grow, sumj;
  32. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  33. integer *);
  34. integer maind;
  35. extern logical _starpu_lsame_(char *, char *);
  36. doublereal tscal, uscal;
  37. extern doublereal _starpu_dasum_(integer *, doublereal *, integer *);
  38. integer jlast;
  39. extern /* Subroutine */ int _starpu_dtbsv_(char *, char *, char *, integer *,
  40. integer *, doublereal *, integer *, doublereal *, integer *), _starpu_daxpy_(integer *, doublereal *,
  41. doublereal *, integer *, doublereal *, integer *);
  42. logical upper;
  43. extern doublereal _starpu_dlamch_(char *);
  44. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  45. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  46. doublereal bignum;
  47. logical notran;
  48. integer jfirst;
  49. doublereal smlnum;
  50. logical nounit;
  51. /* -- LAPACK auxiliary routine (version 3.2) -- */
  52. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  53. /* November 2006 */
  54. /* .. Scalar Arguments .. */
  55. /* .. */
  56. /* .. Array Arguments .. */
  57. /* .. */
  58. /* Purpose */
  59. /* ======= */
  60. /* DLATBS solves one of the triangular systems */
  61. /* A *x = s*b or A'*x = s*b */
  62. /* with scaling to prevent overflow, where A is an upper or lower */
  63. /* triangular band matrix. Here A' denotes the transpose of A, x and b */
  64. /* are n-element vectors, and s is a scaling factor, usually less than */
  65. /* or equal to 1, chosen so that the components of x will be less than */
  66. /* the overflow threshold. If the unscaled problem will not cause */
  67. /* overflow, the Level 2 BLAS routine DTBSV is called. If the matrix A */
  68. /* is singular (A(j,j) = 0 for some j), then s is set to 0 and a */
  69. /* non-trivial solution to A*x = 0 is returned. */
  70. /* Arguments */
  71. /* ========= */
  72. /* UPLO (input) CHARACTER*1 */
  73. /* Specifies whether the matrix A is upper or lower triangular. */
  74. /* = 'U': Upper triangular */
  75. /* = 'L': Lower triangular */
  76. /* TRANS (input) CHARACTER*1 */
  77. /* Specifies the operation applied to A. */
  78. /* = 'N': Solve A * x = s*b (No transpose) */
  79. /* = 'T': Solve A'* x = s*b (Transpose) */
  80. /* = 'C': Solve A'* x = s*b (Conjugate transpose = Transpose) */
  81. /* DIAG (input) CHARACTER*1 */
  82. /* Specifies whether or not the matrix A is unit triangular. */
  83. /* = 'N': Non-unit triangular */
  84. /* = 'U': Unit triangular */
  85. /* NORMIN (input) CHARACTER*1 */
  86. /* Specifies whether CNORM has been set or not. */
  87. /* = 'Y': CNORM contains the column norms on entry */
  88. /* = 'N': CNORM is not set on entry. On exit, the norms will */
  89. /* be computed and stored in CNORM. */
  90. /* N (input) INTEGER */
  91. /* The order of the matrix A. N >= 0. */
  92. /* KD (input) INTEGER */
  93. /* The number of subdiagonals or superdiagonals in the */
  94. /* triangular matrix A. KD >= 0. */
  95. /* AB (input) DOUBLE PRECISION array, dimension (LDAB,N) */
  96. /* The upper or lower triangular band matrix A, stored in the */
  97. /* first KD+1 rows of the array. The j-th column of A is stored */
  98. /* in the j-th column of the array AB as follows: */
  99. /* if UPLO = 'U', AB(kd+1+i-j,j) = A(i,j) for max(1,j-kd)<=i<=j; */
  100. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(n,j+kd). */
  101. /* LDAB (input) INTEGER */
  102. /* The leading dimension of the array AB. LDAB >= KD+1. */
  103. /* X (input/output) DOUBLE PRECISION array, dimension (N) */
  104. /* On entry, the right hand side b of the triangular system. */
  105. /* On exit, X is overwritten by the solution vector x. */
  106. /* SCALE (output) DOUBLE PRECISION */
  107. /* The scaling factor s for the triangular system */
  108. /* A * x = s*b or A'* x = s*b. */
  109. /* If SCALE = 0, the matrix A is singular or badly scaled, and */
  110. /* the vector x is an exact or approximate solution to A*x = 0. */
  111. /* CNORM (input or output) DOUBLE PRECISION array, dimension (N) */
  112. /* If NORMIN = 'Y', CNORM is an input argument and CNORM(j) */
  113. /* contains the norm of the off-diagonal part of the j-th column */
  114. /* of A. If TRANS = 'N', CNORM(j) must be greater than or equal */
  115. /* to the infinity-norm, and if TRANS = 'T' or 'C', CNORM(j) */
  116. /* must be greater than or equal to the 1-norm. */
  117. /* If NORMIN = 'N', CNORM is an output argument and CNORM(j) */
  118. /* returns the 1-norm of the offdiagonal part of the j-th column */
  119. /* of A. */
  120. /* INFO (output) INTEGER */
  121. /* = 0: successful exit */
  122. /* < 0: if INFO = -k, the k-th argument had an illegal value */
  123. /* Further Details */
  124. /* ======= ======= */
  125. /* A rough bound on x is computed; if that is less than overflow, DTBSV */
  126. /* is called, otherwise, specific code is used which checks for possible */
  127. /* overflow or divide-by-zero at every operation. */
  128. /* A columnwise scheme is used for solving A*x = b. The basic algorithm */
  129. /* if A is lower triangular is */
  130. /* x[1:n] := b[1:n] */
  131. /* for j = 1, ..., n */
  132. /* x(j) := x(j) / A(j,j) */
  133. /* x[j+1:n] := x[j+1:n] - x(j) * A[j+1:n,j] */
  134. /* end */
  135. /* Define bounds on the components of x after j iterations of the loop: */
  136. /* M(j) = bound on x[1:j] */
  137. /* G(j) = bound on x[j+1:n] */
  138. /* Initially, let M(0) = 0 and G(0) = max{x(i), i=1,...,n}. */
  139. /* Then for iteration j+1 we have */
  140. /* M(j+1) <= G(j) / | A(j+1,j+1) | */
  141. /* G(j+1) <= G(j) + M(j+1) * | A[j+2:n,j+1] | */
  142. /* <= G(j) ( 1 + CNORM(j+1) / | A(j+1,j+1) | ) */
  143. /* where CNORM(j+1) is greater than or equal to the infinity-norm of */
  144. /* column j+1 of A, not counting the diagonal. Hence */
  145. /* G(j) <= G(0) product ( 1 + CNORM(i) / | A(i,i) | ) */
  146. /* 1<=i<=j */
  147. /* and */
  148. /* |x(j)| <= ( G(0) / |A(j,j)| ) product ( 1 + CNORM(i) / |A(i,i)| ) */
  149. /* 1<=i< j */
  150. /* Since |x(j)| <= M(j), we use the Level 2 BLAS routine DTBSV if the */
  151. /* reciprocal of the largest M(j), j=1,..,n, is larger than */
  152. /* max(underflow, 1/overflow). */
  153. /* The bound on x(j) is also used to determine when a step in the */
  154. /* columnwise method can be performed without fear of overflow. If */
  155. /* the computed bound is greater than a large constant, x is scaled to */
  156. /* prevent overflow, but if the bound overflows, x is set to 0, x(j) to */
  157. /* 1, and scale to 0, and a non-trivial solution to A*x = 0 is found. */
  158. /* Similarly, a row-wise scheme is used to solve A'*x = b. The basic */
  159. /* algorithm for A upper triangular is */
  160. /* for j = 1, ..., n */
  161. /* x(j) := ( b(j) - A[1:j-1,j]' * x[1:j-1] ) / A(j,j) */
  162. /* end */
  163. /* We simultaneously compute two bounds */
  164. /* G(j) = bound on ( b(i) - A[1:i-1,i]' * x[1:i-1] ), 1<=i<=j */
  165. /* M(j) = bound on x(i), 1<=i<=j */
  166. /* The initial values are G(0) = 0, M(0) = max{b(i), i=1,..,n}, and we */
  167. /* add the constraint G(j) >= G(j-1) and M(j) >= M(j-1) for j >= 1. */
  168. /* Then the bound on x(j) is */
  169. /* M(j) <= M(j-1) * ( 1 + CNORM(j) ) / | A(j,j) | */
  170. /* <= M(0) * product ( ( 1 + CNORM(i) ) / |A(i,i)| ) */
  171. /* 1<=i<=j */
  172. /* and we can safely call DTBSV if 1/M(n) and 1/G(n) are both greater */
  173. /* than max(underflow, 1/overflow). */
  174. /* ===================================================================== */
  175. /* .. Parameters .. */
  176. /* .. */
  177. /* .. Local Scalars .. */
  178. /* .. */
  179. /* .. External Functions .. */
  180. /* .. */
  181. /* .. External Subroutines .. */
  182. /* .. */
  183. /* .. Intrinsic Functions .. */
  184. /* .. */
  185. /* .. Executable Statements .. */
  186. /* Parameter adjustments */
  187. ab_dim1 = *ldab;
  188. ab_offset = 1 + ab_dim1;
  189. ab -= ab_offset;
  190. --x;
  191. --cnorm;
  192. /* Function Body */
  193. *info = 0;
  194. upper = _starpu_lsame_(uplo, "U");
  195. notran = _starpu_lsame_(trans, "N");
  196. nounit = _starpu_lsame_(diag, "N");
  197. /* Test the input parameters. */
  198. if (! upper && ! _starpu_lsame_(uplo, "L")) {
  199. *info = -1;
  200. } else if (! notran && ! _starpu_lsame_(trans, "T") && !
  201. _starpu_lsame_(trans, "C")) {
  202. *info = -2;
  203. } else if (! nounit && ! _starpu_lsame_(diag, "U")) {
  204. *info = -3;
  205. } else if (! _starpu_lsame_(normin, "Y") && ! _starpu_lsame_(normin,
  206. "N")) {
  207. *info = -4;
  208. } else if (*n < 0) {
  209. *info = -5;
  210. } else if (*kd < 0) {
  211. *info = -6;
  212. } else if (*ldab < *kd + 1) {
  213. *info = -8;
  214. }
  215. if (*info != 0) {
  216. i__1 = -(*info);
  217. _starpu_xerbla_("DLATBS", &i__1);
  218. return 0;
  219. }
  220. /* Quick return if possible */
  221. if (*n == 0) {
  222. return 0;
  223. }
  224. /* Determine machine dependent parameters to control overflow. */
  225. smlnum = _starpu_dlamch_("Safe minimum") / _starpu_dlamch_("Precision");
  226. bignum = 1. / smlnum;
  227. *scale = 1.;
  228. if (_starpu_lsame_(normin, "N")) {
  229. /* Compute the 1-norm of each column, not including the diagonal. */
  230. if (upper) {
  231. /* A is upper triangular. */
  232. i__1 = *n;
  233. for (j = 1; j <= i__1; ++j) {
  234. /* Computing MIN */
  235. i__2 = *kd, i__3 = j - 1;
  236. jlen = min(i__2,i__3);
  237. cnorm[j] = _starpu_dasum_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1], &
  238. c__1);
  239. /* L10: */
  240. }
  241. } else {
  242. /* A is lower triangular. */
  243. i__1 = *n;
  244. for (j = 1; j <= i__1; ++j) {
  245. /* Computing MIN */
  246. i__2 = *kd, i__3 = *n - j;
  247. jlen = min(i__2,i__3);
  248. if (jlen > 0) {
  249. cnorm[j] = _starpu_dasum_(&jlen, &ab[j * ab_dim1 + 2], &c__1);
  250. } else {
  251. cnorm[j] = 0.;
  252. }
  253. /* L20: */
  254. }
  255. }
  256. }
  257. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  258. /* greater than BIGNUM. */
  259. imax = _starpu_idamax_(n, &cnorm[1], &c__1);
  260. tmax = cnorm[imax];
  261. if (tmax <= bignum) {
  262. tscal = 1.;
  263. } else {
  264. tscal = 1. / (smlnum * tmax);
  265. _starpu_dscal_(n, &tscal, &cnorm[1], &c__1);
  266. }
  267. /* Compute a bound on the computed solution vector to see if the */
  268. /* Level 2 BLAS routine DTBSV can be used. */
  269. j = _starpu_idamax_(n, &x[1], &c__1);
  270. xmax = (d__1 = x[j], abs(d__1));
  271. xbnd = xmax;
  272. if (notran) {
  273. /* Compute the growth in A * x = b. */
  274. if (upper) {
  275. jfirst = *n;
  276. jlast = 1;
  277. jinc = -1;
  278. maind = *kd + 1;
  279. } else {
  280. jfirst = 1;
  281. jlast = *n;
  282. jinc = 1;
  283. maind = 1;
  284. }
  285. if (tscal != 1.) {
  286. grow = 0.;
  287. goto L50;
  288. }
  289. if (nounit) {
  290. /* A is non-unit triangular. */
  291. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  292. /* Initially, G(0) = max{x(i), i=1,...,n}. */
  293. grow = 1. / max(xbnd,smlnum);
  294. xbnd = grow;
  295. i__1 = jlast;
  296. i__2 = jinc;
  297. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  298. /* Exit the loop if the growth factor is too small. */
  299. if (grow <= smlnum) {
  300. goto L50;
  301. }
  302. /* M(j) = G(j-1) / abs(A(j,j)) */
  303. tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
  304. /* Computing MIN */
  305. d__1 = xbnd, d__2 = min(1.,tjj) * grow;
  306. xbnd = min(d__1,d__2);
  307. if (tjj + cnorm[j] >= smlnum) {
  308. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  309. grow *= tjj / (tjj + cnorm[j]);
  310. } else {
  311. /* G(j) could overflow, set GROW to 0. */
  312. grow = 0.;
  313. }
  314. /* L30: */
  315. }
  316. grow = xbnd;
  317. } else {
  318. /* A is unit triangular. */
  319. /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
  320. /* Computing MIN */
  321. d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
  322. grow = min(d__1,d__2);
  323. i__2 = jlast;
  324. i__1 = jinc;
  325. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  326. /* Exit the loop if the growth factor is too small. */
  327. if (grow <= smlnum) {
  328. goto L50;
  329. }
  330. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  331. grow *= 1. / (cnorm[j] + 1.);
  332. /* L40: */
  333. }
  334. }
  335. L50:
  336. ;
  337. } else {
  338. /* Compute the growth in A' * x = b. */
  339. if (upper) {
  340. jfirst = 1;
  341. jlast = *n;
  342. jinc = 1;
  343. maind = *kd + 1;
  344. } else {
  345. jfirst = *n;
  346. jlast = 1;
  347. jinc = -1;
  348. maind = 1;
  349. }
  350. if (tscal != 1.) {
  351. grow = 0.;
  352. goto L80;
  353. }
  354. if (nounit) {
  355. /* A is non-unit triangular. */
  356. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  357. /* Initially, M(0) = max{x(i), i=1,...,n}. */
  358. grow = 1. / max(xbnd,smlnum);
  359. xbnd = grow;
  360. i__1 = jlast;
  361. i__2 = jinc;
  362. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  363. /* Exit the loop if the growth factor is too small. */
  364. if (grow <= smlnum) {
  365. goto L80;
  366. }
  367. /* G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  368. xj = cnorm[j] + 1.;
  369. /* Computing MIN */
  370. d__1 = grow, d__2 = xbnd / xj;
  371. grow = min(d__1,d__2);
  372. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  373. tjj = (d__1 = ab[maind + j * ab_dim1], abs(d__1));
  374. if (xj > tjj) {
  375. xbnd *= tjj / xj;
  376. }
  377. /* L60: */
  378. }
  379. grow = min(grow,xbnd);
  380. } else {
  381. /* A is unit triangular. */
  382. /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
  383. /* Computing MIN */
  384. d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
  385. grow = min(d__1,d__2);
  386. i__2 = jlast;
  387. i__1 = jinc;
  388. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  389. /* Exit the loop if the growth factor is too small. */
  390. if (grow <= smlnum) {
  391. goto L80;
  392. }
  393. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  394. xj = cnorm[j] + 1.;
  395. grow /= xj;
  396. /* L70: */
  397. }
  398. }
  399. L80:
  400. ;
  401. }
  402. if (grow * tscal > smlnum) {
  403. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  404. /* elements of X is not too small. */
  405. _starpu_dtbsv_(uplo, trans, diag, n, kd, &ab[ab_offset], ldab, &x[1], &c__1);
  406. } else {
  407. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  408. if (xmax > bignum) {
  409. /* Scale X so that its components are less than or equal to */
  410. /* BIGNUM in absolute value. */
  411. *scale = bignum / xmax;
  412. _starpu_dscal_(n, scale, &x[1], &c__1);
  413. xmax = bignum;
  414. }
  415. if (notran) {
  416. /* Solve A * x = b */
  417. i__1 = jlast;
  418. i__2 = jinc;
  419. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  420. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  421. xj = (d__1 = x[j], abs(d__1));
  422. if (nounit) {
  423. tjjs = ab[maind + j * ab_dim1] * tscal;
  424. } else {
  425. tjjs = tscal;
  426. if (tscal == 1.) {
  427. goto L100;
  428. }
  429. }
  430. tjj = abs(tjjs);
  431. if (tjj > smlnum) {
  432. /* abs(A(j,j)) > SMLNUM: */
  433. if (tjj < 1.) {
  434. if (xj > tjj * bignum) {
  435. /* Scale x by 1/b(j). */
  436. rec = 1. / xj;
  437. _starpu_dscal_(n, &rec, &x[1], &c__1);
  438. *scale *= rec;
  439. xmax *= rec;
  440. }
  441. }
  442. x[j] /= tjjs;
  443. xj = (d__1 = x[j], abs(d__1));
  444. } else if (tjj > 0.) {
  445. /* 0 < abs(A(j,j)) <= SMLNUM: */
  446. if (xj > tjj * bignum) {
  447. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  448. /* to avoid overflow when dividing by A(j,j). */
  449. rec = tjj * bignum / xj;
  450. if (cnorm[j] > 1.) {
  451. /* Scale by 1/CNORM(j) to avoid overflow when */
  452. /* multiplying x(j) times column j. */
  453. rec /= cnorm[j];
  454. }
  455. _starpu_dscal_(n, &rec, &x[1], &c__1);
  456. *scale *= rec;
  457. xmax *= rec;
  458. }
  459. x[j] /= tjjs;
  460. xj = (d__1 = x[j], abs(d__1));
  461. } else {
  462. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  463. /* scale = 0, and compute a solution to A*x = 0. */
  464. i__3 = *n;
  465. for (i__ = 1; i__ <= i__3; ++i__) {
  466. x[i__] = 0.;
  467. /* L90: */
  468. }
  469. x[j] = 1.;
  470. xj = 1.;
  471. *scale = 0.;
  472. xmax = 0.;
  473. }
  474. L100:
  475. /* Scale x if necessary to avoid overflow when adding a */
  476. /* multiple of column j of A. */
  477. if (xj > 1.) {
  478. rec = 1. / xj;
  479. if (cnorm[j] > (bignum - xmax) * rec) {
  480. /* Scale x by 1/(2*abs(x(j))). */
  481. rec *= .5;
  482. _starpu_dscal_(n, &rec, &x[1], &c__1);
  483. *scale *= rec;
  484. }
  485. } else if (xj * cnorm[j] > bignum - xmax) {
  486. /* Scale x by 1/2. */
  487. _starpu_dscal_(n, &c_b36, &x[1], &c__1);
  488. *scale *= .5;
  489. }
  490. if (upper) {
  491. if (j > 1) {
  492. /* Compute the update */
  493. /* x(max(1,j-kd):j-1) := x(max(1,j-kd):j-1) - */
  494. /* x(j)* A(max(1,j-kd):j-1,j) */
  495. /* Computing MIN */
  496. i__3 = *kd, i__4 = j - 1;
  497. jlen = min(i__3,i__4);
  498. d__1 = -x[j] * tscal;
  499. _starpu_daxpy_(&jlen, &d__1, &ab[*kd + 1 - jlen + j * ab_dim1]
  500. , &c__1, &x[j - jlen], &c__1);
  501. i__3 = j - 1;
  502. i__ = _starpu_idamax_(&i__3, &x[1], &c__1);
  503. xmax = (d__1 = x[i__], abs(d__1));
  504. }
  505. } else if (j < *n) {
  506. /* Compute the update */
  507. /* x(j+1:min(j+kd,n)) := x(j+1:min(j+kd,n)) - */
  508. /* x(j) * A(j+1:min(j+kd,n),j) */
  509. /* Computing MIN */
  510. i__3 = *kd, i__4 = *n - j;
  511. jlen = min(i__3,i__4);
  512. if (jlen > 0) {
  513. d__1 = -x[j] * tscal;
  514. _starpu_daxpy_(&jlen, &d__1, &ab[j * ab_dim1 + 2], &c__1, &x[
  515. j + 1], &c__1);
  516. }
  517. i__3 = *n - j;
  518. i__ = j + _starpu_idamax_(&i__3, &x[j + 1], &c__1);
  519. xmax = (d__1 = x[i__], abs(d__1));
  520. }
  521. /* L110: */
  522. }
  523. } else {
  524. /* Solve A' * x = b */
  525. i__2 = jlast;
  526. i__1 = jinc;
  527. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  528. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  529. /* k<>j */
  530. xj = (d__1 = x[j], abs(d__1));
  531. uscal = tscal;
  532. rec = 1. / max(xmax,1.);
  533. if (cnorm[j] > (bignum - xj) * rec) {
  534. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  535. rec *= .5;
  536. if (nounit) {
  537. tjjs = ab[maind + j * ab_dim1] * tscal;
  538. } else {
  539. tjjs = tscal;
  540. }
  541. tjj = abs(tjjs);
  542. if (tjj > 1.) {
  543. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  544. /* Computing MIN */
  545. d__1 = 1., d__2 = rec * tjj;
  546. rec = min(d__1,d__2);
  547. uscal /= tjjs;
  548. }
  549. if (rec < 1.) {
  550. _starpu_dscal_(n, &rec, &x[1], &c__1);
  551. *scale *= rec;
  552. xmax *= rec;
  553. }
  554. }
  555. sumj = 0.;
  556. if (uscal == 1.) {
  557. /* If the scaling needed for A in the dot product is 1, */
  558. /* call DDOT to perform the dot product. */
  559. if (upper) {
  560. /* Computing MIN */
  561. i__3 = *kd, i__4 = j - 1;
  562. jlen = min(i__3,i__4);
  563. sumj = _starpu_ddot_(&jlen, &ab[*kd + 1 - jlen + j * ab_dim1],
  564. &c__1, &x[j - jlen], &c__1);
  565. } else {
  566. /* Computing MIN */
  567. i__3 = *kd, i__4 = *n - j;
  568. jlen = min(i__3,i__4);
  569. if (jlen > 0) {
  570. sumj = _starpu_ddot_(&jlen, &ab[j * ab_dim1 + 2], &c__1, &
  571. x[j + 1], &c__1);
  572. }
  573. }
  574. } else {
  575. /* Otherwise, use in-line code for the dot product. */
  576. if (upper) {
  577. /* Computing MIN */
  578. i__3 = *kd, i__4 = j - 1;
  579. jlen = min(i__3,i__4);
  580. i__3 = jlen;
  581. for (i__ = 1; i__ <= i__3; ++i__) {
  582. sumj += ab[*kd + i__ - jlen + j * ab_dim1] *
  583. uscal * x[j - jlen - 1 + i__];
  584. /* L120: */
  585. }
  586. } else {
  587. /* Computing MIN */
  588. i__3 = *kd, i__4 = *n - j;
  589. jlen = min(i__3,i__4);
  590. i__3 = jlen;
  591. for (i__ = 1; i__ <= i__3; ++i__) {
  592. sumj += ab[i__ + 1 + j * ab_dim1] * uscal * x[j +
  593. i__];
  594. /* L130: */
  595. }
  596. }
  597. }
  598. if (uscal == tscal) {
  599. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  600. /* was not used to scale the dotproduct. */
  601. x[j] -= sumj;
  602. xj = (d__1 = x[j], abs(d__1));
  603. if (nounit) {
  604. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  605. tjjs = ab[maind + j * ab_dim1] * tscal;
  606. } else {
  607. tjjs = tscal;
  608. if (tscal == 1.) {
  609. goto L150;
  610. }
  611. }
  612. tjj = abs(tjjs);
  613. if (tjj > smlnum) {
  614. /* abs(A(j,j)) > SMLNUM: */
  615. if (tjj < 1.) {
  616. if (xj > tjj * bignum) {
  617. /* Scale X by 1/abs(x(j)). */
  618. rec = 1. / xj;
  619. _starpu_dscal_(n, &rec, &x[1], &c__1);
  620. *scale *= rec;
  621. xmax *= rec;
  622. }
  623. }
  624. x[j] /= tjjs;
  625. } else if (tjj > 0.) {
  626. /* 0 < abs(A(j,j)) <= SMLNUM: */
  627. if (xj > tjj * bignum) {
  628. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  629. rec = tjj * bignum / xj;
  630. _starpu_dscal_(n, &rec, &x[1], &c__1);
  631. *scale *= rec;
  632. xmax *= rec;
  633. }
  634. x[j] /= tjjs;
  635. } else {
  636. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  637. /* scale = 0, and compute a solution to A'*x = 0. */
  638. i__3 = *n;
  639. for (i__ = 1; i__ <= i__3; ++i__) {
  640. x[i__] = 0.;
  641. /* L140: */
  642. }
  643. x[j] = 1.;
  644. *scale = 0.;
  645. xmax = 0.;
  646. }
  647. L150:
  648. ;
  649. } else {
  650. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  651. /* product has already been divided by 1/A(j,j). */
  652. x[j] = x[j] / tjjs - sumj;
  653. }
  654. /* Computing MAX */
  655. d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
  656. xmax = max(d__2,d__3);
  657. /* L160: */
  658. }
  659. }
  660. *scale /= tscal;
  661. }
  662. /* Scale the column norms by 1/TSCAL for return. */
  663. if (tscal != 1.) {
  664. d__1 = 1. / tscal;
  665. _starpu_dscal_(n, &d__1, &cnorm[1], &c__1);
  666. }
  667. return 0;
  668. /* End of DLATBS */
  669. } /* _starpu_dlatbs_ */