source: CIVL/examples/omp/nas-dc/common/randdp.f@ 1aaefd4

main test-branch
Last change on this file since 1aaefd4 was ea777aa, checked in by Alex Wilton <awilton@…>, 3 years ago

Moved examples, include, build_default.properties, common.xml, and README out from dev.civl.com into the root of the repo.

git-svn-id: svn://vsl.cis.udel.edu/civl/trunk@5704 fb995dde-84ed-4084-dfe6-e5aef3e2452c

  • Property mode set to 100644
File size: 5.1 KB
Line 
1c---------------------------------------------------------------------
2c---------------------------------------------------------------------
3
4 double precision function randlc (x, a)
5
6c---------------------------------------------------------------------
7c---------------------------------------------------------------------
8
9c---------------------------------------------------------------------
10c
11c This routine returns a uniform pseudorandom double precision number in the
12c range (0, 1) by using the linear congruential generator
13c
14c x_{k+1} = a x_k (mod 2^46)
15c
16c where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
17c before repeating. The argument A is the same as 'a' in the above formula,
18c and X is the same as x_0. A and X must be odd double precision integers
19c in the range (1, 2^46). The returned value RANDLC is normalized to be
20c between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain
21c the new seed x_1, so that subsequent calls to RANDLC using the same
22c arguments will generate a continuous sequence.
23c
24c This routine should produce the same results on any computer with at least
25c 48 mantissa bits in double precision floating point data. On 64 bit
26c systems, double precision should be disabled.
27c
28c David H. Bailey October 26, 1990
29c
30c---------------------------------------------------------------------
31
32 implicit none
33
34 double precision r23,r46,t23,t46,a,x,t1,t2,t3,t4,a1,a2,x1,x2,z
35 parameter (r23 = 0.5d0 ** 23, r46 = r23 ** 2, t23 = 2.d0 ** 23,
36 > t46 = t23 ** 2)
37
38c---------------------------------------------------------------------
39c Break A into two parts such that A = 2^23 * A1 + A2.
40c---------------------------------------------------------------------
41 t1 = r23 * a
42 a1 = int (t1)
43 a2 = a - t23 * a1
44
45c---------------------------------------------------------------------
46c Break X into two parts such that X = 2^23 * X1 + X2, compute
47c Z = A1 * X2 + A2 * X1 (mod 2^23), and then
48c X = 2^23 * Z + A2 * X2 (mod 2^46).
49c---------------------------------------------------------------------
50 t1 = r23 * x
51 x1 = int (t1)
52 x2 = x - t23 * x1
53 t1 = a1 * x2 + a2 * x1
54 t2 = int (r23 * t1)
55 z = t1 - t23 * t2
56 t3 = t23 * z + a2 * x2
57 t4 = int (r46 * t3)
58 x = t3 - t46 * t4
59 randlc = r46 * x
60
61 return
62 end
63
64
65
66
67c---------------------------------------------------------------------
68c---------------------------------------------------------------------
69
70 subroutine vranlc (n, x, a, y)
71
72c---------------------------------------------------------------------
73c---------------------------------------------------------------------
74
75c---------------------------------------------------------------------
76c
77c This routine generates N uniform pseudorandom double precision numbers in
78c the range (0, 1) by using the linear congruential generator
79c
80c x_{k+1} = a x_k (mod 2^46)
81c
82c where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
83c before repeating. The argument A is the same as 'a' in the above formula,
84c and X is the same as x_0. A and X must be odd double precision integers
85c in the range (1, 2^46). The N results are placed in Y and are normalized
86c to be between 0 and 1. X is updated to contain the new seed, so that
87c subsequent calls to VRANLC using the same arguments will generate a
88c continuous sequence. If N is zero, only initialization is performed, and
89c the variables X, A and Y are ignored.
90c
91c This routine is the standard version designed for scalar or RISC systems.
92c However, it should produce the same results on any single processor
93c computer with at least 48 mantissa bits in double precision floating point
94c data. On 64 bit systems, double precision should be disabled.
95c
96c---------------------------------------------------------------------
97
98 implicit none
99
100 integer i,n
101 double precision y,r23,r46,t23,t46,a,x,t1,t2,t3,t4,a1,a2,x1,x2,z
102 dimension y(*)
103 parameter (r23 = 0.5d0 ** 23, r46 = r23 ** 2, t23 = 2.d0 ** 23,
104 > t46 = t23 ** 2)
105
106
107c---------------------------------------------------------------------
108c Break A into two parts such that A = 2^23 * A1 + A2.
109c---------------------------------------------------------------------
110 t1 = r23 * a
111 a1 = int (t1)
112 a2 = a - t23 * a1
113
114c---------------------------------------------------------------------
115c Generate N results. This loop is not vectorizable.
116c---------------------------------------------------------------------
117 do i = 1, n
118
119c---------------------------------------------------------------------
120c Break X into two parts such that X = 2^23 * X1 + X2, compute
121c Z = A1 * X2 + A2 * X1 (mod 2^23), and then
122c X = 2^23 * Z + A2 * X2 (mod 2^46).
123c---------------------------------------------------------------------
124 t1 = r23 * x
125 x1 = int (t1)
126 x2 = x - t23 * x1
127 t1 = a1 * x2 + a2 * x1
128 t2 = int (r23 * t1)
129 z = t1 - t23 * t2
130 t3 = t23 * z + a2 * x2
131 t4 = int (r46 * t3)
132 x = t3 - t46 * t4
133 y(i) = r46 * x
134 enddo
135
136 return
137 end
Note: See TracBrowser for help on using the repository browser.