You are on page 1of 10

DD2356 – Calculate PI with MPI

Stefano Markidis
Calculate PI with MPI Non-Blocking
We use a basic MC algorithm is based on the following steps:
• Draw a unit square
• Draw a unit circle inside the unit square
• Throw a coin in the unit square
• Count the rate of success where the coin ends up in the unit
circle: P(coin in the circle)
– P(coin in the circle) = area of the circle / area of the
square = π r^2 / (2 r)^2 = π r^2 / 4 r^2 = π / 4
– à π = 4 P( coin in the circle)

2
Serial Code

3
Parallelization With MPI Non-Blocking Point-to-Point
• Each MPI process calculate parts of iterations =
NUM_ITER / num_ranks
• Every process except process 0 sends its own Linear reduction
count to process 0 algorithm
• Process 0 receives from all the other processes Because it uses a
and accumulates the counts number of
messages that is
O(p) where p is the
number of
processes

4
MPI Code - Initialization

Number of trials = 2 24

Important: each MPI


process gets a different
list of pseudo-random
Each process numbers
takes only part of all samples 5
Computation
MPI Code
Compute
&
Communication

6
MPI Code - Finalization

7
1. Scaling Test – Strong Scaling
• (Global) Problem size
is fixed, and we
change the number of
processes
• We expect that
increasing the number
of processes the
execution time
decreases

8
2. Scaling Test – Weak Scaling
• The problem size per
process is fixed, and we
change the number of
processes
• We expect that increasing
the number of processes
the execution time increases
– More
communication

9
Optimization – Overlap Communication & Computation

Start Comm.

Computation

Ensure comm.
Is completed

10

You might also like