0

I'm trying to speed up my C++ Monte Carlo simulation but I am a bit puzzled. My outer-loop is over the number of paths and my idea was to vectorize it (adding #pragma simd?). However, I've read the following:

  1. The moral of this question was to initialize the random number generator outside the loop.
  2. Many documents only praise how vectorization can improve significantly when paths are vectorized.

How can these two facts coexist in a low memory environment? (ie. without generating and storing all the random numbers before the loop)

foreignvol
  • 681
  • 2
  • 7
  • 15
  • This question does not make sense. Initializing pseudorandom number generators can be quite expensive but it is fine to do it only once per program run. It has nothing to do with generating random numbers since that is usually quick. – Öö Tiib Apr 08 '20 at 01:16
  • But doesn't the rng change once it generates a number? Something has to or it will always generate the same number or am I missing something? – foreignvol Apr 08 '20 at 01:22
  • Huh? PRNG is meant to generate very long sequence of seemingly random numbers. Mersenne Twister for example is called MT19937 because the sequence is 2 in 19937 - 1 numbers long before it starts to repeat itself. Initialization is for to set from where in that sequence it starts. – Öö Tiib Apr 08 '20 at 05:53
  • Your linked example did use random device to initialize default random engine for each number, that was its inefficiency. – Öö Tiib Apr 08 '20 at 05:59

0 Answers0