Lecture 9 - Parallel Algorithms
Lecture 9 - Parallel Algorithms
Parallel Algorithms
Md Mehrab Hossain Opi
Introduction 2
• Algorithms we have seen so far uses single-processor computer.
• Today we will study algorithms for parallel machines.
• Computers with more than one processors.
processors
1 2 3 p
1 2 3 4 … … … m
Global memory
Shared Memory Model 10
• We assume the input is given in the global memory.
• There is space for storing intermediate results.
• There is chance of access conflict.
• What happens if more than one processor tries to access the same
global memory cell.
• Several variants of PRAM is proposed.
Shared Memory Model 11
• EREW PRAM
• Exclusive Read and Exclusive Write PRAM is the model in which no
concurrent read or write is allowed.
• Processor can access different cells concurrently.
• CREW PRAM
• Concurrent Read and Exclusive Write
• CRCW PRAM
• Concurrent Read and Concurrent Write.
Array 3 -2 4 3 -4 8 -7 9
Sum 3 1 5 8 4 12 5 14
Minimum 3 -2 -2 -2 -4 -4 -7 -7
• This solves to .
• Is it work-optimal?
• No.
Prefix Computation 17
• The total work done by this algorithm is .
• Using sequential algorithm this can be done in .
5 12 8 6 3 9 11 12 1 5 6 7 10 4 3 5
Processor 1 Processor 2 Processor 3 Processor 4
Step 1 (local to processors)
5 17 25 31 3 12 23 35 1 6 12 19 10 14 17 22
Local sums 31 35 19 22
Step 2 (global computation)
31 66 85 10
7
5 17 25 31 3 12 23 35 1 6 12 19 10 14 17 22
Step 3 (update)
5 17 25 31 34 43 54 66 67 72 78 85 95 99 10 10
2 7
Work-Optimal Prefix Computation 20
• Step 1 takes time.
• Step 2 takes time.
• Finally step 3 also takes time.
Merging 21
• The problem of merging is to take two sorted sequence as input and
produce a sorted sequence of all the elements.
• We already know an time algorithm.
• Let’s see how we can use parallel computing.
Parallel Merging 22
• Suppose we have two sorted sequence.
Thank You.