I'm trying to find the most efficient way to generate random numbers for a MC simulation I'm working on. I've been reading a lot about the double precision Mersenne Twister algorithm and I wanted to understand a couple of basic things before moving on.
I compiled and run the test provided by the official dSFMT files and this the best result for my system:
C:\TDM-GCC-64\C++ Tests\dSFMT>test-sse2-M19937 -s
consumed time for generating 100000000 randoms.
ST BLOCK [0, 1) AVE: 115ms.
ST BLOCK (0, 1] AVE: 108ms.
ST BLOCK (0, 1) AVE: 106ms.
ST BLOCK [1, 2) AVE: 77ms.
ST SEQ [0, 1) 1 AVE: 174ms.
ST SEQ [0, 1) 2 AVE: 207ms.
total = 500014655.815776
ST SEQ (0, 1] 1 AVE: 173ms.
ST SEQ (0, 1] 2 AVE: 205ms.
total = 500035344.184224
ST SEQ (0, 1) 1 AVE: 209ms.
ST SEQ (0, 1) 2 AVE: 247ms.
total = 500014655.815776
ST SEQ [1, 2) 1 AVE: 173ms.
ST SEQ [1, 2) 2 AVE: 204ms.
total = 1500064655.815183
My questions are:
- Why is generating [1,2) faster than [0,1)?
- Why block generation is faster than sequential? Shouldn't allocating a big array and having to delete and rewrite on it be slower?
- If I need to generate 1e12 numbers, what would be the best strategy? If doing it in blocks, what's the optimal array size?