removed extern C identifiers from random_lcg functions

This commit is contained in:
John Tramm 2019-12-04 17:01:35 +00:00
parent 638172e68d
commit 28edfc5021
2 changed files with 23 additions and 39 deletions

View file

@ -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

View file

@ -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<uint64_t>(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<uint64_t>(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<uint64_t>(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<uint64_t>(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;
}