Tuesday, 18 April 2017

Estimation of the PI value:

How to do:

Generate N random points in the unit square. Count M, the number of points that are in the quarter circle. Then PI is approximately equal to the ratio 4 * M / N.

First, we will see the implementation of this in serial fashion:

Each time a single processor is generating the random number and it calculates the value of PI using those values.
It takes a large amount of time, because each time in iteration it should generate a random number and calculate the PI value.

You can see the serial implementation of this, here

Now let us parallelize it using MPI:

Each processor uses different random numbers.We should ensure this is to have a single master processor generate all the random numbers, and then divide them up.

You can see the implementation of the above program using MPI, here

With parallelising using MPI, we have got a huge difference in time, this implementation is much faster than the serial code.


By the graph we can clearly see the difference between the time taken for change in number of processors.(Np-number of process)

Experimental Setup:


4-Core Intel I7 @ 3.07GHz 16 GB RAM
Hadoop version - 2.0.3
mpicc version - 2.0.2

How to run?

Follow this link

Why this is faster:


Each processor will calculate the PI value individually, so the speed up increases n times (if we have n processors)

You can see the output of the program here




No comments:

Post a Comment