gcc/libgfortran
Janne Blomqvist 0eaee4abb1 Improve PRNG jumping when using threads
Currently, when a new thread needs to use the RANDOM_NUMBER intrinsic,
the per-thread PRNG state is initialized by copying the master state
and then jumping forwards N*2**128 entries in the stream so that the
PRNG streams for different threads don't alias each other, where N is
the number of threads that have so far initialized the PRNG.

With this patch the master state itself is jumped forwards once each
time a new thread initializes the PRNG, thus obviating the need to
jump through all the N-1 previous streams. Effectively turning an O(N)
algorithm into an O(1) one.

Regtested on x86_64-pc-linux-gnu.

libgfortran/ChangeLog:

2019-09-05  Janne Blomqvist  <jb@gcc.gnu.org>

	* intrinsics/random.c (master_init): Replace with
	master_state.init.
	(njumps): Remove variable.
	(master_state): Make instance of struct prng_state.
	(init_rand_state): When jumping, update the master_state once
	instead of keeping track of how many jumps need to be done.
	(SZU64): Modify to handle new master_state.
	(SZ): Likewise.
	(random_seed_i4): Likewise.
	(random_seed_i8): Likewise.

From-SVN: r275397
2019-09-05 09:59:55 +03:00
..
caf re PR libfortran/89593 (warning "passing argument 3 of ‘_gfortran_caf_{get,send}_by_ref’ from incompatible pointer type" when building libgfortran) 2019-03-05 23:41:39 +01:00
config re PR fortran/88678 (Many gfortran.dg/ieee/ieee_X.f90 test cases fail starting with r267465) 2019-01-30 21:44:35 +01:00
generated re PR fortran/54613 ([F08] Add FINDLOC plus support MAXLOC/MINLOC with KIND=/BACK=) 2019-05-17 19:50:55 +02:00
ieee
intrinsics Improve PRNG jumping when using threads 2019-09-05 09:59:55 +03:00
io PR 53796 Make inquire(file=, recl=) conform to F2018 2019-08-07 10:34:10 +03:00
m4 re PR libfortran/88807 (misleading indentation warnings building libgfortran) 2019-01-12 10:15:54 +01:00
runtime PR fortran/68401 Improve allocation error message 2019-08-17 08:45:37 +03:00
acinclude.m4
aclocal.m4
c99_protos.h
ChangeLog Improve PRNG jumping when using threads 2019-09-05 09:59:55 +03:00
ChangeLog-2002
ChangeLog-2003
ChangeLog-2004
ChangeLog-2005
ChangeLog-2006
ChangeLog-2007
ChangeLog-2008
ChangeLog-2009
ChangeLog-2010
ChangeLog-2011
ChangeLog-2012
ChangeLog-2013
ChangeLog-2014
ChangeLog-2015
ChangeLog-2016
ChangeLog-2017
ChangeLog-2018
config.h.in libfortran/90038 Reap dead children when wait=.false. 2019-05-19 22:38:11 +03:00
configure Enable full GFortran library for AMD GCN 2019-06-25 11:41:38 +00:00
configure.ac Enable full GFortran library for AMD GCN 2019-06-25 11:41:38 +00:00
configure.host
gfortran.map PR fortran/68401 Improve allocation error message 2019-08-17 08:45:37 +03:00
ISO_Fortran_binding.h gfortran.texi: Add description in sections on TS 29113 and further interoperability with C. 2019-01-12 15:25:52 +00:00
kinds-override.h
libgfortran.h PR fortran/68401 Improve allocation error message 2019-08-17 08:45:37 +03:00
libgfortran.spec.in
libtool-version
Makefile.am re PR fortran/54613 ([F08] Add FINDLOC plus support MAXLOC/MINLOC with KIND=/BACK=) 2019-05-17 19:24:27 +02:00
Makefile.in libfortran/90038: Use posix_spawn instead of fork 2019-05-17 21:18:04 +03:00
mk-kinds-h.sh
mk-sik-inc.sh
mk-srk-inc.sh