dgesc2.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177
  1. /* dgesc2.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 integer c_n1 = -1;
  16. /* Subroutine */ int _starpu_dgesc2_(integer *n, doublereal *a, integer *lda,
  17. doublereal *rhs, integer *ipiv, integer *jpiv, doublereal *scale)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, i__1, i__2;
  21. doublereal d__1, d__2;
  22. /* Local variables */
  23. integer i__, j;
  24. doublereal eps, temp;
  25. extern /* Subroutine */ int _starpu_dscal_(integer *, doublereal *, doublereal *,
  26. integer *), _starpu_dlabad_(doublereal *, doublereal *);
  27. extern doublereal _starpu_dlamch_(char *);
  28. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  29. doublereal bignum;
  30. extern /* Subroutine */ int _starpu_dlaswp_(integer *, doublereal *, integer *,
  31. integer *, integer *, integer *, integer *);
  32. doublereal smlnum;
  33. /* -- LAPACK auxiliary routine (version 3.2) -- */
  34. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  35. /* November 2006 */
  36. /* .. Scalar Arguments .. */
  37. /* .. */
  38. /* .. Array Arguments .. */
  39. /* .. */
  40. /* Purpose */
  41. /* ======= */
  42. /* DGESC2 solves a system of linear equations */
  43. /* A * X = scale* RHS */
  44. /* with a general N-by-N matrix A using the LU factorization with */
  45. /* complete pivoting computed by DGETC2. */
  46. /* Arguments */
  47. /* ========= */
  48. /* N (input) INTEGER */
  49. /* The order of the matrix A. */
  50. /* A (input) DOUBLE PRECISION array, dimension (LDA,N) */
  51. /* On entry, the LU part of the factorization of the n-by-n */
  52. /* matrix A computed by DGETC2: A = P * L * U * Q */
  53. /* LDA (input) INTEGER */
  54. /* The leading dimension of the array A. LDA >= max(1, N). */
  55. /* RHS (input/output) DOUBLE PRECISION array, dimension (N). */
  56. /* On entry, the right hand side vector b. */
  57. /* On exit, the solution vector X. */
  58. /* IPIV (input) INTEGER array, dimension (N). */
  59. /* The pivot indices; for 1 <= i <= N, row i of the */
  60. /* matrix has been interchanged with row IPIV(i). */
  61. /* JPIV (input) INTEGER array, dimension (N). */
  62. /* The pivot indices; for 1 <= j <= N, column j of the */
  63. /* matrix has been interchanged with column JPIV(j). */
  64. /* SCALE (output) DOUBLE PRECISION */
  65. /* On exit, SCALE contains the scale factor. SCALE is chosen */
  66. /* 0 <= SCALE <= 1 to prevent owerflow in the solution. */
  67. /* Further Details */
  68. /* =============== */
  69. /* Based on contributions by */
  70. /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  71. /* Umea University, S-901 87 Umea, Sweden. */
  72. /* ===================================================================== */
  73. /* .. Parameters .. */
  74. /* .. */
  75. /* .. Local Scalars .. */
  76. /* .. */
  77. /* .. External Subroutines .. */
  78. /* .. */
  79. /* .. External Functions .. */
  80. /* .. */
  81. /* .. Intrinsic Functions .. */
  82. /* .. */
  83. /* .. Executable Statements .. */
  84. /* Set constant to control owerflow */
  85. /* Parameter adjustments */
  86. a_dim1 = *lda;
  87. a_offset = 1 + a_dim1;
  88. a -= a_offset;
  89. --rhs;
  90. --ipiv;
  91. --jpiv;
  92. /* Function Body */
  93. eps = _starpu_dlamch_("P");
  94. smlnum = _starpu_dlamch_("S") / eps;
  95. bignum = 1. / smlnum;
  96. _starpu_dlabad_(&smlnum, &bignum);
  97. /* Apply permutations IPIV to RHS */
  98. i__1 = *n - 1;
  99. _starpu_dlaswp_(&c__1, &rhs[1], lda, &c__1, &i__1, &ipiv[1], &c__1);
  100. /* Solve for L part */
  101. i__1 = *n - 1;
  102. for (i__ = 1; i__ <= i__1; ++i__) {
  103. i__2 = *n;
  104. for (j = i__ + 1; j <= i__2; ++j) {
  105. rhs[j] -= a[j + i__ * a_dim1] * rhs[i__];
  106. /* L10: */
  107. }
  108. /* L20: */
  109. }
  110. /* Solve for U part */
  111. *scale = 1.;
  112. /* Check for scaling */
  113. i__ = _starpu_idamax_(n, &rhs[1], &c__1);
  114. if (smlnum * 2. * (d__1 = rhs[i__], abs(d__1)) > (d__2 = a[*n + *n *
  115. a_dim1], abs(d__2))) {
  116. temp = .5 / (d__1 = rhs[i__], abs(d__1));
  117. _starpu_dscal_(n, &temp, &rhs[1], &c__1);
  118. *scale *= temp;
  119. }
  120. for (i__ = *n; i__ >= 1; --i__) {
  121. temp = 1. / a[i__ + i__ * a_dim1];
  122. rhs[i__] *= temp;
  123. i__1 = *n;
  124. for (j = i__ + 1; j <= i__1; ++j) {
  125. rhs[i__] -= rhs[j] * (a[i__ + j * a_dim1] * temp);
  126. /* L30: */
  127. }
  128. /* L40: */
  129. }
  130. /* Apply permutations JPIV to the solution (RHS) */
  131. i__1 = *n - 1;
  132. _starpu_dlaswp_(&c__1, &rhs[1], lda, &c__1, &i__1, &jpiv[1], &c_n1);
  133. return 0;
  134. /* End of DGESC2 */
  135. } /* _starpu_dgesc2_ */