How super computers approximate the value of Pi - Monte Carlo method

in #super8 years ago

Many of us have a misconception that value of Pi is (22/7) but the fact is, being an irrational number Pi can never be expressed as a ratio a/b, where a and b are integers and b is non-zero. (22/7) is generally used as its just a close approximation to the actual value of pi.

Computers try to calculate(approximate) the value of Pi by using some special techniques, the Monte Carlo method is one of them. It is a technique to calculate the value of Pi by using methods of statistics and probability.

This technique works on the fact that if a circle of radius R is inscribed in a square of side 2R, then area of circle = Pi*(R*R) and area of square = (2R)*(2R). Hence the value of Pi = (4*area of circle) / (area of square).

Image

So different threads running on a computer in parallel, start picking random points inside the square and check if that point lies inside the circle too. The computer keeps the track of total number of random points taken (T) and also of the number of points which lie inside the circle (N). Then the value of Pi is approximated as (4*N)/T. This algorithm is slow but easy to run in parallel, so super computers run this algorithm with different threads running in parallel on their different CPU cores, and hence approximate the value of Pi.