From 28edfc50213cc0a812e8d8564b49eb4cc3bc9f08 Mon Sep 17 00:00:00 2001 From: John Tramm Date: Wed, 4 Dec 2019 17:01:35 +0000 Subject: [PATCH] removed extern C identifiers from random_lcg functions --- include/openmc/random_lcg.h | 30 +++++++++++++++--------------- src/random_lcg.cpp | 32 ++++++++------------------------ 2 files changed, 23 insertions(+), 39 deletions(-) diff --git a/include/openmc/random_lcg.h b/include/openmc/random_lcg.h index 53cb39f1e..518dedb45 100644 --- a/include/openmc/random_lcg.h +++ b/include/openmc/random_lcg.h @@ -10,14 +10,14 @@ namespace openmc { // Module constants. //============================================================================== -constexpr int N_STREAMS = 6; -extern "C" const int STREAM_TRACKING; -extern "C" const int STREAM_TALLIES; -extern "C" const int STREAM_SOURCE; -extern "C" const int STREAM_URR_PTABLE; -extern "C" const int STREAM_VOLUME; -extern "C" const int STREAM_PHOTON; -constexpr int64_t DEFAULT_SEED = 1; +constexpr int N_STREAMS {6}; +constexpr int STREAM_TRACKING {0}; +constexpr int STREAM_TALLIES {1}; +constexpr int STREAM_SOURCE {2}; +constexpr int STREAM_URR_PTABLE {3}; +constexpr int STREAM_VOLUME {4}; +constexpr int STREAM_PHOTON {5}; +constexpr int64_t DEFAULT_SEED {1}; //============================================================================== //! Generate a pseudo-random number using a linear congruential generator. @@ -25,7 +25,7 @@ constexpr int64_t DEFAULT_SEED = 1; //! @return A random number between 0 and 1 //============================================================================== -extern "C" double prn(uint64_t* prn_seed); +double prn(uint64_t* prn_seed); //============================================================================== //! Generate a random number which is 'n' times ahead from the current seed. @@ -38,7 +38,7 @@ extern "C" double prn(uint64_t* prn_seed); //! @return A random number between 0 and 1 //============================================================================== -extern "C" double future_prn(int64_t n, uint64_t prn_seed); +double future_prn(int64_t n, uint64_t prn_seed); //============================================================================== //! Set a RNG seed to a unique value based on a unique particle ID by striding @@ -47,7 +47,7 @@ extern "C" double future_prn(int64_t n, uint64_t prn_seed); //! @param id The particle ID //============================================================================== -extern "C" void init_seed(int64_t id, uint64_t* prn_seeds, int offset ); +void init_seed(int64_t id, uint64_t* prn_seeds, int offset ); //============================================================================== //! Set the RNG seeds to unique values based on the ID of the particle. This @@ -57,7 +57,7 @@ extern "C" void init_seed(int64_t id, uint64_t* prn_seeds, int offset ); //! @param id The particle ID //============================================================================== -extern "C" void init_particle_seeds(int64_t id, uint64_t* prn_seeds ); +void init_particle_seeds(int64_t id, uint64_t* prn_seeds ); //============================================================================== //! Advance the random number seed 'n' times from the current seed. This @@ -67,7 +67,7 @@ extern "C" void init_particle_seeds(int64_t id, uint64_t* prn_seeds ); //! @param n The number of RNG seeds to skip ahead by //============================================================================== -extern "C" void advance_prn_seed(int64_t n, uint64_t* prn_seed); +void advance_prn_seed(int64_t n, uint64_t* prn_seed); //============================================================================== //! Advance a random number seed 'n' times. @@ -89,7 +89,7 @@ uint64_t future_seed(uint64_t n, uint64_t prn_seed); //! Get OpenMC's master seed. //============================================================================== -extern "C" int64_t openmc_get_seed(); +int64_t openmc_get_seed(); //============================================================================== //! Set OpenMC's master seed. @@ -97,7 +97,7 @@ extern "C" int64_t openmc_get_seed(); //! one. //============================================================================== -extern "C" void openmc_set_seed(int64_t new_seed); +void openmc_set_seed(int64_t new_seed); } // namespace openmc #endif // OPENMC_RANDOM_LCG_H diff --git a/src/random_lcg.cpp b/src/random_lcg.cpp index 2b5f66d59..4ce80a1fc 100644 --- a/src/random_lcg.cpp +++ b/src/random_lcg.cpp @@ -5,15 +5,6 @@ namespace openmc { - -// Constants -extern "C" const int STREAM_TRACKING {0}; -extern "C" const int STREAM_TALLIES {1}; -extern "C" const int STREAM_SOURCE {2}; -extern "C" const int STREAM_URR_PTABLE {3}; -extern "C" const int STREAM_VOLUME {4}; -extern "C" const int STREAM_PHOTON {5}; - // Starting seed int64_t master_seed {1}; @@ -31,8 +22,7 @@ constexpr double prn_norm {1.0 / prn_mod}; // 2^-63 // PRN //============================================================================== -extern "C" double -prn(uint64_t* prn_seed) +double prn(uint64_t* prn_seed) { // This algorithm uses bit-masking to find the next integer(8) value to be // used to calculate the random number. @@ -47,8 +37,7 @@ prn(uint64_t* prn_seed) // FUTURE_PRN //============================================================================== -extern "C" double -future_prn(int64_t n, uint64_t prn_seed) +double future_prn(int64_t n, uint64_t prn_seed) { return future_seed(static_cast(n), prn_seed) * prn_norm; } @@ -57,8 +46,7 @@ future_prn(int64_t n, uint64_t prn_seed) // SET_SEED //============================================================================== -extern "C" void -init_seed(int64_t id, uint64_t* prn_seed, int offset) +void init_seed(int64_t id, uint64_t* prn_seed, int offset) { *prn_seed = future_seed(static_cast(id) * prn_stride, master_seed + offset); } @@ -67,8 +55,7 @@ init_seed(int64_t id, uint64_t* prn_seed, int offset) // SET_PARTICLE_SEEDS //============================================================================== -extern "C" void -init_particle_seeds(int64_t id, uint64_t* prn_seeds) +void init_particle_seeds(int64_t id, uint64_t* prn_seeds) { for (int i = 0; i < N_STREAMS; i++) { prn_seeds[i] = future_seed(static_cast(id) * prn_stride, master_seed + i); @@ -79,8 +66,7 @@ init_particle_seeds(int64_t id, uint64_t* prn_seeds) // ADVANCE_PRN_SEED //============================================================================== -extern "C" void -advance_prn_seed(int64_t n, uint64_t* prn_seed) +void advance_prn_seed(int64_t n, uint64_t* prn_seed) { *prn_seed = future_seed(static_cast(n), *prn_seed); } @@ -89,8 +75,7 @@ advance_prn_seed(int64_t n, uint64_t* prn_seed) // FUTURE_SEED //============================================================================== -uint64_t -future_seed(uint64_t n, uint64_t prn_seed) +uint64_t future_seed(uint64_t n, uint64_t prn_seed) { // Make sure nskip is less than 2^M. n &= prn_mask; @@ -128,10 +113,9 @@ future_seed(uint64_t n, uint64_t prn_seed) // API FUNCTIONS //============================================================================== -extern "C" int64_t openmc_get_seed() {return master_seed;} +int64_t openmc_get_seed() {return master_seed;} -extern "C" void -openmc_set_seed(int64_t new_seed) +void openmc_set_seed(int64_t new_seed) { master_seed = new_seed; }