dgetc2.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. /* dgetc2.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_b10 = -1.;
  16. /* Subroutine */ int _starpu_dgetc2_(integer *n, doublereal *a, integer *lda, integer
  17. *ipiv, integer *jpiv, integer *info)
  18. {
  19. /* System generated locals */
  20. integer a_dim1, a_offset, i__1, i__2, i__3;
  21. doublereal d__1;
  22. /* Local variables */
  23. integer i__, j, ip, jp;
  24. doublereal eps;
  25. integer ipv, jpv;
  26. extern /* Subroutine */ int _starpu_dger_(integer *, integer *, doublereal *,
  27. doublereal *, integer *, doublereal *, integer *, doublereal *,
  28. integer *);
  29. doublereal smin, xmax;
  30. extern /* Subroutine */ int _starpu_dswap_(integer *, doublereal *, integer *,
  31. doublereal *, integer *), _starpu_dlabad_(doublereal *, doublereal *);
  32. extern doublereal _starpu_dlamch_(char *);
  33. doublereal bignum, smlnum;
  34. /* -- LAPACK auxiliary routine (version 3.2) -- */
  35. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  36. /* November 2006 */
  37. /* .. Scalar Arguments .. */
  38. /* .. */
  39. /* .. Array Arguments .. */
  40. /* .. */
  41. /* Purpose */
  42. /* ======= */
  43. /* DGETC2 computes an LU factorization with complete pivoting of the */
  44. /* n-by-n matrix A. The factorization has the form A = P * L * U * Q, */
  45. /* where P and Q are permutation matrices, L is lower triangular with */
  46. /* unit diagonal elements and U is upper triangular. */
  47. /* This is the Level 2 BLAS algorithm. */
  48. /* Arguments */
  49. /* ========= */
  50. /* N (input) INTEGER */
  51. /* The order of the matrix A. N >= 0. */
  52. /* A (input/output) DOUBLE PRECISION array, dimension (LDA, N) */
  53. /* On entry, the n-by-n matrix A to be factored. */
  54. /* On exit, the factors L and U from the factorization */
  55. /* A = P*L*U*Q; the unit diagonal elements of L are not stored. */
  56. /* If U(k, k) appears to be less than SMIN, U(k, k) is given the */
  57. /* value of SMIN, i.e., giving a nonsingular perturbed system. */
  58. /* LDA (input) INTEGER */
  59. /* The leading dimension of the array A. LDA >= max(1,N). */
  60. /* IPIV (output) INTEGER array, dimension(N). */
  61. /* The pivot indices; for 1 <= i <= N, row i of the */
  62. /* matrix has been interchanged with row IPIV(i). */
  63. /* JPIV (output) INTEGER array, dimension(N). */
  64. /* The pivot indices; for 1 <= j <= N, column j of the */
  65. /* matrix has been interchanged with column JPIV(j). */
  66. /* INFO (output) INTEGER */
  67. /* = 0: successful exit */
  68. /* > 0: if INFO = k, U(k, k) is likely to produce owerflow if */
  69. /* we try to solve for x in Ax = b. So U is perturbed to */
  70. /* avoid the overflow. */
  71. /* Further Details */
  72. /* =============== */
  73. /* Based on contributions by */
  74. /* Bo Kagstrom and Peter Poromaa, Department of Computing Science, */
  75. /* Umea University, S-901 87 Umea, Sweden. */
  76. /* ===================================================================== */
  77. /* .. Parameters .. */
  78. /* .. */
  79. /* .. Local Scalars .. */
  80. /* .. */
  81. /* .. External Subroutines .. */
  82. /* .. */
  83. /* .. External Functions .. */
  84. /* .. */
  85. /* .. Intrinsic Functions .. */
  86. /* .. */
  87. /* .. Executable Statements .. */
  88. /* Set constants to control overflow */
  89. /* Parameter adjustments */
  90. a_dim1 = *lda;
  91. a_offset = 1 + a_dim1;
  92. a -= a_offset;
  93. --ipiv;
  94. --jpiv;
  95. /* Function Body */
  96. *info = 0;
  97. eps = _starpu_dlamch_("P");
  98. smlnum = _starpu_dlamch_("S") / eps;
  99. bignum = 1. / smlnum;
  100. _starpu_dlabad_(&smlnum, &bignum);
  101. /* Factorize A using complete pivoting. */
  102. /* Set pivots less than SMIN to SMIN. */
  103. i__1 = *n - 1;
  104. for (i__ = 1; i__ <= i__1; ++i__) {
  105. /* Find max element in matrix A */
  106. xmax = 0.;
  107. i__2 = *n;
  108. for (ip = i__; ip <= i__2; ++ip) {
  109. i__3 = *n;
  110. for (jp = i__; jp <= i__3; ++jp) {
  111. if ((d__1 = a[ip + jp * a_dim1], abs(d__1)) >= xmax) {
  112. xmax = (d__1 = a[ip + jp * a_dim1], abs(d__1));
  113. ipv = ip;
  114. jpv = jp;
  115. }
  116. /* L10: */
  117. }
  118. /* L20: */
  119. }
  120. if (i__ == 1) {
  121. /* Computing MAX */
  122. d__1 = eps * xmax;
  123. smin = max(d__1,smlnum);
  124. }
  125. /* Swap rows */
  126. if (ipv != i__) {
  127. _starpu_dswap_(n, &a[ipv + a_dim1], lda, &a[i__ + a_dim1], lda);
  128. }
  129. ipiv[i__] = ipv;
  130. /* Swap columns */
  131. if (jpv != i__) {
  132. _starpu_dswap_(n, &a[jpv * a_dim1 + 1], &c__1, &a[i__ * a_dim1 + 1], &
  133. c__1);
  134. }
  135. jpiv[i__] = jpv;
  136. /* Check for singularity */
  137. if ((d__1 = a[i__ + i__ * a_dim1], abs(d__1)) < smin) {
  138. *info = i__;
  139. a[i__ + i__ * a_dim1] = smin;
  140. }
  141. i__2 = *n;
  142. for (j = i__ + 1; j <= i__2; ++j) {
  143. a[j + i__ * a_dim1] /= a[i__ + i__ * a_dim1];
  144. /* L30: */
  145. }
  146. i__2 = *n - i__;
  147. i__3 = *n - i__;
  148. _starpu_dger_(&i__2, &i__3, &c_b10, &a[i__ + 1 + i__ * a_dim1], &c__1, &a[i__
  149. + (i__ + 1) * a_dim1], lda, &a[i__ + 1 + (i__ + 1) * a_dim1],
  150. lda);
  151. /* L40: */
  152. }
  153. if ((d__1 = a[*n + *n * a_dim1], abs(d__1)) < smin) {
  154. *info = *n;
  155. a[*n + *n * a_dim1] = smin;
  156. }
  157. return 0;
  158. /* End of DGETC2 */
  159. } /* _starpu_dgetc2_ */