This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH, fortran/52879] RANDOM_SEED revisited
- From: Steve Kargl <sgk at troutmask dot apl dot washington dot edu>
- To: Dominique Dhumieres <dominiq at lps dot ens dot fr>
- Cc: fortran at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org, nmm1 at cam dot ac dot uk
- Date: Sun, 9 Feb 2014 09:06:47 -0800
- Subject: Re: [PATCH, fortran/52879] RANDOM_SEED revisited
- Authentication-results: sourceware.org; auth=none
- References: <20140209143109 dot 181EB104 at mailhost dot lps dot ens dot fr>
On Sun, Feb 09, 2014 at 03:31:09PM +0100, Dominique Dhumieres wrote:
> Steve,
>
> First, it is needed to remove the line
>
> mpz_t put_size, get_size;
>
> in gcc/fortran/check.c, otherwise compiling the file with -Werror
> (default) fails.
OK.
> Second, the patch breaks the interface of RANDOM_SEED(GET/PUT...)
> as shown for gfortran.dg/random_seed_1.f90 and the original test
> in pr52879. This likely makes the patch stage 1 material.
Technically, it doesn't change the interface as SIZE should
be used to determine the shape of GET/PUT. random_seed_1.f90
was specifically crafted with the assumption that SIZE=12.
But, yes, I know gfortran users will have hard coded 12 into
their codes.
As far as stage 1, it was low hanging fruit and I had a little time
to look at a gfortran PR.
> AFAIU my tests in pr52879, comment 1, the generated sequence for real
> does not depend on the four first integers. From a user point of view,
> this surprising (may be undocumented, I did not check).
I could not remember what your comment 1 was trying to convey. But.
yes the 12 seeds were originally split into 3 groups of 4. The first
set went to the first 32-bits, the second set was used for the next
32-bits, and the last 4 give the next 49 bits. Then, ...
> So I think the seed generation should keep the present properties
> and only add a way to randomize the 12 integers.
FX added the scramble_seed() and unscramble_seed() functions to
try to randomize the seeds. But, as shown in comment 0, it is
possible to give random_seed() a set of seeds that defeats FX's
scrambling. The scrambling still yields the grouping as described
above. This gives the nice property of
program rnd
real(4) a04
real(8) a08
real(10) a10
real(16) a16
call random_seed() ; call random_number(a04) ; print *, a04
call random_seed() ; call random_number(a08) ; print *, a08
call random_seed() ; call random_number(a10) ; print *, a10
call random_seed() ; call random_number(a16) ; print *, a16
end program rnd
% gfc4x -o z -O rnd1.f90 && ./z
0.997559547
0.99755959009261719
0.997559590092617187729
0.997559590092617200441811501464004185
To go beyond the scrambling that FX gave us, I think would require
a caching the user defined seeds (so GET will recover PUT) and
much more complicated mashing up of 12 numbers.
--
Steve