Mersenne Twister Thread Safe

Hi,

Our Monte Carlo code has been using Mersenne Twister for several years now. Thank you! I am currently in the process of modifying our C# code to run in parallel across several CPUs (currently I have changed our “for” loop to a “Parallel.For” loop). I see that Mersenne Twister has a “thread safe” option. I am interested in learning about what this means in terms of the random number sequence. Ideally we would like the same results to occur (given the same seed) if one or multiple CPUs are invoked. Will “thread safe” do this for us?

Thanks for any advice or suggestions you might have to offer.
Best regards,
Carole

Hi Carole

Mersenne Twister and also all the other pseudo random sources are thread safe by default (unless you change something with Control). The option is there to be able to actively disable thread-safety if you know you’ll only ever call it from a single thread, to skip the locking overhead.

With thread safety enabled, a single instance of Mersenne Twister produces the same random number sequence no matter whether called in a single or multiple threads.

However, this is only true per instance. Static members like MersenneTwister.Default will typically return separate instances for each thread, each with their own sequences (so they should not be mixed back together if good randomness properties are required).

Thanks,
Christoph

Hi Christoph,
Thank you very much for your reply. I understand now that I cannot use the MT as is for parallel Monte Carlo. I found an article by Matsumoto describing his algorithm for parallel processing:
http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/DC/dgene.pdf
and corresponding code written in C found on same website.
My current plan is to port that code to C#. Do you think Math.NET Numerics has any plans for this?
Best regards,
Carole