Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions common/lib/share/mccode-r.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,9 @@ void mcdis_sphere(double x, double y, double z, double r);

#if RNG_ALG == _RNG_ALG_MT // MT (currently not functional for GPU)
# define MC_RAND_MAX ((uint32_t)0xffffffffUL)
# define RANDSTATE_LEN 1
# ifndef RANDSTATE_LEN
# define RANDSTATE_LEN 1
# endif
# define srandom(seed) mt_srandom_empty()
# define random() mt_random()
# define _random() mt_random()
Expand All @@ -628,7 +630,9 @@ void mcdis_sphere(double x, double y, double z, double r);
# define UINT64_MAX ((uint64_t)0xffffffffffffffffULL)
# endif
# define MC_RAND_MAX UINT64_MAX
# define RANDSTATE_LEN 7
# ifndef RANDSTATE_LEN
# define RANDSTATE_LEN 7
# endif
# define srandom(seed) kiss_srandom(_particle->randstate, seed)
# define random() kiss_random(_particle->randstate)
# define _random() kiss_random(state)
Expand Down
2 changes: 1 addition & 1 deletion common/lib/share/mccode_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ int mccode_main(int argc, char *argv[])
#endif

// MT specific init, note that per-ray init is empty
#if RNG_ALG == 2
#if RNG_ALG == 1
mt_srandom(mcseed);
#endif

Expand Down
11 changes: 9 additions & 2 deletions mccode/src/cogen.c.in
Original file line number Diff line number Diff line change
Expand Up @@ -1863,9 +1863,14 @@ int cogen_raytrace(struct instr_def *instr)
"Split_%s_counter< SplitS_%s; "
"Split_%s_counter++) {",
comp->name, comp->name, comp->name, comp->name);
coutf(" randstate_t randbackup = *_particle->randstate;");
coutf(" randstate_t randbackup[RANDSTATE_LEN];");
coutf(" for (int Split_%s_randstate_idx = 0; Split_%s_randstate_idx < RANDSTATE_LEN; Split_%s_randstate_idx++) {", comp->name, comp->name, comp->name);
coutf(" randbackup[Split_%s_randstate_idx] = _particle->randstate[Split_%s_randstate_idx];", comp->name, comp->name);
coutf(" }");
coutf(" *_particle=Split_%s_particle;", comp->name); // restore particle for SPLIT loop
coutf(" *_particle->randstate = randbackup;");
coutf(" for (int Split_%s_randstate_idx = 0; Split_%s_randstate_idx < RANDSTATE_LEN; Split_%s_randstate_idx++) {", comp->name, comp->name, comp->name);
coutf(" _particle->randstate[Split_%s_randstate_idx] = randbackup[Split_%s_randstate_idx];", comp->name, comp->name);
coutf(" }");
// Experimentally taking out the following line of code following discussions with Milan Klausz:
// It seems that especially for the _uid=0 particle we get strange repetitions in the rng.
// coutf(" srandom(_hash(_particle->_uid* %lu *(1+Split_%s_counter)));", comp->index, comp->name);
Expand Down Expand Up @@ -2423,8 +2428,10 @@ cogen_header(struct instr_def *instr, char *output_name)
cout("#endif");
cout("#if RNG_ALG == _RNG_ALG_MT // MT ");
cout("#define randstate_t uint32_t");
cout("#define RANDSTATE_LEN 1");
cout("#elif RNG_ALG == _RNG_ALG_KISS // KISS");
cout("#define randstate_t uint64_t");
cout("#define RANDSTATE_LEN 7");
cout("#endif");
cout("");

Expand Down
Loading