2 ! { dg-options "-O2 -fdump-tree-optimized" }
6 ! Contributed by Joost VandeVondele
8 MODULE parallel_rng_types
12 ! Global parameters in this module
13 INTEGER, PARAMETER :: dp
=8
17 CHARACTER(LEN
=40) :: name
18 INTEGER :: distribution_type
19 REAL(KIND
=dp
), DIMENSION(3,2) :: bg
,cg
,ig
20 LOGICAL :: antithetic
,extended_precision
21 REAL(KIND
=dp
) :: buffer
22 LOGICAL :: buffer_filled
23 END TYPE rng_stream_type
25 REAL(KIND
=dp
), DIMENSION(3,3) :: a1p0
,a1p76
,a1p127
,&
29 INTEGER, PARAMETER :: GAUSSIAN
= 1,&
32 REAL(KIND
=dp
), PARAMETER :: norm
= 2.328306549295727688e-10_dp
,&
33 m1
= 4294967087.0_dp
,&
34 m2
= 4294944443.0_dp
,&
39 two17
= 131072.0_dp
,& ! 2**17
40 two53
= 9007199254740992.0_dp
,& ! 2**53
41 fact
= 5.9604644775390625e-8_dp
! 1/2**24
46 FUNCTION rn32(rng_stream
) RESULT(u
)
48 TYPE(rng_stream_type
), POINTER :: rng_stream
52 REAL(KIND
=dp
) :: p1
, p2
54 ! -------------------------------------------------------------------------
57 p1
= a12
*rng_stream
%cg(2,1) - a13n
*rng_stream
%cg(1,1)
60 IF (p1
< 0.0_dp
) p1
= p1
+ m1
61 rng_stream
%cg(1,1) = rng_stream
%cg(2,1)
62 rng_stream
%cg(2,1) = rng_stream
%cg(3,1)
63 rng_stream
%cg(3,1) = p1
67 p2
= a21
*rng_stream
%cg(3,2) - a23n
*rng_stream
%cg(1,2)
70 IF (p2
< 0.0_dp
) p2
= p2
+ m2
71 rng_stream
%cg(1,2) = rng_stream
%cg(2,2)
72 rng_stream
%cg(2,2) = rng_stream
%cg(3,2)
73 rng_stream
%cg(3,2) = p2
80 u
= (p1
- p2
+ m1
)*norm
83 IF (rng_stream
%antithetic
) u
= 1.0_dp
- u
87 ! *****************************************************************************
88 FUNCTION rn53(rng_stream
) RESULT(u
)
90 TYPE(rng_stream_type
), POINTER :: rng_stream
95 IF (rng_stream
%antithetic
) THEN
96 u
= u
+ (rn32(rng_stream
) - 1.0_dp
)*fact
97 IF (u
< 0.0_dp
) u
= u
+ 1.0_dp
99 u
= u
+ rn32(rng_stream
)*fact
100 IF (u
>= 1.0_dp
) u
= u
- 1.0_dp
107 ! { dg-final { scan-module-absence "parallel_rng_types" "IMPLICIT_PURE" } }
108 ! { dg-final { scan-tree-dump-times "rn32 \\(rng_stream" 3 "optimized" } }