dptcon.c 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  1. /* dptcon.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_dptcon_(integer *n, doublereal *d__, doublereal *e,
  16. doublereal *anorm, doublereal *rcond, doublereal *work, integer *info)
  17. {
  18. /* System generated locals */
  19. integer i__1;
  20. doublereal d__1;
  21. /* Local variables */
  22. integer i__, ix;
  23. extern integer _starpu_idamax_(integer *, doublereal *, integer *);
  24. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  25. doublereal ainvnm;
  26. /* -- LAPACK routine (version 3.2) -- */
  27. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  28. /* November 2006 */
  29. /* .. Scalar Arguments .. */
  30. /* .. */
  31. /* .. Array Arguments .. */
  32. /* .. */
  33. /* Purpose */
  34. /* ======= */
  35. /* DPTCON computes the reciprocal of the condition number (in the */
  36. /* 1-norm) of a real symmetric positive definite tridiagonal matrix */
  37. /* using the factorization A = L*D*L**T or A = U**T*D*U computed by */
  38. /* DPTTRF. */
  39. /* Norm(inv(A)) is computed by a direct method, and the reciprocal of */
  40. /* the condition number is computed as */
  41. /* RCOND = 1 / (ANORM * norm(inv(A))). */
  42. /* Arguments */
  43. /* ========= */
  44. /* N (input) INTEGER */
  45. /* The order of the matrix A. N >= 0. */
  46. /* D (input) DOUBLE PRECISION array, dimension (N) */
  47. /* The n diagonal elements of the diagonal matrix D from the */
  48. /* factorization of A, as computed by DPTTRF. */
  49. /* E (input) DOUBLE PRECISION array, dimension (N-1) */
  50. /* The (n-1) off-diagonal elements of the unit bidiagonal factor */
  51. /* U or L from the factorization of A, as computed by DPTTRF. */
  52. /* ANORM (input) DOUBLE PRECISION */
  53. /* The 1-norm of the original matrix A. */
  54. /* RCOND (output) DOUBLE PRECISION */
  55. /* The reciprocal of the condition number of the matrix A, */
  56. /* computed as RCOND = 1/(ANORM * AINVNM), where AINVNM is the */
  57. /* 1-norm of inv(A) computed in this routine. */
  58. /* WORK (workspace) DOUBLE PRECISION array, dimension (N) */
  59. /* INFO (output) INTEGER */
  60. /* = 0: successful exit */
  61. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  62. /* Further Details */
  63. /* =============== */
  64. /* The method used is described in Nicholas J. Higham, "Efficient */
  65. /* Algorithms for Computing the Condition Number of a Tridiagonal */
  66. /* Matrix", SIAM J. Sci. Stat. Comput., Vol. 7, No. 1, January 1986. */
  67. /* ===================================================================== */
  68. /* .. Parameters .. */
  69. /* .. */
  70. /* .. Local Scalars .. */
  71. /* .. */
  72. /* .. External Functions .. */
  73. /* .. */
  74. /* .. External Subroutines .. */
  75. /* .. */
  76. /* .. Intrinsic Functions .. */
  77. /* .. */
  78. /* .. Executable Statements .. */
  79. /* Test the input arguments. */
  80. /* Parameter adjustments */
  81. --work;
  82. --e;
  83. --d__;
  84. /* Function Body */
  85. *info = 0;
  86. if (*n < 0) {
  87. *info = -1;
  88. } else if (*anorm < 0.) {
  89. *info = -4;
  90. }
  91. if (*info != 0) {
  92. i__1 = -(*info);
  93. _starpu_xerbla_("DPTCON", &i__1);
  94. return 0;
  95. }
  96. /* Quick return if possible */
  97. *rcond = 0.;
  98. if (*n == 0) {
  99. *rcond = 1.;
  100. return 0;
  101. } else if (*anorm == 0.) {
  102. return 0;
  103. }
  104. /* Check that D(1:N) is positive. */
  105. i__1 = *n;
  106. for (i__ = 1; i__ <= i__1; ++i__) {
  107. if (d__[i__] <= 0.) {
  108. return 0;
  109. }
  110. /* L10: */
  111. }
  112. /* Solve M(A) * x = e, where M(A) = (m(i,j)) is given by */
  113. /* m(i,j) = abs(A(i,j)), i = j, */
  114. /* m(i,j) = -abs(A(i,j)), i .ne. j, */
  115. /* and e = [ 1, 1, ..., 1 ]'. Note M(A) = M(L)*D*M(L)'. */
  116. /* Solve M(L) * x = e. */
  117. work[1] = 1.;
  118. i__1 = *n;
  119. for (i__ = 2; i__ <= i__1; ++i__) {
  120. work[i__] = work[i__ - 1] * (d__1 = e[i__ - 1], abs(d__1)) + 1.;
  121. /* L20: */
  122. }
  123. /* Solve D * M(L)' * x = b. */
  124. work[*n] /= d__[*n];
  125. for (i__ = *n - 1; i__ >= 1; --i__) {
  126. work[i__] = work[i__] / d__[i__] + work[i__ + 1] * (d__1 = e[i__],
  127. abs(d__1));
  128. /* L30: */
  129. }
  130. /* Compute AINVNM = max(x(i)), 1<=i<=n. */
  131. ix = _starpu_idamax_(n, &work[1], &c__1);
  132. ainvnm = (d__1 = work[ix], abs(d__1));
  133. /* Compute the reciprocal condition number. */
  134. if (ainvnm != 0.) {
  135. *rcond = 1. / ainvnm / *anorm;
  136. }
  137. return 0;
  138. /* End of DPTCON */
  139. } /* _starpu_dptcon_ */