Commit 2924b0ba authored by Loic Hausammann's avatar Loic Hausammann Committed by Matthieu Schaller
Browse files

Random: add seed parameter

parent 1ac9f228
......@@ -1052,6 +1052,16 @@ fi
AC_SUBST([TBBMALLOC_LIBS])
AM_CONDITIONAL([HAVETBBMALLOC],[test -n "$TBBMALLOC_LIBS"])
# check for a random seed
AC_ARG_WITH([random-seed],
[AS_HELP_STRING([--with-random-seed=SHORT INT],
[Set the random seed.]
)],
[with_random_seed="$withval"],
[with_random_seed="0"]
)
AC_DEFINE_UNQUOTED([SWIFT_RANDOM_SEED_XOR], [$with_random_seed],[Value of the random seed.]),
# Check for python.
have_python="no"
AC_ARG_WITH([python],
......
......@@ -29,6 +29,11 @@ argument called the type of random number which is basically the nth random
number for the specified seed, which is added to the particle ID, thus providing
a distinct state per random number type.
If the user wishes to run a simulation with a different set of random number,
an option during the configuration (``--with-random-seed=INT``) is available.
This option simply flip some bits in the initial number composed of the ID and the
current simulation time through the binary operator XOR.
Implementation
~~~~~~~~~~~~~~
......
......@@ -455,6 +455,7 @@ void io_write_code_description(hid_t h_file) {
#else
io_write_attribute_s(h_grpcode, "MPI library", "Non-MPI version of SWIFT");
#endif
io_write_attribute_i(h_grpcode, "RandomSeed", SWIFT_RANDOM_SEED_XOR);
H5Gclose(h_grpcode);
}
......
......@@ -140,6 +140,7 @@ INLINE static double inl_erand48(uint16_t xsubi[3]) { return erand48(xsubi); }
INLINE static double random_unit_interval(int64_t id,
const integertime_t ti_current,
const enum random_number_type type) {
/* Start by packing the state into a sequence of 16-bit seeds for rand_r. */
uint16_t buff[9];
id += type;
......@@ -151,6 +152,9 @@ INLINE static double random_unit_interval(int64_t id,
value to get 18 bytes of state. */
buff[8] = 6178;
/* Use the random seed to generate a new random number */
buff[0] = buff[0] ^ (uint16_t)SWIFT_RANDOM_SEED_XOR;
/* Shuffle the buffer values, this will be our source of entropy for
the erand48 generator. */
uint32_t seed16 = 0;
......
......@@ -100,6 +100,9 @@ int main(int argc, char* argv[]) {
message("Seed = %d", seed);
srand(seed);
/* Log the swift random seed */
message("SWIFT random seed = %d", SWIFT_RANDOM_SEED_XOR);
/* Time-step size */
const int time_bin = 30;
......
......@@ -49,6 +49,9 @@ int main(int argc, char* argv[]) {
message("Seed = %d", seed);
srand(seed);
/* Log the swift random seed */
message("SWIFT random seed = %d", SWIFT_RANDOM_SEED_XOR);
/* Time-step size */
const int time_bin = 30;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment