dlatps.c 21 KB

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