Professional Documents
Culture Documents
of
Eratosthenes
by
Fola Olagbemi
Outline
• What is the sieve of Eratosthenes?
• Algorithm used
• Parallelizing the algorithm
• Data decomposition options for the parallel
algorithm
• Block decomposition (to minimize inter-
process communication)
• The program (returns count of primes)
• References
What is the sieve of Eratosthenes?
• An algorithm designed by the Greek
mathematician Eratosthenes: used to find
the prime numbers between two and
another specified number.
• It works by gradually eliminating
multiples of the smallest unmarked
number (x) in the given interval, till > the
specified number.
Algorithm
1. Create a list of natural numbers in the specified
range e.g. 2, 3, 4, ….. , n, none of which is marked
2. Set k to 2 (or smallest number in list) where k is
the smallest unmarked number in the list
3. Repeat
1. Mark all multiples of k between square of k and n
2. Find smallest number greater than k that is
unmarked. Set k to the new value, until > n
4. The unmarked numbers are prime.
Parallelizing the algorithm
• Step 3a – key parallel computation step
• Reduction needed in each iteration to
determine new value of k (process 0 –
controller - may not have the next k)
• Broadcast needed after reduction to inform all
processes of new k.
• The goal in parallelizing is to reduce inter-
process communication as much as possible.
Data decomposition options
• Goal of data decomposition approach chosen
– each process should have roughly the same
number of values to work on (optimal load
balancing)
• Decomposition options:
– Interleaved data decomposition
– Block data decomposition:
• Grouped
• Distributed
Data decomposition options (contd.)
• Interleaved data decomposition (e.g.):
– Process 0 processes numbers 2, 2+p, 2+2p, …
– Process 1 processes numbers 3, 3+p, 3+2p, …
• Advantage
– easy to know which process is working on the value in any array
index i
• Disadvantages
– It can lead to significant load imbalance among processes
(depending on how array elements are divided up among processes)
– May require a significant amount of reduction/broadcast
(communication overheads)
Data decomposition options (contd.)