dpbsvx.c 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516
  1. /* dpbsvx.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. /* Subroutine */ int _starpu_dpbsvx_(char *fact, char *uplo, integer *n, integer *kd,
  16. integer *nrhs, doublereal *ab, integer *ldab, doublereal *afb,
  17. integer *ldafb, char *equed, doublereal *s, doublereal *b, integer *
  18. ldb, doublereal *x, integer *ldx, doublereal *rcond, doublereal *ferr,
  19. doublereal *berr, doublereal *work, integer *iwork, integer *info)
  20. {
  21. /* System generated locals */
  22. integer ab_dim1, ab_offset, afb_dim1, afb_offset, b_dim1, b_offset,
  23. x_dim1, x_offset, i__1, i__2;
  24. doublereal d__1, d__2;
  25. /* Local variables */
  26. integer i__, j, j1, j2;
  27. doublereal amax, smin, smax;
  28. extern logical _starpu_lsame_(char *, char *);
  29. doublereal scond, anorm;
  30. extern /* Subroutine */ int _starpu_dcopy_(integer *, doublereal *, integer *,
  31. doublereal *, integer *);
  32. logical equil, rcequ, upper;
  33. extern doublereal _starpu_dlamch_(char *), _starpu_dlansb_(char *, char *,
  34. integer *, integer *, doublereal *, integer *, doublereal *);
  35. extern /* Subroutine */ int _starpu_dpbcon_(char *, integer *, integer *,
  36. doublereal *, integer *, doublereal *, doublereal *, doublereal *,
  37. integer *, integer *), _starpu_dlaqsb_(char *, integer *,
  38. integer *, doublereal *, integer *, doublereal *, doublereal *,
  39. doublereal *, char *);
  40. logical nofact;
  41. extern /* Subroutine */ int _starpu_dlacpy_(char *, integer *, integer *,
  42. doublereal *, integer *, doublereal *, integer *),
  43. _starpu_xerbla_(char *, integer *), _starpu_dpbequ_(char *, integer *,
  44. integer *, doublereal *, integer *, doublereal *, doublereal *,
  45. doublereal *, integer *);
  46. doublereal bignum;
  47. extern /* Subroutine */ int _starpu_dpbrfs_(char *, integer *, integer *, integer
  48. *, doublereal *, integer *, doublereal *, integer *, doublereal *,
  49. integer *, doublereal *, integer *, doublereal *, doublereal *,
  50. doublereal *, integer *, integer *), _starpu_dpbtrf_(char *,
  51. integer *, integer *, doublereal *, integer *, integer *);
  52. integer infequ;
  53. extern /* Subroutine */ int _starpu_dpbtrs_(char *, integer *, integer *, integer
  54. *, doublereal *, integer *, doublereal *, integer *, integer *);
  55. doublereal smlnum;
  56. /* -- LAPACK driver routine (version 3.2) -- */
  57. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  58. /* November 2006 */
  59. /* .. Scalar Arguments .. */
  60. /* .. */
  61. /* .. Array Arguments .. */
  62. /* .. */
  63. /* Purpose */
  64. /* ======= */
  65. /* DPBSVX uses the Cholesky factorization A = U**T*U or A = L*L**T to */
  66. /* compute the solution to a real system of linear equations */
  67. /* A * X = B, */
  68. /* where A is an N-by-N symmetric positive definite band matrix and X */
  69. /* and B are N-by-NRHS matrices. */
  70. /* Error bounds on the solution and a condition estimate are also */
  71. /* provided. */
  72. /* Description */
  73. /* =========== */
  74. /* The following steps are performed: */
  75. /* 1. If FACT = 'E', real scaling factors are computed to equilibrate */
  76. /* the system: */
  77. /* diag(S) * A * diag(S) * inv(diag(S)) * X = diag(S) * B */
  78. /* Whether or not the system will be equilibrated depends on the */
  79. /* scaling of the matrix A, but if equilibration is used, A is */
  80. /* overwritten by diag(S)*A*diag(S) and B by diag(S)*B. */
  81. /* 2. If FACT = 'N' or 'E', the Cholesky decomposition is used to */
  82. /* factor the matrix A (after equilibration if FACT = 'E') as */
  83. /* A = U**T * U, if UPLO = 'U', or */
  84. /* A = L * L**T, if UPLO = 'L', */
  85. /* where U is an upper triangular band matrix, and L is a lower */
  86. /* triangular band matrix. */
  87. /* 3. If the leading i-by-i principal minor is not positive definite, */
  88. /* then the routine returns with INFO = i. Otherwise, the factored */
  89. /* form of A is used to estimate the condition number of the matrix */
  90. /* A. If the reciprocal of the condition number is less than machine */
  91. /* precision, INFO = N+1 is returned as a warning, but the routine */
  92. /* still goes on to solve for X and compute error bounds as */
  93. /* described below. */
  94. /* 4. The system of equations is solved for X using the factored form */
  95. /* of A. */
  96. /* 5. Iterative refinement is applied to improve the computed solution */
  97. /* matrix and calculate error bounds and backward error estimates */
  98. /* for it. */
  99. /* 6. If equilibration was used, the matrix X is premultiplied by */
  100. /* diag(S) so that it solves the original system before */
  101. /* equilibration. */
  102. /* Arguments */
  103. /* ========= */
  104. /* FACT (input) CHARACTER*1 */
  105. /* Specifies whether or not the factored form of the matrix A is */
  106. /* supplied on entry, and if not, whether the matrix A should be */
  107. /* equilibrated before it is factored. */
  108. /* = 'F': On entry, AFB contains the factored form of A. */
  109. /* If EQUED = 'Y', the matrix A has been equilibrated */
  110. /* with scaling factors given by S. AB and AFB will not */
  111. /* be modified. */
  112. /* = 'N': The matrix A will be copied to AFB and factored. */
  113. /* = 'E': The matrix A will be equilibrated if necessary, then */
  114. /* copied to AFB and factored. */
  115. /* UPLO (input) CHARACTER*1 */
  116. /* = 'U': Upper triangle of A is stored; */
  117. /* = 'L': Lower triangle of A is stored. */
  118. /* N (input) INTEGER */
  119. /* The number of linear equations, i.e., the order of the */
  120. /* matrix A. N >= 0. */
  121. /* KD (input) INTEGER */
  122. /* The number of superdiagonals of the matrix A if UPLO = 'U', */
  123. /* or the number of subdiagonals if UPLO = 'L'. KD >= 0. */
  124. /* NRHS (input) INTEGER */
  125. /* The number of right-hand sides, i.e., the number of columns */
  126. /* of the matrices B and X. NRHS >= 0. */
  127. /* AB (input/output) DOUBLE PRECISION array, dimension (LDAB,N) */
  128. /* On entry, the upper or lower triangle of the symmetric band */
  129. /* matrix A, stored in the first KD+1 rows of the array, except */
  130. /* if FACT = 'F' and EQUED = 'Y', then A must contain the */
  131. /* equilibrated matrix diag(S)*A*diag(S). The j-th column of A */
  132. /* is stored in the j-th column of the array AB as follows: */
  133. /* if UPLO = 'U', AB(KD+1+i-j,j) = A(i,j) for max(1,j-KD)<=i<=j; */
  134. /* if UPLO = 'L', AB(1+i-j,j) = A(i,j) for j<=i<=min(N,j+KD). */
  135. /* See below for further details. */
  136. /* On exit, if FACT = 'E' and EQUED = 'Y', A is overwritten by */
  137. /* diag(S)*A*diag(S). */
  138. /* LDAB (input) INTEGER */
  139. /* The leading dimension of the array A. LDAB >= KD+1. */
  140. /* AFB (input or output) DOUBLE PRECISION array, dimension (LDAFB,N) */
  141. /* If FACT = 'F', then AFB is an input argument and on entry */
  142. /* contains the triangular factor U or L from the Cholesky */
  143. /* factorization A = U**T*U or A = L*L**T of the band matrix */
  144. /* A, in the same storage format as A (see AB). If EQUED = 'Y', */
  145. /* then AFB is the factored form of the equilibrated matrix A. */
  146. /* If FACT = 'N', then AFB is an output argument and on exit */
  147. /* returns the triangular factor U or L from the Cholesky */
  148. /* factorization A = U**T*U or A = L*L**T. */
  149. /* If FACT = 'E', then AFB is an output argument and on exit */
  150. /* returns the triangular factor U or L from the Cholesky */
  151. /* factorization A = U**T*U or A = L*L**T of the equilibrated */
  152. /* matrix A (see the description of A for the form of the */
  153. /* equilibrated matrix). */
  154. /* LDAFB (input) INTEGER */
  155. /* The leading dimension of the array AFB. LDAFB >= KD+1. */
  156. /* EQUED (input or output) CHARACTER*1 */
  157. /* Specifies the form of equilibration that was done. */
  158. /* = 'N': No equilibration (always true if FACT = 'N'). */
  159. /* = 'Y': Equilibration was done, i.e., A has been replaced by */
  160. /* diag(S) * A * diag(S). */
  161. /* EQUED is an input argument if FACT = 'F'; otherwise, it is an */
  162. /* output argument. */
  163. /* S (input or output) DOUBLE PRECISION array, dimension (N) */
  164. /* The scale factors for A; not accessed if EQUED = 'N'. S is */
  165. /* an input argument if FACT = 'F'; otherwise, S is an output */
  166. /* argument. If FACT = 'F' and EQUED = 'Y', each element of S */
  167. /* must be positive. */
  168. /* B (input/output) DOUBLE PRECISION array, dimension (LDB,NRHS) */
  169. /* On entry, the N-by-NRHS right hand side matrix B. */
  170. /* On exit, if EQUED = 'N', B is not modified; if EQUED = 'Y', */
  171. /* B is overwritten by diag(S) * B. */
  172. /* LDB (input) INTEGER */
  173. /* The leading dimension of the array B. LDB >= max(1,N). */
  174. /* X (output) DOUBLE PRECISION array, dimension (LDX,NRHS) */
  175. /* If INFO = 0 or INFO = N+1, the N-by-NRHS solution matrix X to */
  176. /* the original system of equations. Note that if EQUED = 'Y', */
  177. /* A and B are modified on exit, and the solution to the */
  178. /* equilibrated system is inv(diag(S))*X. */
  179. /* LDX (input) INTEGER */
  180. /* The leading dimension of the array X. LDX >= max(1,N). */
  181. /* RCOND (output) DOUBLE PRECISION */
  182. /* The estimate of the reciprocal condition number of the matrix */
  183. /* A after equilibration (if done). If RCOND is less than the */
  184. /* machine precision (in particular, if RCOND = 0), the matrix */
  185. /* is singular to working precision. This condition is */
  186. /* indicated by a return code of INFO > 0. */
  187. /* FERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  188. /* The estimated forward error bound for each solution vector */
  189. /* X(j) (the j-th column of the solution matrix X). */
  190. /* If XTRUE is the true solution corresponding to X(j), FERR(j) */
  191. /* is an estimated upper bound for the magnitude of the largest */
  192. /* element in (X(j) - XTRUE) divided by the magnitude of the */
  193. /* largest element in X(j). The estimate is as reliable as */
  194. /* the estimate for RCOND, and is almost always a slight */
  195. /* overestimate of the true error. */
  196. /* BERR (output) DOUBLE PRECISION array, dimension (NRHS) */
  197. /* The componentwise relative backward error of each solution */
  198. /* vector X(j) (i.e., the smallest relative change in */
  199. /* any element of A or B that makes X(j) an exact solution). */
  200. /* WORK (workspace) DOUBLE PRECISION array, dimension (3*N) */
  201. /* IWORK (workspace) INTEGER array, dimension (N) */
  202. /* INFO (output) INTEGER */
  203. /* = 0: successful exit */
  204. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  205. /* > 0: if INFO = i, and i is */
  206. /* <= N: the leading minor of order i of A is */
  207. /* not positive definite, so the factorization */
  208. /* could not be completed, and the solution has not */
  209. /* been computed. RCOND = 0 is returned. */
  210. /* = N+1: U is nonsingular, but RCOND is less than machine */
  211. /* precision, meaning that the matrix is singular */
  212. /* to working precision. Nevertheless, the */
  213. /* solution and error bounds are computed because */
  214. /* there are a number of situations where the */
  215. /* computed solution can be more accurate than the */
  216. /* value of RCOND would suggest. */
  217. /* Further Details */
  218. /* =============== */
  219. /* The band storage scheme is illustrated by the following example, when */
  220. /* N = 6, KD = 2, and UPLO = 'U': */
  221. /* Two-dimensional storage of the symmetric matrix A: */
  222. /* a11 a12 a13 */
  223. /* a22 a23 a24 */
  224. /* a33 a34 a35 */
  225. /* a44 a45 a46 */
  226. /* a55 a56 */
  227. /* (aij=conjg(aji)) a66 */
  228. /* Band storage of the upper triangle of A: */
  229. /* * * a13 a24 a35 a46 */
  230. /* * a12 a23 a34 a45 a56 */
  231. /* a11 a22 a33 a44 a55 a66 */
  232. /* Similarly, if UPLO = 'L' the format of A is as follows: */
  233. /* a11 a22 a33 a44 a55 a66 */
  234. /* a21 a32 a43 a54 a65 * */
  235. /* a31 a42 a53 a64 * * */
  236. /* Array elements marked * are not used by the routine. */
  237. /* ===================================================================== */
  238. /* .. Parameters .. */
  239. /* .. */
  240. /* .. Local Scalars .. */
  241. /* .. */
  242. /* .. External Functions .. */
  243. /* .. */
  244. /* .. External Subroutines .. */
  245. /* .. */
  246. /* .. Intrinsic Functions .. */
  247. /* .. */
  248. /* .. Executable Statements .. */
  249. /* Parameter adjustments */
  250. ab_dim1 = *ldab;
  251. ab_offset = 1 + ab_dim1;
  252. ab -= ab_offset;
  253. afb_dim1 = *ldafb;
  254. afb_offset = 1 + afb_dim1;
  255. afb -= afb_offset;
  256. --s;
  257. b_dim1 = *ldb;
  258. b_offset = 1 + b_dim1;
  259. b -= b_offset;
  260. x_dim1 = *ldx;
  261. x_offset = 1 + x_dim1;
  262. x -= x_offset;
  263. --ferr;
  264. --berr;
  265. --work;
  266. --iwork;
  267. /* Function Body */
  268. *info = 0;
  269. nofact = _starpu_lsame_(fact, "N");
  270. equil = _starpu_lsame_(fact, "E");
  271. upper = _starpu_lsame_(uplo, "U");
  272. if (nofact || equil) {
  273. *(unsigned char *)equed = 'N';
  274. rcequ = FALSE_;
  275. } else {
  276. rcequ = _starpu_lsame_(equed, "Y");
  277. smlnum = _starpu_dlamch_("Safe minimum");
  278. bignum = 1. / smlnum;
  279. }
  280. /* Test the input parameters. */
  281. if (! nofact && ! equil && ! _starpu_lsame_(fact, "F")) {
  282. *info = -1;
  283. } else if (! upper && ! _starpu_lsame_(uplo, "L")) {
  284. *info = -2;
  285. } else if (*n < 0) {
  286. *info = -3;
  287. } else if (*kd < 0) {
  288. *info = -4;
  289. } else if (*nrhs < 0) {
  290. *info = -5;
  291. } else if (*ldab < *kd + 1) {
  292. *info = -7;
  293. } else if (*ldafb < *kd + 1) {
  294. *info = -9;
  295. } else if (_starpu_lsame_(fact, "F") && ! (rcequ || _starpu_lsame_(
  296. equed, "N"))) {
  297. *info = -10;
  298. } else {
  299. if (rcequ) {
  300. smin = bignum;
  301. smax = 0.;
  302. i__1 = *n;
  303. for (j = 1; j <= i__1; ++j) {
  304. /* Computing MIN */
  305. d__1 = smin, d__2 = s[j];
  306. smin = min(d__1,d__2);
  307. /* Computing MAX */
  308. d__1 = smax, d__2 = s[j];
  309. smax = max(d__1,d__2);
  310. /* L10: */
  311. }
  312. if (smin <= 0.) {
  313. *info = -11;
  314. } else if (*n > 0) {
  315. scond = max(smin,smlnum) / min(smax,bignum);
  316. } else {
  317. scond = 1.;
  318. }
  319. }
  320. if (*info == 0) {
  321. if (*ldb < max(1,*n)) {
  322. *info = -13;
  323. } else if (*ldx < max(1,*n)) {
  324. *info = -15;
  325. }
  326. }
  327. }
  328. if (*info != 0) {
  329. i__1 = -(*info);
  330. _starpu_xerbla_("DPBSVX", &i__1);
  331. return 0;
  332. }
  333. if (equil) {
  334. /* Compute row and column scalings to equilibrate the matrix A. */
  335. _starpu_dpbequ_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax, &
  336. infequ);
  337. if (infequ == 0) {
  338. /* Equilibrate the matrix. */
  339. _starpu_dlaqsb_(uplo, n, kd, &ab[ab_offset], ldab, &s[1], &scond, &amax,
  340. equed);
  341. rcequ = _starpu_lsame_(equed, "Y");
  342. }
  343. }
  344. /* Scale the right-hand side. */
  345. if (rcequ) {
  346. i__1 = *nrhs;
  347. for (j = 1; j <= i__1; ++j) {
  348. i__2 = *n;
  349. for (i__ = 1; i__ <= i__2; ++i__) {
  350. b[i__ + j * b_dim1] = s[i__] * b[i__ + j * b_dim1];
  351. /* L20: */
  352. }
  353. /* L30: */
  354. }
  355. }
  356. if (nofact || equil) {
  357. /* Compute the Cholesky factorization A = U'*U or A = L*L'. */
  358. if (upper) {
  359. i__1 = *n;
  360. for (j = 1; j <= i__1; ++j) {
  361. /* Computing MAX */
  362. i__2 = j - *kd;
  363. j1 = max(i__2,1);
  364. i__2 = j - j1 + 1;
  365. _starpu_dcopy_(&i__2, &ab[*kd + 1 - j + j1 + j * ab_dim1], &c__1, &
  366. afb[*kd + 1 - j + j1 + j * afb_dim1], &c__1);
  367. /* L40: */
  368. }
  369. } else {
  370. i__1 = *n;
  371. for (j = 1; j <= i__1; ++j) {
  372. /* Computing MIN */
  373. i__2 = j + *kd;
  374. j2 = min(i__2,*n);
  375. i__2 = j2 - j + 1;
  376. _starpu_dcopy_(&i__2, &ab[j * ab_dim1 + 1], &c__1, &afb[j * afb_dim1
  377. + 1], &c__1);
  378. /* L50: */
  379. }
  380. }
  381. _starpu_dpbtrf_(uplo, n, kd, &afb[afb_offset], ldafb, info);
  382. /* Return if INFO is non-zero. */
  383. if (*info > 0) {
  384. *rcond = 0.;
  385. return 0;
  386. }
  387. }
  388. /* Compute the norm of the matrix A. */
  389. anorm = _starpu_dlansb_("1", uplo, n, kd, &ab[ab_offset], ldab, &work[1]);
  390. /* Compute the reciprocal of the condition number of A. */
  391. _starpu_dpbcon_(uplo, n, kd, &afb[afb_offset], ldafb, &anorm, rcond, &work[1], &
  392. iwork[1], info);
  393. /* Compute the solution matrix X. */
  394. _starpu_dlacpy_("Full", n, nrhs, &b[b_offset], ldb, &x[x_offset], ldx);
  395. _starpu_dpbtrs_(uplo, n, kd, nrhs, &afb[afb_offset], ldafb, &x[x_offset], ldx,
  396. info);
  397. /* Use iterative refinement to improve the computed solution and */
  398. /* compute error bounds and backward error estimates for it. */
  399. _starpu_dpbrfs_(uplo, n, kd, nrhs, &ab[ab_offset], ldab, &afb[afb_offset], ldafb,
  400. &b[b_offset], ldb, &x[x_offset], ldx, &ferr[1], &berr[1], &work[1]
  401. , &iwork[1], info);
  402. /* Transform the solution matrix X to a solution of the original */
  403. /* system. */
  404. if (rcequ) {
  405. i__1 = *nrhs;
  406. for (j = 1; j <= i__1; ++j) {
  407. i__2 = *n;
  408. for (i__ = 1; i__ <= i__2; ++i__) {
  409. x[i__ + j * x_dim1] = s[i__] * x[i__ + j * x_dim1];
  410. /* L60: */
  411. }
  412. /* L70: */
  413. }
  414. i__1 = *nrhs;
  415. for (j = 1; j <= i__1; ++j) {
  416. ferr[j] /= scond;
  417. /* L80: */
  418. }
  419. }
  420. /* Set INFO = N+1 if the matrix is singular to working precision. */
  421. if (*rcond < _starpu_dlamch_("Epsilon")) {
  422. *info = *n + 1;
  423. }
  424. return 0;
  425. /* End of DPBSVX */
  426. } /* _starpu_dpbsvx_ */