Skip to content

Commit

Permalink
Enable a constant random seed. Remove references to old seeds and the…
Browse files Browse the repository at this point in the history
… old rnd module.
  • Loading branch information
cianciosa committed Jun 5, 2024
1 parent ffc8e2a commit a150162
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 193 deletions.
1 change: 0 additions & 1 deletion src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ target_sources(korc
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_types.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_avalanche.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_hpc.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_rnd_numbers.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_units.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_experimental_pdf.f90>
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/korc_initialize.f90>
Expand Down
10 changes: 10 additions & 0 deletions src/korc_c_random.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ class random_dist {
void set_dist(const real_type low, const real_type high) {
dist = DIST(low, high);
}
void set_seed(const uint64_t seed) {
engine.seed(seed);
}
real_type get_number() {
return dist(engine);
}
Expand Down Expand Up @@ -66,4 +69,11 @@ extern "C" {
const real_type high) {
static_cast<random_N *> (r)->set_dist(low, high);
}
void random_set_seed_U(void *r, int seed) {
static_cast<random_U *> (r)->set_seed(static_cast<uint64_t> (seed));
}

void random_set_seed_N(void *r, int seed) {
static_cast<random_N *> (r)->set_seed(static_cast<uint64_t> (seed));
}
}
6 changes: 0 additions & 6 deletions src/korc_experimental_pdf.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ MODULE korc_experimental_pdf
USE korc_HDF5
USE korc_hpc
use korc_coords
use korc_rnd_numbers
use korc_random
use korc_fields
use korc_input
Expand Down Expand Up @@ -704,7 +703,6 @@ SUBROUTINE sample_Hollmann_distribution(params,random,spp)
INTEGER :: ppp
INTEGER :: nsamples
INTEGER :: mpierr
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)

nsamples = spp%ppp*params%mpi_params%nmpi

Expand Down Expand Up @@ -1028,7 +1026,6 @@ subroutine sample_Hollmann_distribution_3D(params,random,spp,F)
!! mpi error indicator
REAL(rp) :: dg,deta
LOGICAL :: accepted
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)

CALL random%uniform%set(0.0_rp,1.0_rp)

Expand Down Expand Up @@ -1442,8 +1439,6 @@ subroutine sample_Hollmann_distribution_3D_psi(params,random,spp,F)
!! mpi error indicator
REAL(rp) :: dg,deta
LOGICAL :: accepted
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)


nsamples = spp%ppp*params%mpi_params%nmpi

Expand Down Expand Up @@ -1973,7 +1968,6 @@ subroutine sample_Hollmann_distribution_1Dtransport(params,random,spp,F)
!! mpi error indicator
REAL(rp) :: dgmin,dgmax,deta
LOGICAL :: accepted
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)
REAL(rp) :: EPHI,fRE_out,nAr0,nAr1,nAr2,nAr3,nD,nD1,ne,Te,Zeff,nRE


Expand Down
1 change: 0 additions & 1 deletion src/korc_initialize.f90
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module korc_initialize
use korc_hpc
use korc_HDF5
use korc_fields
use korc_rnd_numbers
use korc_spatial_distribution
use korc_velocity_distribution
use korc_coords
Expand Down
3 changes: 1 addition & 2 deletions src/korc_interp.f90
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,7 @@ module korc_interp
!! For a detailed documentation of the PSPLINE library we refer the
!! user to "https://w3.pppl.gov/ntcc/PSPLINE/".
use korc_types
use korc_coords
use korc_rnd_numbers
use korc_coords
use korc_hpc

#ifdef PSPLINE
Expand Down
64 changes: 64 additions & 0 deletions src/korc_random.f90
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,28 @@ SUBROUTINE random_set_dist_N(r, low, high) BIND(C, NAME='random_set_dist_N')
END SUBROUTINE random_set_dist_N
END INTERFACE

INTERFACE
SUBROUTINE random_set_seed_U(r, seed) BIND(C, NAME='random_set_seed_U')
USE, INTRINSIC :: iso_c_binding

IMPLICIT NONE

TYPE (C_PTR), VALUE :: r
INTEGER (C_INT), VALUE :: seed
END SUBROUTINE random_set_seed_U
END INTERFACE

INTERFACE
SUBROUTINE random_set_seed_N(r, seed) BIND(C, NAME='random_set_seed_N')
USE, INTRINSIC :: iso_c_binding

