9 lines
849 B
HTML
9 lines
849 B
HTML
<p>In this problem we aim to approximate π using the <a href="https://en.wikipedia.org/wiki/Monte_Carlo_method">Monte Carlo method</a>.</p>
|
|
|
|
<p>Modify the code to run the calculation in parallel.</p>
|
|
<p>An interesting issue arises when we try to have reproducible computation.
|
|
Simply using a <a href="https://en.wikipedia.org/wiki/Pseudorandom_number_generator">seeded pseudo random generator</a>, while accessing it from multiple threads (in a different order each time) defeats the purpose as our computations are still non-deterministic.
|
|
Instead we use a different generator state in each thread
|
|
We use the <a href="http://linux.die.net/man/3/erand48">erand48</a> function to explicitly pass the generators state in each call.
|
|
To ensure different random values for each thread they also need to be seeded with the thread number.</p>
|