dlarf.c 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194
  1. /* dlarf.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 doublereal c_b4 = 1.;
  15. static doublereal c_b5 = 0.;
  16. static integer c__1 = 1;
  17. /* Subroutine */ int _starpu_dlarf_(char *side, integer *m, integer *n, doublereal *v,
  18. integer *incv, doublereal *tau, doublereal *c__, integer *ldc,
  19. doublereal *work)
  20. {
  21. /* System generated locals */
  22. integer c_dim1, c_offset;
  23. doublereal d__1;
  24. /* Local variables */
  25. integer i__;
  26. logical applyleft;
  27. extern /* Subroutine */ int _starpu_dger_(integer *, integer *, doublereal *,
  28. doublereal *, integer *, doublereal *, integer *, doublereal *,
  29. integer *);
  30. extern logical _starpu_lsame_(char *, char *);
  31. extern /* Subroutine */ int _starpu_dgemv_(char *, integer *, integer *,
  32. doublereal *, doublereal *, integer *, doublereal *, integer *,
  33. doublereal *, doublereal *, integer *);
  34. integer lastc, lastv;
  35. extern integer _starpu_iladlc_(integer *, integer *, doublereal *, integer *),
  36. _starpu_iladlr_(integer *, integer *, doublereal *, integer *);
  37. /* -- LAPACK auxiliary routine (version 3.2) -- */
  38. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  39. /* November 2006 */
  40. /* .. Scalar Arguments .. */
  41. /* .. */
  42. /* .. Array Arguments .. */
  43. /* .. */
  44. /* Purpose */
  45. /* ======= */
  46. /* DLARF applies a real elementary reflector H to a real m by n matrix */
  47. /* C, from either the left or the right. H is represented in the form */
  48. /* H = I - tau * v * v' */
  49. /* where tau is a real scalar and v is a real vector. */
  50. /* If tau = 0, then H is taken to be the unit matrix. */
  51. /* Arguments */
  52. /* ========= */
  53. /* SIDE (input) CHARACTER*1 */
  54. /* = 'L': form H * C */
  55. /* = 'R': form C * H */
  56. /* M (input) INTEGER */
  57. /* The number of rows of the matrix C. */
  58. /* N (input) INTEGER */
  59. /* The number of columns of the matrix C. */
  60. /* V (input) DOUBLE PRECISION array, dimension */
  61. /* (1 + (M-1)*abs(INCV)) if SIDE = 'L' */
  62. /* or (1 + (N-1)*abs(INCV)) if SIDE = 'R' */
  63. /* The vector v in the representation of H. V is not used if */
  64. /* TAU = 0. */
  65. /* INCV (input) INTEGER */
  66. /* The increment between elements of v. INCV <> 0. */
  67. /* TAU (input) DOUBLE PRECISION */
  68. /* The value tau in the representation of H. */
  69. /* C (input/output) DOUBLE PRECISION array, dimension (LDC,N) */
  70. /* On entry, the m by n matrix C. */
  71. /* On exit, C is overwritten by the matrix H * C if SIDE = 'L', */
  72. /* or C * H if SIDE = 'R'. */
  73. /* LDC (input) INTEGER */
  74. /* The leading dimension of the array C. LDC >= max(1,M). */
  75. /* WORK (workspace) DOUBLE PRECISION array, dimension */
  76. /* (N) if SIDE = 'L' */
  77. /* or (M) if SIDE = 'R' */
  78. /* ===================================================================== */
  79. /* .. Parameters .. */
  80. /* .. */
  81. /* .. Local Scalars .. */
  82. /* .. */
  83. /* .. External Subroutines .. */
  84. /* .. */
  85. /* .. External Functions .. */
  86. /* .. */
  87. /* .. Executable Statements .. */
  88. /* Parameter adjustments */
  89. --v;
  90. c_dim1 = *ldc;
  91. c_offset = 1 + c_dim1;
  92. c__ -= c_offset;
  93. --work;
  94. /* Function Body */
  95. applyleft = _starpu_lsame_(side, "L");
  96. lastv = 0;
  97. lastc = 0;
  98. if (*tau != 0.) {
  99. /* Set up variables for scanning V. LASTV begins pointing to the end */
  100. /* of V. */
  101. if (applyleft) {
  102. lastv = *m;
  103. } else {
  104. lastv = *n;
  105. }
  106. if (*incv > 0) {
  107. i__ = (lastv - 1) * *incv + 1;
  108. } else {
  109. i__ = 1;
  110. }
  111. /* Look for the last non-zero row in V. */
  112. while(lastv > 0 && v[i__] == 0.) {
  113. --lastv;
  114. i__ -= *incv;
  115. }
  116. if (applyleft) {
  117. /* Scan for the last non-zero column in C(1:lastv,:). */
  118. lastc = _starpu_iladlc_(&lastv, n, &c__[c_offset], ldc);
  119. } else {
  120. /* Scan for the last non-zero row in C(:,1:lastv). */
  121. lastc = _starpu_iladlr_(m, &lastv, &c__[c_offset], ldc);
  122. }
  123. }
  124. /* Note that lastc.eq.0 renders the BLAS operations null; no special */
  125. /* case is needed at this level. */
  126. if (applyleft) {
  127. /* Form H * C */
  128. if (lastv > 0) {
  129. /* w(1:lastc,1) := C(1:lastv,1:lastc)' * v(1:lastv,1) */
  130. _starpu_dgemv_("Transpose", &lastv, &lastc, &c_b4, &c__[c_offset], ldc, &
  131. v[1], incv, &c_b5, &work[1], &c__1);
  132. /* C(1:lastv,1:lastc) := C(...) - v(1:lastv,1) * w(1:lastc,1)' */
  133. d__1 = -(*tau);
  134. _starpu_dger_(&lastv, &lastc, &d__1, &v[1], incv, &work[1], &c__1, &c__[
  135. c_offset], ldc);
  136. }
  137. } else {
  138. /* Form C * H */
  139. if (lastv > 0) {
  140. /* w(1:lastc,1) := C(1:lastc,1:lastv) * v(1:lastv,1) */
  141. _starpu_dgemv_("No transpose", &lastc, &lastv, &c_b4, &c__[c_offset], ldc,
  142. &v[1], incv, &c_b5, &work[1], &c__1);
  143. /* C(1:lastc,1:lastv) := C(...) - w(1:lastc,1) * v(1:lastv,1)' */
  144. d__1 = -(*tau);
  145. _starpu_dger_(&lastc, &lastv, &d__1, &work[1], &c__1, &v[1], incv, &c__[
  146. c_offset], ldc);
  147. }
  148. }
  149. return 0;
  150. /* End of DLARF */
  151. } /* _starpu_dlarf_ */