diff options
author | Steven G. Kargl <kargl@gcc.gnu.org> | 2018-06-01 17:05:02 +0000 |
---|---|---|
committer | Steven G. Kargl <kargl@gcc.gnu.org> | 2018-06-01 17:05:02 +0000 |
commit | ddd3e26e42b8d55989f9964c6ec6ee50b30b1802 (patch) | |
tree | 0bf61ebd5153e8a07d2e13d7f8dc20fc8dfbcfea /libgfortran | |
parent | 77b8fb05b3ae9223abb7bac05d8af6892cfa251a (diff) | |
download | gcc-ddd3e26e42b8d55989f9964c6ec6ee50b30b1802.zip gcc-ddd3e26e42b8d55989f9964c6ec6ee50b30b1802.tar.gz gcc-ddd3e26e42b8d55989f9964c6ec6ee50b30b1802.tar.bz2 |
re PR fortran/63570 ([F2018] Implement 13.7.137 RANDOM INIT (REPEATABLE, IMAGE DISTINCT))
2018-06-01 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/63570
* check.c (gfc_check_random_init): New function. Check arguments of
RANDOM_INIT.
* gfortran.h (GFC_ISYM_RANDOM_INIT): New enum token.
* intrinsic.c (add_subroutines): Add RANDOM_INIT to list of
subroutines.
(gfc_check_intrinsic_standard): Introduce Fortran 2018 check.
* intrinsic.h: Add prototypes for gfc_check_random_init and
gfc_resolve_random_init
* intrinsic.texi: Document new intrinsic subprogram.
* iresolve.c (gfc_resolve_random_init): Resolve routine name.
* trans-decl.c: Declare gfor_fndecl_random_init
* trans-intrinsic.c (conv_intrinsic_random_init): New function.
Translate call to RANDOM_INIT.
(gfc_conv_intrinsic_subroutine): Call it.
* trans.h: Declare gfor_fndecl_random_init
2018-06-01 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/63570
* gfortran.dg/random_init_1.f90: New test.
* gfortran.dg/random_init_2.f90: New test.
* gfortran.dg/random_init_3.f90: New test.
* gfortran.dg/random_init_4.f90: New test.
* gfortran.dg/random_init_5.f90: New test.
* gfortran.dg/random_init_6.f90: New test.
2018-06-01 Steven G. Kargl <kargl@gcc.gnu.org>
PR fortran/63570
* libgfortran/Makefile.am: Add random_init.f90 to build.
* libgfortran/Makefile.in: Regenerated.
* libgfortran/gfortran.map: Expose symbol for _gfortran_random_init.
* libgfortran/intrinsics/random_init.f90: Implementation.
From-SVN: r261075
Diffstat (limited to 'libgfortran')
-rw-r--r-- | libgfortran/ChangeLog | 8 | ||||
-rw-r--r-- | libgfortran/Makefile.am | 3 | ||||
-rw-r--r-- | libgfortran/Makefile.in | 8 | ||||
-rw-r--r-- | libgfortran/gfortran.map | 1 | ||||
-rw-r--r-- | libgfortran/intrinsics/random_init.f90 | 94 |
5 files changed, 111 insertions, 3 deletions
diff --git a/libgfortran/ChangeLog b/libgfortran/ChangeLog index c0b0f85..a220cc8 100644 --- a/libgfortran/ChangeLog +++ b/libgfortran/ChangeLog @@ -1,3 +1,11 @@ +2018-06-01 Steven G. Kargl <kargl@gcc.gnu.org> + + PR fortran/63570 + * libgfortran/Makefile.am: Add random_init.f90 to build. + * libgfortran/Makefile.in: Regenerated. + * libgfortran/gfortran.map: Expose symbol for _gfortran_random_init. + * libgfortran/intrinsics/random_init.f90: Implementation. + 2018-05-28 Jerry DeLisle <jvdelisle@gcc.gnu.org> PR libgfortran/85840 diff --git a/libgfortran/Makefile.am b/libgfortran/Makefile.am index bf9dce4..5831631 100644 --- a/libgfortran/Makefile.am +++ b/libgfortran/Makefile.am @@ -915,7 +915,8 @@ $(gfor_built_specific_src) \ $(gfor_built_specific2_src) \ $(gfor_misc_specifics) \ intrinsics/dprod_r8.f90 \ -intrinsics/f2c_specifics.F90 +intrinsics/f2c_specifics.F90 \ +intrinsics/random_init.f90 # Turn on vectorization and loop unrolling for matmul. $(patsubst %.c,%.lo,$(notdir $(i_matmul_c))): AM_CFLAGS += -ffast-math -ftree-vectorize -funroll-loops --param max-unroll-times=4 diff --git a/libgfortran/Makefile.in b/libgfortran/Makefile.in index 03c3968..b66a91b 100644 --- a/libgfortran/Makefile.in +++ b/libgfortran/Makefile.in @@ -408,7 +408,7 @@ am__objects_56 = _sign_i4.lo _sign_i8.lo _sign_i16.lo _sign_r4.lo \ _mod_r10.lo _mod_r16.lo am__objects_57 = misc_specifics.lo am__objects_58 = $(am__objects_55) $(am__objects_56) $(am__objects_57) \ - dprod_r8.lo f2c_specifics.lo + dprod_r8.lo f2c_specifics.lo random_init.lo am__objects_59 = $(am__objects_3) $(am__objects_47) $(am__objects_49) \ $(am__objects_52) $(am__objects_53) $(am__objects_54) \ $(am__objects_58) @@ -1374,7 +1374,8 @@ $(gfor_built_specific_src) \ $(gfor_built_specific2_src) \ $(gfor_misc_specifics) \ intrinsics/dprod_r8.f90 \ -intrinsics/f2c_specifics.F90 +intrinsics/f2c_specifics.F90 \ +intrinsics/random_init.f90 BUILT_SOURCES = $(gfor_built_src) $(gfor_built_specific_src) \ $(gfor_built_specific2_src) $(gfor_misc_specifics) \ @@ -6230,6 +6231,9 @@ selected_real_kind.lo: intrinsics/selected_real_kind.f90 dprod_r8.lo: intrinsics/dprod_r8.f90 $(LIBTOOL) --tag=FC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(FC) $(AM_FCFLAGS) $(FCFLAGS) -c -o dprod_r8.lo `test -f 'intrinsics/dprod_r8.f90' || echo '$(srcdir)/'`intrinsics/dprod_r8.f90 +random_init.lo: intrinsics/random_init.f90 + $(LIBTOOL) --tag=FC $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(FC) $(AM_FCFLAGS) $(FCFLAGS) -c -o random_init.lo `test -f 'intrinsics/random_init.f90' || echo '$(srcdir)/'`intrinsics/random_init.f90 + mostlyclean-libtool: -rm -f *.lo diff --git a/libgfortran/gfortran.map b/libgfortran/gfortran.map index 29af0dc..78f8d7e 100644 --- a/libgfortran/gfortran.map +++ b/libgfortran/gfortran.map @@ -799,6 +799,7 @@ GFORTRAN_8 { _gfortran_product_r4; _gfortran_product_r8; _gfortran_rand; + _gfortran_random_init; _gfortran_random_r10; _gfortran_random_r16; _gfortran_random_r4; diff --git a/libgfortran/intrinsics/random_init.f90 b/libgfortran/intrinsics/random_init.f90 new file mode 100644 index 0000000..edea0b8 --- /dev/null +++ b/libgfortran/intrinsics/random_init.f90 @@ -0,0 +1,94 @@ +! Copyright (C) 2018 Free Software Foundation, Inc. +! Contributed by Steven G. Kargl <kargl@gcc.gnu.org> +! +! This file is part of the GNU Fortran runtime library (libgfortran). +! +! Libgfortran is free software; you can redistribute it and/or +! modify it under the terms of the GNU General Public +! License as published by the Free Software Foundation; either +! version 3 of the License, or (at your option) any later version. +! +! Libgfortran is distributed in the hope that it will be useful, +! but WITHOUT ANY WARRANTY; without even the implied warranty of +! MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +! GNU General Public License for more details. +! +! Under Section 7 of GPL version 3, you are granted additional +! permissions described in the GCC Runtime Library Exception, version +! 3.1, as published by the Free Software Foundation. +! +! You should have received a copy of the GNU General Public License and +! a copy of the GCC Runtime Library Exception along with this program; +! see the files COPYING3 and COPYING.RUNTIME respectively. If not, see +! <http://www.gnu.org/licenses/>. +! +! +! WARNING: This file should never be compiled with an option that changes +! default logical kind from 4 to some other value or changes default integer +! kind from from 4 to some other value. +! +! +! There are four combinations of repeatable and image_distinct. If a program +! is compiled without the -fcoarray= option or with -fcoarray=single, then +! execution of the compiled executable does not use image_distinct as it is +! irrelevant (although required). The behavior is as follows: +! +! call random_init(.true., .true.) +! +! The sequence of random numbers is repeatable within an instance of program +! execution. That is, calls to random_init(.true., .true.) during the +! execution will reset the sequence of RN to the same sequence. If the +! program is compiled with -fcoarray=lib and multiple images are instantiated, +! then each image accesses a repeatable distinct sequence of random numbers. +! There are no guarantees that multiple execution of the program will access +! the same sequence. +! +! call random_init(.false., .false.) +! call random_init(.false., .true.) +! +! The sequence of random numbers is determined from process-dependent seeds. +! On each execution of the executable, different seeds will be used. For +! -fcoarray=lib and multiple instantiated images, each image will use +! process-dependent seeds. In other words, the two calls have identical +! behavior. +! +! call random_init(.true., .false.) +! +! For a program compiled without the -fcoarray= option or with +! -fcoarray=single, a single image is instantiated when the executable is +! run. If the executable causes multiple images to be instantiated, then +! image_distinct=.false. in one image cannot affect the sequence of random +! numbers in another image. As gfortran gives each image its own independent +! PRNG, this condition is automatically satisfied. +! +impure subroutine _gfortran_random_init(repeatable, image_distinct, hidden) + + implicit none + + logical, value, intent(in) :: repeatable + logical, value, intent(in) :: image_distinct + integer, value, intent(in) :: hidden + + logical, save :: once = .true. + integer :: nseed + integer, save, allocatable :: seed(:) + + if (once) then + once = .false. + call random_seed(size=nseed) + allocate(seed(nseed)) + call random_seed(get=seed) + ! + ! To guarantee that seed is distinct on multiple images, add the hidden + ! argument (which is the image index). + ! + if (image_distinct) seed = seed + hidden + end if + + if (repeatable) then + call random_seed(put=seed); + else + call random_seed(); + end if + +end subroutine _gfortran_random_init |