23
Presented by: Vladimir Aerov Yoed Ginzburg ‘Sieve of Eratosthenes’ Algorithm

Parallelization of ‘Sieve of Eratosthenes ’ Algorithm

  • Upload
    maia

  • View
    121

  • Download
    0

Embed Size (px)

DESCRIPTION

Parallelization of ‘Sieve of Eratosthenes ’ Algorithm. Presented by: Vladimir Aerov Yoed Ginzburg. Background. A prime number (or a prime) is a natural number greater than 1 that has no positive divisors other than 1 and itself. - PowerPoint PPT Presentation

Citation preview

Page 1: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Presented by:

Vladimir AerovYoed Ginzburg

Parallelization of ‘Sieve of Eratosthenes’ Algorithm

Page 2: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

BackgroundA prime number (or a prime) is a natural

number greater than 1 that has no positive divisors other than 1 and itself.

Prime numbers have a central role in number theory: any integer greater than 1 can be expressed as a product of primes that is unique(Also knows as Elucid’s theorem).

As of October 2013, the largest known prime number is  −1, a number with 17,425,170 digits.

Page 3: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

ApplicationsOne of the most important use of prime deals

with encryption. For example, when an email is sent it is often encrypted and then decrypted upon receipt- usually with a function that has a connection to primes.

Naturally, the bigger the prime number used, the harder and longer the decryption process takes.

Another use is in finance, where banks use prime numbers to collect the reminders from different transactions.

Page 4: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Motivation It has been proven that there are an infinite

number of primes, making their future use promising and everlasting.

Finding a new prime number is a difficult process that cannot be done by hand. A super computer is needed because a potential number is divided by every number smaller than it to see if it is in fact prime. This can take days, months, or even years.

Therefore, a fast and efficient method for checking whether a number is prime us needed,

Page 5: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Who Can Help Us?!

Page 6: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Eratosthenes(ehr-uh-TAHS-thuh-neez)

Eratosthenes was the librarian atAlexandria, Egypt in 200 B.C.Also, he was good at mathematics .

Page 7: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Eratosthenes(ehr-uh-TAHS-thuh-neez)

Eratosthenes was a Greek mathematician, astronomer, and geographer.

He invented a method for finding prime numbers that is still used today as a standing ground for many advanced algorithms.

This method is called Sieve of Eratosthenes.

Page 8: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Eratosthenes’ Sieve

A sieve has holes in it and is used to filter out the liquid.

Eratosthenes’s sieve works the same way, only with prime numbers.

Page 9: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

The Sieve of EratosthenesWhile sieve of Eratosthenes is simple to

grasp and somewhat intuitive, it’s a strong algorithm that not only can decide if a number is prime, but find all the primes between it’s limit.

Page 10: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 7071 72 73 74 75 76 77 78 79 8081 82 83 84 85 86 87 88 89 9091 92 93 94 95 96 97 98 99 100

Hundreds Chart

Page 11: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 7071 72 73 74 75 76 77 78 79 8081 82 83 84 85 86 87 88 89 9091 92 93 94 95 96 97 98 99 100

1- Cross out 1 ; it is not a prime

Page 12: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 7071 72 73 74 75 76 77 78 79 8081 82 83 84 85 86 87 88 89 9091 92 93 94 95 96 97 98 99 100

2- Leave 2 ; cross out its multiples

Page 13: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 7071 72 73 74 75 76 77 78 79 8081 82 83 84 85 86 87 88 89 9091 92 93 94 95 96 97 98 99 100

Repeat this for all the rest of the list

Page 14: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

1 2 3 4 5 6 7 8 9 1011 12 13 14 15 16 17 18 19 2021 22 23 24 25 26 27 28 29 3031 32 33 34 35 36 37 38 39 4041 42 43 44 45 46 47 48 49 5051 52 53 54 55 56 57 58 59 6061 62 63 64 65 66 67 68 69 7071 72 73 74 75 76 77 78 79 8081 82 83 84 85 86 87 88 89 9091 92 93 94 95 96 97 98 99 100

Enjoy your new bunch of Primes!

Page 15: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Pseudo - Code

Page 16: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

But it has one little weakness…

Page 17: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

The Computing time rapidly increase with the size of the list

Page 18: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Parallelizing the Algorithm Since there is no correlation between primes, we can

simply divide the list equally between the processes, which make Sieve of Eratosthenes an embarrassingly parallel algorithm.

The algorithm need to be repeated only for the first elements!

Simply use Open MP on a serial implantation!

The Algorithm bottle neck is off course the last check of the whole list in order to determinate the prime numbers.

Page 19: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

The Results

Page 20: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Running time

1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 320

0.2

0.4

0.6

0.8

1

1.2

1.4

Runtime at dif f erent problem size

N umber of threads

Runti

me

1,000100,0001,000,000

Page 21: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Speedup

1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 32

12

4

6

8

10

12

14

16

18

20

22

24

26

28

30

32

Speedups at dif f erent problem size

N umber of threads

Speed

up

Linear Progression1,000100,0001,000,000

Page 22: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

Efficiency

1 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 320

0.05

0.1

0.15

0.2

0.25

0.3

0.35

0.4

0.45

0.5

0.55

0.6

0.65

0.7

0.75

0.8

0.85

0.9

0.95

1Ef f iciency at dif f erent problem size

N umber of threads

Speed

up

Linear Progression1,000100,0001,000,000

Page 23: Parallelization of ‘Sieve  of  Eratosthenes ’  Algorithm

ConclusionParallelizing Sieve of Eratosthenes proved to be

extremely useful, and sticking to Amdahl's law up until the processor limit of the hobbit system.

Taking the test into up to 6,000,000 showed even better result: 18 seconds as a serial process and only 2.3 at 8 processors.

Checking for bigger natural proved to by problematic as the serial program took minutes to run.