TABLE OF CONTENTS


ABINIT/m_OurRng [ Modules ]

[ Top ] [ Modules ]

NAME

  m_OurRng

FUNCTION

  Random number generator module
  Should be modify and merge with uniformrandom and zbq

COPYRIGHT

  Copyright (C) 2013-2022 ABINIT group (J. Bieder)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

NOTES

SOURCE

23 #include "defs.h"
24 
25 MODULE m_OurRng
26 !! Implementation of various RNG with a small footprint
27 
28  !use m_numeric_tools,  only : uniformrandom
29 
30 IMPLICIT NONE
31 
32 PRIVATE
33 
34 PUBLIC :: OurRng
35 
36 CONTAINS

ABINIT/m_OurRng/OurRng [ Functions ]

[ Top ] [ Functions ]

NAME

  OurRng

FUNCTION

  Generator given by G. Colin de Verdiere
  Efficient on GPU and MIC

COPYRIGHT

  Copyright (C) 2013-2022 ABINIT group (J. Bieder)
  This file is distributed under the terms of the
  GNU General Public License, see ~abinit/COPYING
  or http://www.gnu.org/copyleft/gpl.txt .

INPUTS

  xn=seed
  rng=random number

OUTPUT

SIDE EFFECTS

NOTES

SOURCE

65 SUBROUTINE OurRng(xn,rng)
66   ! returns a value between 0. and 1. with a period of 2**31
67   ! implements the Marsaglia serie:
68   !   xn+1 = (69069 * xn) mod 2^31
69 !Arguments ------------------------------------
70   DOUBLE PRECISION, INTENT(  OUT) :: rng
71   INTEGER(8), INTENT(INOUT) :: xn
72   !
73   INTEGER(8) :: two31  ! 2 ** 31
74   INTEGER(8) :: two31m ! 2 ** 31 -1
75   INTEGER(8), PARAMETER :: mars   = 69069
76   INTEGER(8) :: xn8
77   INTRINSIC MOD, REAL, IAND
78 
79   two31 = 1
80   two31 = two31 * 65536   ! **16
81   two31 = two31 * 32768   ! **31
82   two31m = two31 - 1
83 
84 !!$  two31  = z'80000000'
85 !!$  two31m = z'7FFFFFFF'
86 
87   IF (xn == 0) xn = 1
88   xn8 = (mars * xn)
89   xn8 = IAND(xn8, two31m)
90   xn = xn8
91 
92   rng = REAL(xn, 8) / REAL(two31m, 8)
93   ! guard to avoid pick up one since that sould never happen (otherwise ctqmc
94   ! may generate an error and exit the code)
95   if ( rng == 1.d0 ) rng = 0.d0
96 END SUBROUTINE OurRng