QuoteYou want a single random engine accessed by multiple threadsIdeally, yesQuoteYour worried about each thread with its own local random engine objects somehow having static shared memory that isn't thread safe?Yes, I am worried that C++11 Random is not really thread-safe.QuoteThink or random engines as containers: you can't have multiple threads inserting into a global std::vector without locking, but there is no problem in having a local std::vector in each thread. Like some thread-local storage?I was thinking of creating *several* rngs and initializing each one with std::seed_seq. But Normally NP (population) >> number of threads.Here's the example I have in my head (evolution algorithm, DE). Consider NP vectors each of size D. We index the vectors by i = 1,..., NP. So, we mutate each vector in sone way but essentially we need to generate three random indexes Unif[1,D] r1,r2, r3 that are not the same as each other and none of them equal to i (we need a loop to generate them until true). All other data is shared read only, so the only non-deterministic behavior lies in the generation of these random indices.// Since DE is all about randomness, is the odd race condition a disaster in this case?
Last edited by Cuchulainn
on January 27th, 2015, 11:00 pm, edited 1 time in total.