dlarnv.c 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147
  1. /* dlarnv.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_dlarnv_(integer *idist, integer *iseed, integer *n,
  14. doublereal *x)
  15. {
  16. /* System generated locals */
  17. integer i__1, i__2, i__3;
  18. /* Builtin functions */
  19. double log(doublereal), sqrt(doublereal), cos(doublereal);
  20. /* Local variables */
  21. integer i__;
  22. doublereal u[128];
  23. integer il, iv, il2;
  24. extern /* Subroutine */ int _starpu_dlaruv_(integer *, integer *, doublereal *);
  25. /* -- LAPACK auxiliary routine (version 3.2) -- */
  26. /* Univ. of Tennessee, Univ. of California Berkeley and NAG Ltd.. */
  27. /* November 2006 */
  28. /* .. Scalar Arguments .. */
  29. /* .. */
  30. /* .. Array Arguments .. */
  31. /* .. */
  32. /* Purpose */
  33. /* ======= */
  34. /* DLARNV returns a vector of n random real numbers from a uniform or */
  35. /* normal distribution. */
  36. /* Arguments */
  37. /* ========= */
  38. /* IDIST (input) INTEGER */
  39. /* Specifies the distribution of the random numbers: */
  40. /* = 1: uniform (0,1) */
  41. /* = 2: uniform (-1,1) */
  42. /* = 3: normal (0,1) */
  43. /* ISEED (input/output) INTEGER array, dimension (4) */
  44. /* On entry, the seed of the random number generator; the array */
  45. /* elements must be between 0 and 4095, and ISEED(4) must be */
  46. /* odd. */
  47. /* On exit, the seed is updated. */
  48. /* N (input) INTEGER */
  49. /* The number of random numbers to be generated. */
  50. /* X (output) DOUBLE PRECISION array, dimension (N) */
  51. /* The generated random numbers. */
  52. /* Further Details */
  53. /* =============== */
  54. /* This routine calls the auxiliary routine DLARUV to generate random */
  55. /* real numbers from a uniform (0,1) distribution, in batches of up to */
  56. /* 128 using vectorisable code. The Box-Muller method is used to */
  57. /* transform numbers from a uniform to a normal distribution. */
  58. /* ===================================================================== */
  59. /* .. Parameters .. */
  60. /* .. */
  61. /* .. Local Scalars .. */
  62. /* .. */
  63. /* .. Local Arrays .. */
  64. /* .. */
  65. /* .. Intrinsic Functions .. */
  66. /* .. */
  67. /* .. External Subroutines .. */
  68. /* .. */
  69. /* .. Executable Statements .. */
  70. /* Parameter adjustments */
  71. --x;
  72. --iseed;
  73. /* Function Body */
  74. i__1 = *n;
  75. for (iv = 1; iv <= i__1; iv += 64) {
  76. /* Computing MIN */
  77. i__2 = 64, i__3 = *n - iv + 1;
  78. il = min(i__2,i__3);
  79. if (*idist == 3) {
  80. il2 = il << 1;
  81. } else {
  82. il2 = il;
  83. }
  84. /* Call DLARUV to generate IL2 numbers from a uniform (0,1) */
  85. /* distribution (IL2 <= LV) */
  86. _starpu_dlaruv_(&iseed[1], &il2, u);
  87. if (*idist == 1) {
  88. /* Copy generated numbers */
  89. i__2 = il;
  90. for (i__ = 1; i__ <= i__2; ++i__) {
  91. x[iv + i__ - 1] = u[i__ - 1];
  92. /* L10: */
  93. }
  94. } else if (*idist == 2) {
  95. /* Convert generated numbers to uniform (-1,1) distribution */
  96. i__2 = il;
  97. for (i__ = 1; i__ <= i__2; ++i__) {
  98. x[iv + i__ - 1] = u[i__ - 1] * 2. - 1.;
  99. /* L20: */
  100. }
  101. } else if (*idist == 3) {
  102. /* Convert generated numbers to normal (0,1) distribution */
  103. i__2 = il;
  104. for (i__ = 1; i__ <= i__2; ++i__) {
  105. x[iv + i__ - 1] = sqrt(log(u[(i__ << 1) - 2]) * -2.) * cos(u[(
  106. i__ << 1) - 1] * 6.2831853071795864769252867663);
  107. /* L30: */
  108. }
  109. }
  110. /* L40: */
  111. }
  112. return 0;
  113. /* End of DLARNV */
  114. } /* _starpu_dlarnv_ */