diff options
author | Janne Blomqvist <jb@gcc.gnu.org> | 2019-09-05 09:59:55 +0300 |
---|---|---|
committer | Janne Blomqvist <jb@gcc.gnu.org> | 2019-09-05 09:59:55 +0300 |
commit | 0eaee4abb1d99f6165769a8ad2bfbf818860f40b (patch) | |
tree | 00b19c147fb98d452597b2fdbda9432eb4395450 /libcpp/files.c | |
parent | f44526e367a99b8699fbdc31bb9bcc0618dbe072 (diff) | |
download | gcc-0eaee4abb1d99f6165769a8ad2bfbf818860f40b.zip gcc-0eaee4abb1d99f6165769a8ad2bfbf818860f40b.tar.gz gcc-0eaee4abb1d99f6165769a8ad2bfbf818860f40b.tar.bz2 |
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
Diffstat (limited to 'libcpp/files.c')
0 files changed, 0 insertions, 0 deletions