Skip to content

Latest commit

 

History

History

simple-pi

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 

Parallel calculation of π

An approximation to the value of π can be calculated from the following expression

img

where the answer becomes more accurate with increasing N. As each term is independent, the summation over i can be parallelized nearly trivially.

Starting from the serial code pi.cpp (or pi.F90 for Fortran), make a version that performs the calculation parallel with two processes.

  1. Divide the range over N in two, so that rank 0 does i=1, 2, ... , N/2 and rank 1 does i=N/2 + 1, N/2 + 2, ... , N.

  2. Both tasks calculate their own partial sums

  3. Once finished with the calculation, rank 1 sends its partial sum to rank 0, which then calculates the final result and prints it out.

  4. Compare the result to the that of the serial calculation, do you get exactly the same result? If not, can you explain why?