From 99d9f1c9f15de8bd825e4a4488cc59853749faf6 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Thu, 25 Nov 2021 11:48:45 -0300 Subject: [PATCH 1/3] AMUN: Initialize RNG before module SYSTEM. Signed-off-by: Grzegorz Kowal --- sources/amun.F90 | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/sources/amun.F90 b/sources/amun.F90 index 39b1e92..20dfd84 100644 --- a/sources/amun.F90 +++ b/sources/amun.F90 @@ -43,7 +43,7 @@ program amun use random , only : initialize_random, finalize_random use system , only : initialize_system, finalize_system use system , only : print_system_info, prepare_system, evolve_system - use system , only : quit, nsteps, rngtype, nwork + use system , only : quit, nsteps, nwork use timers , only : initialize_timers, finalize_timers use timers , only : start_timer, stop_timer, set_timer, get_timer use timers , only : get_timer_total, timer_enabled, timer_description @@ -138,21 +138,21 @@ program amun call print_message(loc, "Could not read parameters!") if (check_status(status /= 0)) go to 6000 -! initialize a few basic modules: IO, SYSTEM, RRANDOM, and WORKSPACE +! initialize a few basic modules: IO, RANDOM, SYSTEM, and WORKSPACE ! call initialize_io(verbose, status) if (status /= 0) & call print_message(loc, "Could not initialize module IO!") if (check_status(status /= 0)) go to 5000 + call initialize_random("same", 1, 0, nproc, status) + if (status /= 0) & + call print_message(loc, "Could not initialize module RANDOM!") + if (check_status(status /= 0)) go to 4000 + call initialize_system(verbose, status) if (status /= 0) & call print_message(loc, "Could not initialize module SYSTEM!") - if (check_status(status /= 0)) go to 4000 - - call initialize_random(rngtype, 1, 0, nproc, status) - if (status /= 0) & - call print_message(loc, "Could not initialize module RANDOM!") if (check_status(status /= 0)) go to 3000 call initialize_workspace(nwork, status) @@ -196,14 +196,14 @@ program amun call print_message(loc, "Could not finalize module WORKSPACE!") 2000 continue - call finalize_random(status) - if (status /= 0) & - call print_message(loc, "Could not finalize module RANDOM!") - 3000 continue - call finalize_system(verbose, status) if (status /= 0) & call print_message(loc, "Could not finalize module SYSTEM!") + 3000 continue + + call finalize_random(status) + if (status /= 0) & + call print_message(loc, "Could not finalize module RANDOM!") 4000 continue call finalize_io(status) From 54263b263c0551e6015ec889952412bc5a4478c9 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Thu, 25 Nov 2021 11:54:06 -0300 Subject: [PATCH 2/3] RANDOM: Add subroutine to reset the seeds. This subroutine will restore the initial seeds values. Signed-off-by: Grzegorz Kowal --- sources/random.F90 | 60 ++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 55 insertions(+), 5 deletions(-) diff --git a/sources/random.F90 b/sources/random.F90 index 64002a0..56cd9d2 100644 --- a/sources/random.F90 +++ b/sources/random.F90 @@ -53,14 +53,10 @@ module random ! real(kind=8), parameter :: i64tor8 = 2.0d+00**(-53) -! by default everything is private -! private -! declare public subroutines -! public :: initialize_random, finalize_random - public :: nseeds, set_seeds, get_seeds, gentype + public :: nseeds, reset_seeds, set_seeds, get_seeds, gentype public :: randuni, randsym, randnorz contains @@ -175,6 +171,60 @@ module random ! !=============================================================================== ! +! subroutine RESET_SEEDS: +! ---------------------- +! +! Subroutine resets the seeds, according to the generator type. +! +! Arguments: +! +! rngtype - the generator type ('same' or 'random'); +! +!=============================================================================== +! + subroutine reset_seeds(rngtype) + + implicit none + + character(len=*), intent(in) :: rngtype + + integer :: i + + integer(kind=8), dimension(4) :: s + +!------------------------------------------------------------------------------- +! + select case(trim(rngtype)) + case('random') + state = 1234567890 + s(1) = splitmix64() + s(2) = splitmix64() + s(3) = splitmix64() + s(4) = splitmix64() + do i = 1, nseeds * np + call jump(s(:)) + end do + seeds(:,0) = s(:) + do i = 1, lseed + call jump(s(:)) + seeds(:,i) = s(:) + end do + gentype = 'random' + case default + state = 1234567890 + seeds(1,:) = splitmix64() + seeds(2,:) = splitmix64() + seeds(3,:) = splitmix64() + seeds(4,:) = splitmix64() + gentype = 'same' + end select + +!------------------------------------------------------------------------------- +! + end subroutine reset_seeds +! +!=============================================================================== +! ! subroutine SET_SEEDS: ! -------------------- ! From aa552c7a515154deda33a4a2a2dcb2811f8421f2 Mon Sep 17 00:00:00 2001 From: Grzegorz Kowal Date: Thu, 25 Nov 2021 11:56:01 -0300 Subject: [PATCH 3/3] SYSTEM: Reset seeds in initialize_system(). Signed-off-by: Grzegorz Kowal --- sources/system.F90 | 3 +++ 1 file changed, 3 insertions(+) diff --git a/sources/system.F90 b/sources/system.F90 index 10110dd..faf3440 100644 --- a/sources/system.F90 +++ b/sources/system.F90 @@ -115,6 +115,7 @@ module system use mesh , only : initialize_mesh use mpitools , only : check_status use problems , only : initialize_problems + use random , only : reset_seeds use statistics , only : initialize_statistics implicit none @@ -133,6 +134,8 @@ module system call print_message(loc, "Could not restore the system parameters!") if (check_status(status /= 0)) return + call reset_seeds(rngtype) + call initialize_equations(eqsys, eos, verbose, status) if (status /=0) & call print_message(loc, "Could not initialize module EQUATIONS!")