@@ -99,7 +99,25 @@ extern Eidos_RNG_State gEidos_RNG_SINGLE;
9999extern std::vector<Eidos_RNG_State *> gEidos_RNG_PERTHREAD ;
100100#endif
101101
102- // Calls to the GSL should use these macros to get the RNG state they need, whether single- or multi-threaded.
102+ #if DEBUG
103+ // This global flag is a bit of a hack. It's a way for Eidos client code to detect when the random number
104+ // generator has been used by the Eidos interpreter, which might be of interest. SLiM uses this to disable
105+ // some checks that are invalid if the Eidos code executed is stochastic. This is NOT thread-safe, in the
106+ // sense that if different threads are try to use this facility simultaneously it will not work. It is
107+ // also just hacky enough that it probably shouldn't be used in production code, so it is DEBUG only.
108+ // The flag is set whenever one of the RNG accessors below is called.
109+ extern bool gEidos_RNG_usageFlag ;
110+
111+ inline __attribute__ ((always_inline)) void EIDOS_RNG_PING_RESET(void ) { gEidos_RNG_usageFlag = false ; }
112+ inline __attribute__ ((always_inline)) void EIDOS_RNG_PING(void ) { gEidos_RNG_usageFlag = true ; }
113+ inline __attribute__ ((always_inline)) bool EIDOS_RNG_PING_IS_SET(void ) { return gEidos_RNG_usageFlag ; }
114+ #else
115+ inline __attribute__ ((always_inline)) void EIDOS_RNG_PING_RESET(void ) { }
116+ inline __attribute__ ((always_inline)) void EIDOS_RNG_PING(void ) { }
117+ inline __attribute__ ((always_inline)) bool EIDOS_RNG_PING_IS_SET(void ) { return false ; }
118+ #endif
119+
120+ // Calls to the GSL should use these functions to get the RNG state they need, whether single- or multi-threaded.
103121// BCH 11/5/2022: The thread number must now be supplied. It will be zero when single-threaded, and so is
104122// ignored. Since this is now a bit more heavyweight, the RNG for a thread should be obtained outside of any
105123// core loops. The most important thing is that when there is a parallel region, the RNG is obtained INSIDE
@@ -111,15 +129,15 @@ extern std::vector<Eidos_RNG_State *> gEidos_RNG_PERTHREAD;
111129// Eidos_RNG_State *rng_state = EIDOS_STATE_RNG(omp_get_thread_num());
112130//
113131#ifndef _OPENMP
114- # define EIDOS_GSL_RNG (threadnum ) ( &gEidos_RNG_SINGLE .gsl_rng_)
115- # define EIDOS_32BIT_RNG (threadnum ) ( gEidos_RNG_SINGLE .pcg32_rng_)
116- # define EIDOS_64BIT_RNG (threadnum ) ( gEidos_RNG_SINGLE .pcg64_rng_)
117- # define EIDOS_STATE_RNG (threadnum ) ( &gEidos_RNG_SINGLE )
132+ inline __attribute__ ((always_inline)) gsl_rng * EIDOS_GSL_RNG(int threadnum) { EIDOS_RNG_PING (); return &gEidos_RNG_SINGLE .gsl_rng_ ; }
133+ inline __attribute__ ((always_inline)) EidosRNG_32_bit & EIDOS_32BIT_RNG(int threadnum) { EIDOS_RNG_PING (); return gEidos_RNG_SINGLE .pcg32_rng_ ; }
134+ inline __attribute__ ((always_inline)) EidosRNG_64_bit & EIDOS_64BIT_RNG(int threadnum) { EIDOS_RNG_PING (); return gEidos_RNG_SINGLE .pcg64_rng_ ; }
135+ inline __attribute__ ((always_inline)) Eidos_RNG_State * EIDOS_STATE_RNG(int threadnum) { EIDOS_RNG_PING (); return &gEidos_RNG_SINGLE ; }
118136#else
119- # define EIDOS_GSL_RNG (threadnum ) ( &gEidos_RNG_PERTHREAD [threadnum]->gsl_rng_)
120- # define EIDOS_32BIT_RNG (threadnum ) ( gEidos_RNG_PERTHREAD [threadnum]->pcg32_rng_)
121- # define EIDOS_64BIT_RNG (threadnum ) ( gEidos_RNG_PERTHREAD [threadnum]->pcg64_rng_)
122- # define EIDOS_STATE_RNG (threadnum ) ( gEidos_RNG_PERTHREAD [threadnum])
137+ inline __attribute__ ((always_inline)) gsl_rng * EIDOS_GSL_RNG(int threadnum) { EIDOS_RNG_PING (); return &gEidos_RNG_PERTHREAD [threadnum]->gsl_rng_ ; }
138+ inline __attribute__ ((always_inline)) EidosRNG_32_bit & EIDOS_32BIT_RNG(int threadnum) { EIDOS_RNG_PING (); return gEidos_RNG_PERTHREAD [threadnum]->pcg32_rng_ ; }
139+ inline __attribute__ ((always_inline)) EidosRNG_64_bit & EIDOS_64BIT_RNG(int threadnum) { EIDOS_RNG_PING (); return gEidos_RNG_PERTHREAD [threadnum]->pcg64_rng_ ; }
140+ inline __attribute__ ((always_inline)) Eidos_RNG_State * EIDOS_STATE_RNG(int threadnum) { EIDOS_RNG_PING (); return & gEidos_RNG_PERTHREAD [threadnum]; }
123141#endif
124142
125143#if DEBUG
0 commit comments