diff --git a/common/lib/share/mccode-r.h.in b/common/lib/share/mccode-r.h.in index da0c0e793..a9896d098 100644 --- a/common/lib/share/mccode-r.h.in +++ b/common/lib/share/mccode-r.h.in @@ -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() @@ -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) diff --git a/common/lib/share/mccode_main.c b/common/lib/share/mccode_main.c index d40a112a1..9a9dbd2f8 100644 --- a/common/lib/share/mccode_main.c +++ b/common/lib/share/mccode_main.c @@ -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 diff --git a/mccode/src/cogen.c.in b/mccode/src/cogen.c.in index 053fbc4fa..ecdf96897 100644 --- a/mccode/src/cogen.c.in +++ b/mccode/src/cogen.c.in @@ -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); @@ -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("");