dlasrt.c 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  1. /* dlasrt.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. /* Subroutine */ int _starpu_dlasrt_(char *id, integer *n, doublereal *d__, integer *
  14. info)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2;
  18. /* Local variables */
  19. integer i__, j;
  20. doublereal d1, d2, d3;
  21. integer dir;
  22. doublereal tmp;
  23. integer endd;
  24. extern logical _starpu_lsame_(char *, char *);
  25. integer stack[64] /* was [2][32] */;
  26. doublereal dmnmx;
  27. integer start;
  28. extern /* Subroutine */ int _starpu_xerbla_(char *, integer *);
  29. integer stkpnt;
  30. /* -- LAPACK routine (version 3.2) -- */
  31. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  32. /* November 2006 */
  33. /* .. Scalar Arguments .. */
  34. /* .. */
  35. /* .. Array Arguments .. */
  36. /* .. */
  37. /* Purpose */
  38. /* ======= */
  39. /* Sort the numbers in D in increasing order (if ID = 'I') or */
  40. /* in decreasing order (if ID = 'D' ). */
  41. /* Use Quick Sort, reverting to Insertion sort on arrays of */
  42. /* size <= 20. Dimension of STACK limits N to about 2**32. */
  43. /* Arguments */
  44. /* ========= */
  45. /* ID (input) CHARACTER*1 */
  46. /* = 'I': sort D in increasing order; */
  47. /* = 'D': sort D in decreasing order. */
  48. /* N (input) INTEGER */
  49. /* The length of the array D. */
  50. /* D (input/output) DOUBLE PRECISION array, dimension (N) */
  51. /* On entry, the array to be sorted. */
  52. /* On exit, D has been sorted into increasing order */
  53. /* (D(1) <= ... <= D(N) ) or into decreasing order */
  54. /* (D(1) >= ... >= D(N) ), depending on ID. */
  55. /* INFO (output) INTEGER */
  56. /* = 0: successful exit */
  57. /* < 0: if INFO = -i, the i-th argument had an illegal value */
  58. /* ===================================================================== */
  59. /* .. Parameters .. */
  60. /* .. */
  61. /* .. Local Scalars .. */
  62. /* .. */
  63. /* .. Local Arrays .. */
  64. /* .. */
  65. /* .. External Functions .. */
  66. /* .. */
  67. /* .. External Subroutines .. */
  68. /* .. */
  69. /* .. Executable Statements .. */
  70. /* Test the input paramters. */
  71. /* Parameter adjustments */
  72. --d__;
  73. /* Function Body */
  74. *info = 0;
  75. dir = -1;
  76. if (_starpu_lsame_(id, "D")) {
  77. dir = 0;
  78. } else if (_starpu_lsame_(id, "I")) {
  79. dir = 1;
  80. }
  81. if (dir == -1) {
  82. *info = -1;
  83. } else if (*n < 0) {
  84. *info = -2;
  85. }
  86. if (*info != 0) {
  87. i__1 = -(*info);
  88. _starpu_xerbla_("DLASRT", &i__1);
  89. return 0;
  90. }
  91. /* Quick return if possible */
  92. if (*n <= 1) {
  93. return 0;
  94. }
  95. stkpnt = 1;
  96. stack[0] = 1;
  97. stack[1] = *n;
  98. L10:
  99. start = stack[(stkpnt << 1) - 2];
  100. endd = stack[(stkpnt << 1) - 1];
  101. --stkpnt;
  102. if (endd - start <= 20 && endd - start > 0) {
  103. /* Do Insertion sort on D( START:ENDD ) */
  104. if (dir == 0) {
  105. /* Sort into decreasing order */
  106. i__1 = endd;
  107. for (i__ = start + 1; i__ <= i__1; ++i__) {
  108. i__2 = start + 1;
  109. for (j = i__; j >= i__2; --j) {
  110. if (d__[j] > d__[j - 1]) {
  111. dmnmx = d__[j];
  112. d__[j] = d__[j - 1];
  113. d__[j - 1] = dmnmx;
  114. } else {
  115. goto L30;
  116. }
  117. /* L20: */
  118. }
  119. L30:
  120. ;
  121. }
  122. } else {
  123. /* Sort into increasing order */
  124. i__1 = endd;
  125. for (i__ = start + 1; i__ <= i__1; ++i__) {
  126. i__2 = start + 1;
  127. for (j = i__; j >= i__2; --j) {
  128. if (d__[j] < d__[j - 1]) {
  129. dmnmx = d__[j];
  130. d__[j] = d__[j - 1];
  131. d__[j - 1] = dmnmx;
  132. } else {
  133. goto L50;
  134. }
  135. /* L40: */
  136. }
  137. L50:
  138. ;
  139. }
  140. }
  141. } else if (endd - start > 20) {
  142. /* Partition D( START:ENDD ) and stack parts, largest one first */
  143. /* Choose partition entry as median of 3 */
  144. d1 = d__[start];
  145. d2 = d__[endd];
  146. i__ = (start + endd) / 2;
  147. d3 = d__[i__];
  148. if (d1 < d2) {
  149. if (d3 < d1) {
  150. dmnmx = d1;
  151. } else if (d3 < d2) {
  152. dmnmx = d3;
  153. } else {
  154. dmnmx = d2;
  155. }
  156. } else {
  157. if (d3 < d2) {
  158. dmnmx = d2;
  159. } else if (d3 < d1) {
  160. dmnmx = d3;
  161. } else {
  162. dmnmx = d1;
  163. }
  164. }
  165. if (dir == 0) {
  166. /* Sort into decreasing order */
  167. i__ = start - 1;
  168. j = endd + 1;
  169. L60:
  170. L70:
  171. --j;
  172. if (d__[j] < dmnmx) {
  173. goto L70;
  174. }
  175. L80:
  176. ++i__;
  177. if (d__[i__] > dmnmx) {
  178. goto L80;
  179. }
  180. if (i__ < j) {
  181. tmp = d__[i__];
  182. d__[i__] = d__[j];
  183. d__[j] = tmp;
  184. goto L60;
  185. }
  186. if (j - start > endd - j - 1) {
  187. ++stkpnt;
  188. stack[(stkpnt << 1) - 2] = start;
  189. stack[(stkpnt << 1) - 1] = j;
  190. ++stkpnt;
  191. stack[(stkpnt << 1) - 2] = j + 1;
  192. stack[(stkpnt << 1) - 1] = endd;
  193. } else {
  194. ++stkpnt;
  195. stack[(stkpnt << 1) - 2] = j + 1;
  196. stack[(stkpnt << 1) - 1] = endd;
  197. ++stkpnt;
  198. stack[(stkpnt << 1) - 2] = start;
  199. stack[(stkpnt << 1) - 1] = j;
  200. }
  201. } else {
  202. /* Sort into increasing order */
  203. i__ = start - 1;
  204. j = endd + 1;
  205. L90:
  206. L100:
  207. --j;
  208. if (d__[j] > dmnmx) {
  209. goto L100;
  210. }
  211. L110:
  212. ++i__;
  213. if (d__[i__] < dmnmx) {
  214. goto L110;
  215. }
  216. if (i__ < j) {
  217. tmp = d__[i__];
  218. d__[i__] = d__[j];
  219. d__[j] = tmp;
  220. goto L90;
  221. }
  222. if (j - start > endd - j - 1) {
  223. ++stkpnt;
  224. stack[(stkpnt << 1) - 2] = start;
  225. stack[(stkpnt << 1) - 1] = j;
  226. ++stkpnt;
  227. stack[(stkpnt << 1) - 2] = j + 1;
  228. stack[(stkpnt << 1) - 1] = endd;
  229. } else {
  230. ++stkpnt;
  231. stack[(stkpnt << 1) - 2] = j + 1;
  232. stack[(stkpnt << 1) - 1] = endd;
  233. ++stkpnt;
  234. stack[(stkpnt << 1) - 2] = start;
  235. stack[(stkpnt << 1) - 1] = j;
  236. }
  237. }
  238. }
  239. if (stkpnt > 0) {
  240. goto L10;
  241. }
  242. return 0;
  243. /* End of DLASRT */
  244. } /* _starpu_dlasrt_ */