diff --git a/CMakeLists.txt b/CMakeLists.txt index a8b801eb75..41ca8d8eec 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -270,7 +270,7 @@ endif() # Show flags being used message(STATUS "Fortran flags: ${f90flags}") message(STATUS "C flags: ${cflags}") -message(STATUS "CXX flags: ${cxxflags}") +message(STATUS "C++ flags: ${cxxflags}") message(STATUS "Linker flags: ${ldflags}") #=============================================================================== diff --git a/src/constants.F90 b/src/constants.F90 index 73aca25d29..2466dbb145 100644 --- a/src/constants.F90 +++ b/src/constants.F90 @@ -1,5 +1,7 @@ module constants + use, intrinsic :: ISO_C_BINDING + implicit none ! ============================================================================ @@ -419,6 +421,7 @@ module constants integer, parameter :: STREAM_SOURCE = 3 integer, parameter :: STREAM_URR_PTABLE = 4 integer, parameter :: STREAM_VOLUME = 5 + integer(C_INT64_T), parameter :: DEFAULT_SEED = 1_8 ! ============================================================================ ! MISCELLANEOUS CONSTANTS diff --git a/src/initialize.F90 b/src/initialize.F90 index 117381328e..21d568c72a 100644 --- a/src/initialize.F90 +++ b/src/initialize.F90 @@ -20,7 +20,7 @@ module initialize use message_passing use mgxs_data, only: read_mgxs, create_macro_xs use output, only: print_version, write_message, print_usage - use random_lcg, only: openmc_set_seed, seed + use random_lcg, only: openmc_set_seed use settings #ifdef _OPENMP use simulation_header, only: n_threads @@ -84,7 +84,7 @@ contains ! Initialize random number generator -- if the user specifies a seed, it ! will be re-initialized later - err = openmc_set_seed(seed) + err = openmc_set_seed(DEFAULT_SEED) ! Read XML input files call read_input_xml() diff --git a/src/random_lcg.C b/src/random_lcg.C index ef49cd13b4..5bdf13d708 100644 --- a/src/random_lcg.C +++ b/src/random_lcg.C @@ -15,11 +15,11 @@ const double prn_norm = pow(2, -63); // 2^-63 // Module constants const int N_STREAMS = 5; -const int STREAM_TRACKING = 0; -const int STREAM_TALLIES = 1; -const int STREAM_SOURCE = 2; -const int STREAM_URR_PTABLE = 3; -const int STREAM_VOLUME = 4; +const int STREAM_TRACKING = 1; +const int STREAM_TALLIES = 2; +const int STREAM_SOURCE = 3; +const int STREAM_URR_PTABLE = 4; +const int STREAM_VOLUME = 5; // Current PRNG state uint64_t prn_seed[N_STREAMS]; // current seed @@ -48,9 +48,9 @@ prn() //============================================================================== extern "C" double -future_prn(uint64_t n) +future_prn(int64_t n) { - return future_seed(n, prn_seed[stream]) * prn_norm; + return future_seed(static_cast(n), prn_seed[stream]) * prn_norm; } //============================================================================== @@ -58,10 +58,10 @@ future_prn(uint64_t n) //============================================================================== extern "C" void -set_particle_seed(uint64_t id) +set_particle_seed(int64_t id) { for (int i = 0; i < N_STREAMS; i++) { - prn_seed[i] = future_seed(id * prn_stride, seed + i); + prn_seed[i] = future_seed(static_cast(id) * prn_stride, seed + i); } } @@ -70,16 +70,16 @@ set_particle_seed(uint64_t id) //============================================================================== extern "C" void -advance_prn_seed(uint64_t n) +advance_prn_seed(int64_t n) { - prn_seed[stream] = future_seed(n, prn_seed[stream]); + prn_seed[stream] = future_seed(static_cast(n), prn_seed[stream]); } //============================================================================== // FUTURE_SEED //============================================================================== -extern "C" uint64_t +uint64_t future_seed(uint64_t n, uint64_t seed) { // Make sure nskip is less than 2^M. @@ -121,7 +121,7 @@ future_seed(uint64_t n, uint64_t seed) extern "C" void prn_set_stream(int i) { - stream = i - 1; + stream = i - 1; // Shift by one to move from Fortran to C indexing. } //============================================================================== @@ -136,7 +136,7 @@ openmc_set_seed(uint64_t new_seed) for (int i = 0; i < N_STREAMS; i++) { prn_seed[i] = seed + i; } - stream = STREAM_TRACKING; + prn_set_stream(STREAM_TRACKING); #pragma end omp parallel return 0; } diff --git a/src/random_lcg.h b/src/random_lcg.h index 889195f109..4c7ec01404 100644 --- a/src/random_lcg.h +++ b/src/random_lcg.h @@ -14,21 +14,21 @@ extern "C" double prn(); // current seed. //============================================================================== -extern "C" double future_prn(uint64_t n); +extern "C" double future_prn(int64_t n); //============================================================================== // SET_PARTICLE_SEED sets the seed to a unique value based on the ID of the // particle. //============================================================================== -extern "C" void set_particle_seed(uint64_t id); +extern "C" void set_particle_seed(int64_t id); //============================================================================== // ADVANCE_PRN_SEED advances the random number seed 'n' times from the current // seed. //============================================================================== -extern "C" void advance_prn_seed(uint64_t n); +extern "C" void advance_prn_seed(int64_t n); //============================================================================== // FUTURE_SEED advances the random number seed 'skip' times. This is usually @@ -37,7 +37,7 @@ extern "C" void advance_prn_seed(uint64_t n); // are used. //============================================================================== -extern "C" uint64_t future_seed(uint64_t n, uint64_t seed); +uint64_t future_seed(uint64_t n, uint64_t seed); //============================================================================== // PRN_SET_STREAM changes the random number stream. If random numbers are needed