IMPLICIT NONE

TYPE (C_PTR), VALUE :: r
INTEGER (C_INT), VALUE :: seed
END SUBROUTINE random_set_seed_N
END INTERFACE

!*******************************************************************************
! Class Defintions
!*******************************************************************************
Expand All @@ -117,6 +139,7 @@ END SUBROUTINE random_set_dist_N
PROCEDURE :: get => random_U_get_random
PROCEDURE :: get_array => random_U_get_randoms
PROCEDURE :: set => random_U_set_dist
PROCEDURE :: seed => random_U_set_seed
FINAL :: random_U_context_destruct
END TYPE

Expand All @@ -125,6 +148,7 @@ END SUBROUTINE random_set_dist_N
PROCEDURE :: get => random_N_get_random
PROCEDURE :: get_array => random_N_get_randoms
PROCEDURE :: set => random_N_set_dist
PROCEDURE :: seed => random_N_set_seed
FINAL :: random_N_context_destruct
END TYPE

Expand Down Expand Up @@ -361,4 +385,44 @@ SUBROUTINE random_N_set_dist(this, low, high)

END SUBROUTINE

SUBROUTINE random_U_set_seed(this, seed, mpi_rank)
IMPLICIT NONE

! Arguments
CLASS (random_U_context), INTENT(in) :: this
INTEGER, INTENT(in) :: seed
INTEGER, INTENT(IN) :: mpi_rank

! Local Variables
INTEGER :: thread_num

! Start of executable code
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(thread_num)
thread_num = get_thread_number()
CALL random_set_seed_U(this%states(thread_num), &
seed + mpi_rank*get_max_threads() + thread_num)
!$OMP END PARALLEL

END SUBROUTINE

SUBROUTINE random_N_set_seed(this, seed, mpi_rank)
IMPLICIT NONE

! Arguments
CLASS (random_N_context), INTENT(in) :: this
INTEGER, INTENT(in) :: seed
INTEGER, INTENT(IN) :: mpi_rank

! Local Variables
INTEGER :: thread_num

! Start of executable code
!$OMP PARALLEL DEFAULT(SHARED) PRIVATE(thread_num)
thread_num = get_thread_number()
CALL random_set_seed_N(this%states(thread_num), &
seed + mpi_rank*get_max_threads() + thread_num)
!$OMP END PARALLEL

END SUBROUTINE

END MODULE korc_random
177 changes: 0 additions & 177 deletions src/korc_rnd_numbers.f90

This file was deleted.

5 changes: 0 additions & 5 deletions src/korc_spatial_distribution.f90
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ MODULE korc_spatial_distribution
USE korc_hpc
use korc_fields
use korc_profiles
use korc_rnd_numbers
use korc_random
use korc_hammersley_generator
use korc_avalanche
Expand Down Expand Up @@ -168,7 +167,6 @@ end subroutine torus
! REAL(rp), DIMENSION(:), ALLOCATABLE :: zeta
!! Uniform deviates in the range \([0,2\pi]\) representing
!! the uniform toroidal angle \(\zeta\) distribution of the particles.
! INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)

! ALLOCATE( theta(spp%ppp) )
! ALLOCATE( zeta(spp%ppp) )
Expand Down Expand Up @@ -1294,7 +1292,6 @@ subroutine MH_psi(params,random,spp,F)
!! mpi error indicator

LOGICAL :: accepted
INTEGER,DIMENSION(34) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)

if (params%mpi_params%rank.EQ.0_idef) then
write(output_unit_write,*) '*** START SAMPLING ***'
Expand Down Expand Up @@ -1695,7 +1692,6 @@ subroutine FIO_therm(params,random,spp,F,P)
!! mpi error indicator

LOGICAL :: accepted
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)

if (params%mpi_params%rank.EQ.0_idef) then
write(output_unit_write,*) '*** START SAMPLING ***'
Expand Down Expand Up @@ -2234,7 +2230,6 @@ subroutine BMC_radial(params,random,spp,F,P)
!! mpi error indicator

LOGICAL :: accepted
INTEGER,DIMENSION(33) :: seed=(/1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1/)
REAL(rp) :: rm_buffer,rm_test
INTEGER :: Nr_a
REAL(rp), ALLOCATABLE,DIMENSION(:) :: r_a,nRE
Expand Down
Loading

0 comments on commit a150162

Please sign in to comment.