Estimating π with Monte Carlo

First, we will apply our new knowledge of cuRAND to perform an estimate of the well-known mathematical constant π, or Pi, which is, of course, the never-ending irrational number 3.14159265358979...

To get an estimate, though, we need to take a moment to think about what this means. Let's think about a circle. Remember that the radius of a circle is the length from the center of the circle to any point in the circle; usually, this is designated with R. The diameter is defined as D = 2R, and the circumference C is the length around the circle. Pi is then defined as π = C / D . We can use Euclidean geometry to find a formula for the area of the circle, which turns out being A = πR2 . Now, let's think about a circle ...

Get Hands-On GPU Programming with Python and CUDA now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.