source: CIVL/examples/omp/nas-dc/common/randi8.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: 2.2 KB
Line 
1 double precision function randlc(x, a)
2
3c---------------------------------------------------------------------
4c
5c This routine returns a uniform pseudorandom double precision number in the
6c range (0, 1) by using the linear congruential generator
7c
8c x_{k+1} = a x_k (mod 2^46)
9c
10c where 0 < x_k < 2^46 and 0 < a < 2^46. This scheme generates 2^44 numbers
11c before repeating. The argument A is the same as 'a' in the above formula,
12c and X is the same as x_0. A and X must be odd double precision integers
13c in the range (1, 2^46). The returned value RANDLC is normalized to be
14c between 0 and 1, i.e. RANDLC = 2^(-46) * x_1. X is updated to contain
15c the new seed x_1, so that subsequent calls to RANDLC using the same
16c arguments will generate a continuous sequence.
17
18 implicit none
19 double precision x, a
20 integer*8 i246m1, Lx, La
21 double precision d2m46
22
23 parameter(d2m46=0.5d0**46)
24
25 save i246m1
26 data i246m1/X'00003FFFFFFFFFFF'/
27
28 Lx = X
29 La = A
30
31 Lx = iand(Lx*La,i246m1)
32 randlc = d2m46*dble(Lx)
33 x = dble(Lx)
34 return
35 end
36
37
38c---------------------------------------------------------------------
39c---------------------------------------------------------------------
40
41
42 SUBROUTINE VRANLC (N, X, A, Y)
43 implicit none
44 integer n, i
45 double precision x, a, y(*)
46 integer*8 i246m1, Lx, La
47 double precision d2m46
48
49c This doesn't work, because the compiler does the calculation in 32
50c bits and overflows. No standard way (without f90 stuff) to specify
51c that the rhs should be done in 64 bit arithmetic.
52c parameter(i246m1=2**46-1)
53
54 parameter(d2m46=0.5d0**46)
55
56 save i246m1
57 data i246m1/X'00003FFFFFFFFFFF'/
58
59c Note that the v6 compiler on an R8000 does something stupid with
60c the above. Using the following instead (or various other things)
61c makes the calculation run almost 10 times as fast.
62c
63c save d2m46
64c data d2m46/0.0d0/
65c if (d2m46 .eq. 0.0d0) then
66c d2m46 = 0.5d0**46
67c endif
68
69 Lx = X
70 La = A
71 do i = 1, N
72 Lx = iand(Lx*La,i246m1)
73 y(i) = d2m46*dble(Lx)
74 end do
75 x = dble(Lx)
76
77 return
78 end
79
Note: See TracBrowser for help on using the repository browser.