dlatrs.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816
  1. /* dlatrs.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_dlatrs_(char *uplo, char *trans, char *diag, char *
  17. normin, integer *n, doublereal *a, integer *lda, doublereal *x,
  18. doublereal *scale, doublereal *cnorm, integer *info)
  19. {
  20. /* System generated locals */
  21. integer a_dim1, a_offset, i__1, i__2, i__3;
  22. doublereal d__1, d__2, d__3;
  23. /* Local variables */
  24. integer i__, j;
  25. doublereal xj, rec, tjj;
  26. integer jinc;
  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. extern logical _starpu_lsame_(char *, char *);
  35. doublereal tscal, uscal;
  36. extern doublereal _starpu_dasum_(integer *, doublereal *, integer *);
  37. integer jlast;
  38. extern /* Subroutine */ int _starpu_daxpy_(integer *, doublereal *, doublereal *,
  39. integer *, doublereal *, integer *);
  40. logical upper;
  41. extern /* Subroutine */ int _starpu_dtrsv_(char *, char *, char *, integer *,
  42. doublereal *, integer *, doublereal *, integer *);
  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. /* DLATRS solves one of the triangular systems */
  61. /* A *x = s*b or A'*x = s*b */
  62. /* with scaling to prevent overflow. Here A is an upper or lower */
  63. /* triangular matrix, A' denotes the transpose of A, x and b are */
  64. /* 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 DTRSV 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. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  93. /* The triangular matrix A. If UPLO = 'U', the leading n by n */
  94. /* upper triangular part of the array A contains the upper */
  95. /* triangular matrix, and the strictly lower triangular part of */
  96. /* A is not referenced. If UPLO = 'L', the leading n by n lower */
  97. /* triangular part of the array A contains the lower triangular */
  98. /* matrix, and the strictly upper triangular part of A is not */
  99. /* referenced. If DIAG = 'U', the diagonal elements of A are */
  100. /* also not referenced and are assumed to be 1. */
  101. /* LDA (input) INTEGER */
  102. /* The leading dimension of the array A. LDA >= max (1,N). */
  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, DTRSV */
  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 DTRSV 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 DTRSV 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. a_dim1 = *lda;
  188. a_offset = 1 + a_dim1;
  189. a -= a_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 (*lda < max(1,*n)) {
  211. *info = -7;
  212. }
  213. if (*info != 0) {
  214. i__1 = -(*info);
  215. _starpu_xerbla_("DLATRS", &i__1);
  216. return 0;
  217. }
  218. /* Quick return if possible */
  219. if (*n == 0) {
  220. return 0;
  221. }
  222. /* Determine machine dependent parameters to control overflow. */
  223. smlnum = _starpu_dlamch_("Safe minimum") / _starpu_dlamch_("Precision");
  224. bignum = 1. / smlnum;
  225. *scale = 1.;
  226. if (_starpu_lsame_(normin, "N")) {
  227. /* Compute the 1-norm of each column, not including the diagonal. */
  228. if (upper) {
  229. /* A is upper triangular. */
  230. i__1 = *n;
  231. for (j = 1; j <= i__1; ++j) {
  232. i__2 = j - 1;
  233. cnorm[j] = _starpu_dasum_(&i__2, &a[j * a_dim1 + 1], &c__1);
  234. /* L10: */
  235. }
  236. } else {
  237. /* A is lower triangular. */
  238. i__1 = *n - 1;
  239. for (j = 1; j <= i__1; ++j) {
  240. i__2 = *n - j;
  241. cnorm[j] = _starpu_dasum_(&i__2, &a[j + 1 + j * a_dim1], &c__1);
  242. /* L20: */
  243. }
  244. cnorm[*n] = 0.;
  245. }
  246. }
  247. /* Scale the column norms by TSCAL if the maximum element in CNORM is */
  248. /* greater than BIGNUM. */
  249. imax = _starpu_idamax_(n, &cnorm[1], &c__1);
  250. tmax = cnorm[imax];
  251. if (tmax <= bignum) {
  252. tscal = 1.;
  253. } else {
  254. tscal = 1. / (smlnum * tmax);
  255. _starpu_dscal_(n, &tscal, &cnorm[1], &c__1);
  256. }
  257. /* Compute a bound on the computed solution vector to see if the */
  258. /* Level 2 BLAS routine DTRSV can be used. */
  259. j = _starpu_idamax_(n, &x[1], &c__1);
  260. xmax = (d__1 = x[j], abs(d__1));
  261. xbnd = xmax;
  262. if (notran) {
  263. /* Compute the growth in A * x = b. */
  264. if (upper) {
  265. jfirst = *n;
  266. jlast = 1;
  267. jinc = -1;
  268. } else {
  269. jfirst = 1;
  270. jlast = *n;
  271. jinc = 1;
  272. }
  273. if (tscal != 1.) {
  274. grow = 0.;
  275. goto L50;
  276. }
  277. if (nounit) {
  278. /* A is non-unit triangular. */
  279. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  280. /* Initially, G(0) = max{x(i), i=1,...,n}. */
  281. grow = 1. / max(xbnd,smlnum);
  282. xbnd = grow;
  283. i__1 = jlast;
  284. i__2 = jinc;
  285. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  286. /* Exit the loop if the growth factor is too small. */
  287. if (grow <= smlnum) {
  288. goto L50;
  289. }
  290. /* M(j) = G(j-1) / abs(A(j,j)) */
  291. tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
  292. /* Computing MIN */
  293. d__1 = xbnd, d__2 = min(1.,tjj) * grow;
  294. xbnd = min(d__1,d__2);
  295. if (tjj + cnorm[j] >= smlnum) {
  296. /* G(j) = G(j-1)*( 1 + CNORM(j) / abs(A(j,j)) ) */
  297. grow *= tjj / (tjj + cnorm[j]);
  298. } else {
  299. /* G(j) could overflow, set GROW to 0. */
  300. grow = 0.;
  301. }
  302. /* L30: */
  303. }
  304. grow = xbnd;
  305. } else {
  306. /* A is unit triangular. */
  307. /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
  308. /* Computing MIN */
  309. d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
  310. grow = min(d__1,d__2);
  311. i__2 = jlast;
  312. i__1 = jinc;
  313. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  314. /* Exit the loop if the growth factor is too small. */
  315. if (grow <= smlnum) {
  316. goto L50;
  317. }
  318. /* G(j) = G(j-1)*( 1 + CNORM(j) ) */
  319. grow *= 1. / (cnorm[j] + 1.);
  320. /* L40: */
  321. }
  322. }
  323. L50:
  324. ;
  325. } else {
  326. /* Compute the growth in A' * x = b. */
  327. if (upper) {
  328. jfirst = 1;
  329. jlast = *n;
  330. jinc = 1;
  331. } else {
  332. jfirst = *n;
  333. jlast = 1;
  334. jinc = -1;
  335. }
  336. if (tscal != 1.) {
  337. grow = 0.;
  338. goto L80;
  339. }
  340. if (nounit) {
  341. /* A is non-unit triangular. */
  342. /* Compute GROW = 1/G(j) and XBND = 1/M(j). */
  343. /* Initially, M(0) = max{x(i), i=1,...,n}. */
  344. grow = 1. / max(xbnd,smlnum);
  345. xbnd = grow;
  346. i__1 = jlast;
  347. i__2 = jinc;
  348. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  349. /* Exit the loop if the growth factor is too small. */
  350. if (grow <= smlnum) {
  351. goto L80;
  352. }
  353. /* G(j) = max( G(j-1), M(j-1)*( 1 + CNORM(j) ) ) */
  354. xj = cnorm[j] + 1.;
  355. /* Computing MIN */
  356. d__1 = grow, d__2 = xbnd / xj;
  357. grow = min(d__1,d__2);
  358. /* M(j) = M(j-1)*( 1 + CNORM(j) ) / abs(A(j,j)) */
  359. tjj = (d__1 = a[j + j * a_dim1], abs(d__1));
  360. if (xj > tjj) {
  361. xbnd *= tjj / xj;
  362. }
  363. /* L60: */
  364. }
  365. grow = min(grow,xbnd);
  366. } else {
  367. /* A is unit triangular. */
  368. /* Compute GROW = 1/G(j), where G(0) = max{x(i), i=1,...,n}. */
  369. /* Computing MIN */
  370. d__1 = 1., d__2 = 1. / max(xbnd,smlnum);
  371. grow = min(d__1,d__2);
  372. i__2 = jlast;
  373. i__1 = jinc;
  374. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  375. /* Exit the loop if the growth factor is too small. */
  376. if (grow <= smlnum) {
  377. goto L80;
  378. }
  379. /* G(j) = ( 1 + CNORM(j) )*G(j-1) */
  380. xj = cnorm[j] + 1.;
  381. grow /= xj;
  382. /* L70: */
  383. }
  384. }
  385. L80:
  386. ;
  387. }
  388. if (grow * tscal > smlnum) {
  389. /* Use the Level 2 BLAS solve if the reciprocal of the bound on */
  390. /* elements of X is not too small. */
  391. _starpu_dtrsv_(uplo, trans, diag, n, &a[a_offset], lda, &x[1], &c__1);
  392. } else {
  393. /* Use a Level 1 BLAS solve, scaling intermediate results. */
  394. if (xmax > bignum) {
  395. /* Scale X so that its components are less than or equal to */
  396. /* BIGNUM in absolute value. */
  397. *scale = bignum / xmax;
  398. _starpu_dscal_(n, scale, &x[1], &c__1);
  399. xmax = bignum;
  400. }
  401. if (notran) {
  402. /* Solve A * x = b */
  403. i__1 = jlast;
  404. i__2 = jinc;
  405. for (j = jfirst; i__2 < 0 ? j >= i__1 : j <= i__1; j += i__2) {
  406. /* Compute x(j) = b(j) / A(j,j), scaling x if necessary. */
  407. xj = (d__1 = x[j], abs(d__1));
  408. if (nounit) {
  409. tjjs = a[j + j * a_dim1] * tscal;
  410. } else {
  411. tjjs = tscal;
  412. if (tscal == 1.) {
  413. goto L100;
  414. }
  415. }
  416. tjj = abs(tjjs);
  417. if (tjj > smlnum) {
  418. /* abs(A(j,j)) > SMLNUM: */
  419. if (tjj < 1.) {
  420. if (xj > tjj * bignum) {
  421. /* Scale x by 1/b(j). */
  422. rec = 1. / xj;
  423. _starpu_dscal_(n, &rec, &x[1], &c__1);
  424. *scale *= rec;
  425. xmax *= rec;
  426. }
  427. }
  428. x[j] /= tjjs;
  429. xj = (d__1 = x[j], abs(d__1));
  430. } else if (tjj > 0.) {
  431. /* 0 < abs(A(j,j)) <= SMLNUM: */
  432. if (xj > tjj * bignum) {
  433. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM */
  434. /* to avoid overflow when dividing by A(j,j). */
  435. rec = tjj * bignum / xj;
  436. if (cnorm[j] > 1.) {
  437. /* Scale by 1/CNORM(j) to avoid overflow when */
  438. /* multiplying x(j) times column j. */
  439. rec /= cnorm[j];
  440. }
  441. _starpu_dscal_(n, &rec, &x[1], &c__1);
  442. *scale *= rec;
  443. xmax *= rec;
  444. }
  445. x[j] /= tjjs;
  446. xj = (d__1 = x[j], abs(d__1));
  447. } else {
  448. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  449. /* scale = 0, and compute a solution to A*x = 0. */
  450. i__3 = *n;
  451. for (i__ = 1; i__ <= i__3; ++i__) {
  452. x[i__] = 0.;
  453. /* L90: */
  454. }
  455. x[j] = 1.;
  456. xj = 1.;
  457. *scale = 0.;
  458. xmax = 0.;
  459. }
  460. L100:
  461. /* Scale x if necessary to avoid overflow when adding a */
  462. /* multiple of column j of A. */
  463. if (xj > 1.) {
  464. rec = 1. / xj;
  465. if (cnorm[j] > (bignum - xmax) * rec) {
  466. /* Scale x by 1/(2*abs(x(j))). */
  467. rec *= .5;
  468. _starpu_dscal_(n, &rec, &x[1], &c__1);
  469. *scale *= rec;
  470. }
  471. } else if (xj * cnorm[j] > bignum - xmax) {
  472. /* Scale x by 1/2. */
  473. _starpu_dscal_(n, &c_b36, &x[1], &c__1);
  474. *scale *= .5;
  475. }
  476. if (upper) {
  477. if (j > 1) {
  478. /* Compute the update */
  479. /* x(1:j-1) := x(1:j-1) - x(j) * A(1:j-1,j) */
  480. i__3 = j - 1;
  481. d__1 = -x[j] * tscal;
  482. _starpu_daxpy_(&i__3, &d__1, &a[j * a_dim1 + 1], &c__1, &x[1],
  483. &c__1);
  484. i__3 = j - 1;
  485. i__ = _starpu_idamax_(&i__3, &x[1], &c__1);
  486. xmax = (d__1 = x[i__], abs(d__1));
  487. }
  488. } else {
  489. if (j < *n) {
  490. /* Compute the update */
  491. /* x(j+1:n) := x(j+1:n) - x(j) * A(j+1:n,j) */
  492. i__3 = *n - j;
  493. d__1 = -x[j] * tscal;
  494. _starpu_daxpy_(&i__3, &d__1, &a[j + 1 + j * a_dim1], &c__1, &
  495. x[j + 1], &c__1);
  496. i__3 = *n - j;
  497. i__ = j + _starpu_idamax_(&i__3, &x[j + 1], &c__1);
  498. xmax = (d__1 = x[i__], abs(d__1));
  499. }
  500. }
  501. /* L110: */
  502. }
  503. } else {
  504. /* Solve A' * x = b */
  505. i__2 = jlast;
  506. i__1 = jinc;
  507. for (j = jfirst; i__1 < 0 ? j >= i__2 : j <= i__2; j += i__1) {
  508. /* Compute x(j) = b(j) - sum A(k,j)*x(k). */
  509. /* k<>j */
  510. xj = (d__1 = x[j], abs(d__1));
  511. uscal = tscal;
  512. rec = 1. / max(xmax,1.);
  513. if (cnorm[j] > (bignum - xj) * rec) {
  514. /* If x(j) could overflow, scale x by 1/(2*XMAX). */
  515. rec *= .5;
  516. if (nounit) {
  517. tjjs = a[j + j * a_dim1] * tscal;
  518. } else {
  519. tjjs = tscal;
  520. }
  521. tjj = abs(tjjs);
  522. if (tjj > 1.) {
  523. /* Divide by A(j,j) when scaling x if A(j,j) > 1. */
  524. /* Computing MIN */
  525. d__1 = 1., d__2 = rec * tjj;
  526. rec = min(d__1,d__2);
  527. uscal /= tjjs;
  528. }
  529. if (rec < 1.) {
  530. _starpu_dscal_(n, &rec, &x[1], &c__1);
  531. *scale *= rec;
  532. xmax *= rec;
  533. }
  534. }
  535. sumj = 0.;
  536. if (uscal == 1.) {
  537. /* If the scaling needed for A in the dot product is 1, */
  538. /* call DDOT to perform the dot product. */
  539. if (upper) {
  540. i__3 = j - 1;
  541. sumj = _starpu_ddot_(&i__3, &a[j * a_dim1 + 1], &c__1, &x[1],
  542. &c__1);
  543. } else if (j < *n) {
  544. i__3 = *n - j;
  545. sumj = _starpu_ddot_(&i__3, &a[j + 1 + j * a_dim1], &c__1, &x[
  546. j + 1], &c__1);
  547. }
  548. } else {
  549. /* Otherwise, use in-line code for the dot product. */
  550. if (upper) {
  551. i__3 = j - 1;
  552. for (i__ = 1; i__ <= i__3; ++i__) {
  553. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  554. /* L120: */
  555. }
  556. } else if (j < *n) {
  557. i__3 = *n;
  558. for (i__ = j + 1; i__ <= i__3; ++i__) {
  559. sumj += a[i__ + j * a_dim1] * uscal * x[i__];
  560. /* L130: */
  561. }
  562. }
  563. }
  564. if (uscal == tscal) {
  565. /* Compute x(j) := ( x(j) - sumj ) / A(j,j) if 1/A(j,j) */
  566. /* was not used to scale the dotproduct. */
  567. x[j] -= sumj;
  568. xj = (d__1 = x[j], abs(d__1));
  569. if (nounit) {
  570. tjjs = a[j + j * a_dim1] * tscal;
  571. } else {
  572. tjjs = tscal;
  573. if (tscal == 1.) {
  574. goto L150;
  575. }
  576. }
  577. /* Compute x(j) = x(j) / A(j,j), scaling if necessary. */
  578. tjj = abs(tjjs);
  579. if (tjj > smlnum) {
  580. /* abs(A(j,j)) > SMLNUM: */
  581. if (tjj < 1.) {
  582. if (xj > tjj * bignum) {
  583. /* Scale X by 1/abs(x(j)). */
  584. rec = 1. / xj;
  585. _starpu_dscal_(n, &rec, &x[1], &c__1);
  586. *scale *= rec;
  587. xmax *= rec;
  588. }
  589. }
  590. x[j] /= tjjs;
  591. } else if (tjj > 0.) {
  592. /* 0 < abs(A(j,j)) <= SMLNUM: */
  593. if (xj > tjj * bignum) {
  594. /* Scale x by (1/abs(x(j)))*abs(A(j,j))*BIGNUM. */
  595. rec = tjj * bignum / xj;
  596. _starpu_dscal_(n, &rec, &x[1], &c__1);
  597. *scale *= rec;
  598. xmax *= rec;
  599. }
  600. x[j] /= tjjs;
  601. } else {
  602. /* A(j,j) = 0: Set x(1:n) = 0, x(j) = 1, and */
  603. /* scale = 0, and compute a solution to A'*x = 0. */
  604. i__3 = *n;
  605. for (i__ = 1; i__ <= i__3; ++i__) {
  606. x[i__] = 0.;
  607. /* L140: */
  608. }
  609. x[j] = 1.;
  610. *scale = 0.;
  611. xmax = 0.;
  612. }
  613. L150:
  614. ;
  615. } else {
  616. /* Compute x(j) := x(j) / A(j,j) - sumj if the dot */
  617. /* product has already been divided by 1/A(j,j). */
  618. x[j] = x[j] / tjjs - sumj;
  619. }
  620. /* Computing MAX */
  621. d__2 = xmax, d__3 = (d__1 = x[j], abs(d__1));
  622. xmax = max(d__2,d__3);
  623. /* L160: */
  624. }
  625. }
  626. *scale /= tscal;
  627. }
  628. /* Scale the column norms by 1/TSCAL for return. */
  629. if (tscal != 1.) {
  630. d__1 = 1. / tscal;
  631. _starpu_dscal_(n, &d__1, &cnorm[1], &c__1);
  632. }
  633. return 0;
  634. /* End of DLATRS */
  635. } /* _starpu_dlatrs_ */