11f6643lec12 - The Sieve of Eratosthenes Rajendra V....

Info iconThis preview shows pages 1–4. Sign up to view the full content.

View Full Document Right Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: The Sieve of Eratosthenes Rajendra V. Boppana Slides adapted from M.J. Quinn, Parallel Programming in C with MPI and OpenMP, McGraw Hill, 2004 Outline Sequential algorithm Sources of parallelism Data decomposition options Parallel algorithm development, analysis MPI program enchmarking Benchmarking Optimizations CS6643 F'11 Lec12 2 Prime Numbers A prime number is Greater than 1 Can be divided without a reminder by itself and 1 only 2 is the smallest and only even number prime All numbers that are not prime are called composite numbers CS6643 F'11 Lec12 3 Sieve Algorithm to Find Primes 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 2 3 4 5 6 7 8 9 1 2 3 4 5 6 2 4 6 8 10 12 14 16 18 20 22 24 26 28 30 2 4 6 8 2 4 6 3 9 15 21 27 3 9 5 5 25 5 7 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 32 34 36 38 40 42 44 46 48 50 52 54 56 58 60 33 39 45 51 57 35 55 49 Complexity: ( n lnln n ) Need to do this for each prime n 1/2 CS6643 F'11 Lec12 4 Pseudocode 1. Create list of unmarked natural numbers 2,3,, n 2. k 2 3. Repeat (a) Mark all multiples of k between k 2 and n (b) k smallest unmarked number > k until k 2 > n . The unmarked numbers are primes 4. The unmarked numbers are primes CS6643 F'11 Lec12 5 Sources of Parallelism Checking and marking numbers can be done in parallel Use domain decomposition Divide data into pieces Associate computational steps with data One primitive task per array element Agglomerate primitive tasks to get a more practical task-channel graph Communication is given in step 3b of pseudo code CS6643 F'11 Lec12 6 Making 3(a) Parallel Mark all multiples of k between k 2 and n for all j = k 2 j n with increment k do mark j // composite number Endfor Divide the numbers into approximately p equal parts Each task marks composites in its part CS6643 F'11 Lec12 7 Making 3(b) Parallel Find smallest unmarked number > k among the p processes all-reduce Min-reduction (to find smallest unmarked number > k ) + Broadcast (to indicate this number to all tasks) CS6643 F'11 Lec12 8 Agglomeration Goals Consolidate tasks Reduce communication cost Balance computations among processes CS6643 F'11 Lec12 9 Data Decomposition Options Interleaved (cyclic) Easy to determine owner of each index Leads to load imbalance for this problem Block Balances loads More complicated to determine owner if n not a multiple of p CS6643 F'11 Lec12 10 Block Decomposition Options Want to balance workload when n not a multiple of p Each process gets either n...
View Full Document

Page1 / 10

11f6643lec12 - The Sieve of Eratosthenes Rajendra V....

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online