RANDOM: Rewrite seed numbers handling.
The array of seed numbers makes sense only when OpenMP is used. With MPI on, the length of seed vector on each MPI process is equal to the number of OpenMP threads. For no OpenMP, only one seed number per MPI process is used. Signed-off-by: Grzegorz Kowal <grzegorz@amuncode.org>
This commit is contained in:
parent
56ec194862
commit
eef631de50
@ -308,9 +308,10 @@ program amun
|
|||||||
!
|
!
|
||||||
call setup_mpi(div(:), per(:), .false.)
|
call setup_mpi(div(:), per(:), .false.)
|
||||||
|
|
||||||
! initialize the random number generator
|
! initialize the random number generator (passes the number of OpenMP threads
|
||||||
|
! and the current thread number)
|
||||||
!
|
!
|
||||||
call initialize_random(nprocs, nproc)
|
call initialize_random(1, 0)
|
||||||
|
|
||||||
! initialize geometry modules and print info
|
! initialize geometry modules and print info
|
||||||
!
|
!
|
||||||
|
@ -80,7 +80,7 @@ module random
|
|||||||
!
|
!
|
||||||
!===============================================================================
|
!===============================================================================
|
||||||
!
|
!
|
||||||
subroutine initialize_random(nprocs, nproc)
|
subroutine initialize_random(nthreads, nthread)
|
||||||
|
|
||||||
! obtain required variables from other modules
|
! obtain required variables from other modules
|
||||||
!
|
!
|
||||||
@ -92,7 +92,7 @@ module random
|
|||||||
|
|
||||||
! subroutine arguments
|
! subroutine arguments
|
||||||
!
|
!
|
||||||
integer, intent(in) :: nprocs, nproc
|
integer, intent(in) :: nthreads, nthread
|
||||||
|
|
||||||
! local variables
|
! local variables
|
||||||
!
|
!
|
||||||
@ -112,9 +112,9 @@ module random
|
|||||||
call start_timer(iri)
|
call start_timer(iri)
|
||||||
#endif /* PROFILE */
|
#endif /* PROFILE */
|
||||||
|
|
||||||
! set the processor number
|
! set the thread number
|
||||||
!
|
!
|
||||||
kp = nproc
|
kp = nthread
|
||||||
|
|
||||||
! obtain the generator type
|
! obtain the generator type
|
||||||
!
|
!
|
||||||
@ -122,7 +122,7 @@ module random
|
|||||||
|
|
||||||
! calculate the number of seeds
|
! calculate the number of seeds
|
||||||
!
|
!
|
||||||
nseeds = 2 * nprocs
|
nseeds = nthreads
|
||||||
lseed = nseeds - 1
|
lseed = nseeds - 1
|
||||||
|
|
||||||
! allocate seeds for random number generator
|
! allocate seeds for random number generator
|
||||||
@ -138,12 +138,8 @@ module random
|
|||||||
seeds(i) = 123456789 * r
|
seeds(i) = 123456789 * r
|
||||||
end do
|
end do
|
||||||
case default
|
case default
|
||||||
call random_number(r)
|
r = 0.1234567890123456789
|
||||||
do i = 0, nprocs - 1
|
do i = 0, lseed
|
||||||
seeds(i) = 123456789 * r
|
|
||||||
end do
|
|
||||||
call random_number(r)
|
|
||||||
do i = nprocs, lseed
|
|
||||||
seeds(i) = 123456789 * r
|
seeds(i) = 123456789 * r
|
||||||
end do
|
end do
|
||||||
end select
|
end select
|
||||||
@ -204,7 +200,7 @@ module random
|
|||||||
!
|
!
|
||||||
!===============================================================================
|
!===============================================================================
|
||||||
!
|
!
|
||||||
subroutine set_seeds(np, seed)
|
subroutine set_seeds(np, nseeds)
|
||||||
|
|
||||||
! declare all variables as implicit
|
! declare all variables as implicit
|
||||||
!
|
!
|
||||||
@ -212,8 +208,8 @@ module random
|
|||||||
|
|
||||||
! input arguments
|
! input arguments
|
||||||
!
|
!
|
||||||
integer , intent(in) :: np
|
integer , intent(in) :: np
|
||||||
integer(kind=4), dimension(0:np-1), intent(in) :: seed
|
integer(kind=4), dimension(np), intent(in) :: nseeds
|
||||||
|
|
||||||
! local variables
|
! local variables
|
||||||
!
|
!
|
||||||
@ -230,35 +226,19 @@ module random
|
|||||||
|
|
||||||
! set the seeds only if the input array and seeds have the same sizes
|
! set the seeds only if the input array and seeds have the same sizes
|
||||||
!
|
!
|
||||||
if (np == nseeds) then
|
l = min(lseed, np - 1)
|
||||||
|
seeds(0:l) = seed(1:l+1)
|
||||||
seeds(0:lseed) = seed(0:lseed)
|
select case(gentype)
|
||||||
|
case('random')
|
||||||
else
|
if (l < lseed) then
|
||||||
|
do i = l + 1, lseed
|
||||||
! if the input array and seeds have different sizes, expand or shrink seeds
|
call random_number(r)
|
||||||
!
|
seeds(i) = 123456789 * r
|
||||||
select case(gentype)
|
|
||||||
case('random')
|
|
||||||
l = min(lseed, np - 1)
|
|
||||||
seeds(0:l) = seed(0:l)
|
|
||||||
if (l < lseed) then
|
|
||||||
do i = l + 1, lseed
|
|
||||||
call random_number(r)
|
|
||||||
seeds(i) = 123456789 * r
|
|
||||||
end do
|
|
||||||
end if
|
|
||||||
case default
|
|
||||||
l = nseeds / 2
|
|
||||||
do i = 0, l - 1
|
|
||||||
seeds(i) = seed(0)
|
|
||||||
end do
|
end do
|
||||||
do i = l, lseed
|
end if
|
||||||
seeds(i) = seed(np-1)
|
case default
|
||||||
end do
|
seeds(l+1:lseed) = seeds(0)
|
||||||
end select
|
end select
|
||||||
|
|
||||||
end if
|
|
||||||
|
|
||||||
#ifdef PROFILE
|
#ifdef PROFILE
|
||||||
! stop accounting time for the random number generator
|
! stop accounting time for the random number generator
|
||||||
@ -279,7 +259,7 @@ module random
|
|||||||
!
|
!
|
||||||
!===============================================================================
|
!===============================================================================
|
||||||
!
|
!
|
||||||
subroutine get_seeds(seed)
|
subroutine get_seeds(rseeds)
|
||||||
|
|
||||||
! declare all variables as implicit
|
! declare all variables as implicit
|
||||||
!
|
!
|
||||||
@ -287,7 +267,7 @@ module random
|
|||||||
|
|
||||||
! output arguments
|
! output arguments
|
||||||
!
|
!
|
||||||
integer(kind=4), dimension(0:lseed), intent(out) :: seed
|
integer(kind=4), dimension(nseeds), intent(out) :: rseeds
|
||||||
!
|
!
|
||||||
!-------------------------------------------------------------------------------
|
!-------------------------------------------------------------------------------
|
||||||
!
|
!
|
||||||
@ -297,7 +277,7 @@ module random
|
|||||||
call start_timer(iri)
|
call start_timer(iri)
|
||||||
#endif /* PROFILE */
|
#endif /* PROFILE */
|
||||||
|
|
||||||
seed(0:lseed) = seeds(0:lseed)
|
rseeds(1:nseeds) = seeds(0:lseed)
|
||||||
|
|
||||||
#ifdef PROFILE
|
#ifdef PROFILE
|
||||||
! stop accounting time for the random number generator
|
! stop accounting time for the random number generator
|
||||||
|
Loading…
x
Reference in New Issue
Block a user