Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00...

55
Concurrent Systems Parallelism

Transcript of Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00...

Page 1: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Concurrent Systems Parallelism

Page 2: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Final Exam Schedule

• CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M.

• Exam Scheduled for 8:00 Friday May 5, 2000• Physics L1

Page 3: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Final Exam Schedule

• CS1311 Sections E/F Tuesday/Thursday 2:00 P.M.

• Exam Scheduled for 2:50 Wednesday May 3, 2000• Physics L1

Page 4: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Concurrent Systems

Page 5: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Sequential Processing

• All of the algorithms we’ve seen so far are sequential:– They have one “thread” of execution– One step follows another in sequence– One processor is all that is needed to

run the algorithm

Page 6: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

A Non-sequential Example

• Consider a house with a burglar alarm system.• The system continually monitors:

– The front door– The back door– The sliding glass door– The door to the deck– The kitchen windows– The living room windows– The bedroom windows

• The burglar alarm is watching all of these “at once” (at the same time).

Page 7: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Another Non-sequential Example

• Your car has an onboard digital dashboard that simultaneously:– Calculates how fast you’re going and

displays it on the speedometer– Checks your oil level– Checks your fuel level and calculates

consumption– Monitors the heat of the engine and

turns on a light if it is too hot– Monitors your alternator to make sure it

is charging your battery

Page 8: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Concurrent Systems

• A system in which:– Multiple tasks can be executed at

the same time– The tasks may be duplicates of

each other, or distinct tasks– The overall time to perform the

series of tasks is reduced

Page 9: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Advantages of Concurrency

• Concurrent processes can reduce duplication in code.

• The overall runtime of the algorithm can be significantly reduced.

• More real-world problems can be solved than with sequential algorithms alone.

• Redundancy can make systems more reliable.

Page 10: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Disadvantages of Concurrency

• Runtime is not always reduced, so careful planning is required

• Concurrent algorithms can be more complex than sequential algorithms

• Shared data can be corrupted• Communications between tasks is

needed

Page 11: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Achieving Concurrency

CPU 1 CPU 2

Memory

bus

• Many computers today have more than one processor (multiprocessor machines)

Page 12: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Achieving Concurrency

CPU

task 1task 2

task 3ZZZZ

ZZZZ

• Concurrency can also be achieved on a computer with only one processor:– The computer “juggles” jobs, swapping its

attention to each in turn– “Time slicing” allows many users to get CPU

resources– Tasks may be suspended while they wait for

something, such as device I/O

Page 13: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Concurrency vs. Parallelism

• Concurrency is the execution of multiple tasks at the same time, regardless of the number of processors.

• Parallelism is the execution of multiple processors on the same task.

Page 14: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Types of Concurrent Systems

• Multiprogramming• Multiprocessing• Multitasking• Distributed Systems

Page 15: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multiprogramming

• Share a single CPU among many users or tasks.

• May have a time-shared algorithm or a priority algorithm for determining which task to run next

• Give the illusion of simultaneous processing through rapid swapping of tasks (interleaving).

Page 16: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

MultiprogrammingMemoryUser 1User 2

CPU

User1 User2

Page 17: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multiprogramming

1

2

3

4

1 2 3 4CPU’s

Tasks/Users

Page 18: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multiprocessing

• Executes multiple tasks at the same time

• Uses multiple processors to accomplish the tasks

• Each processor may also timeshare among several tasks

• Has a shared memory that is used by all the tasks

Page 19: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

MultiprocessingMemoryUser 1: Task1User 1: Task2User 2: Task1

CPU

User1 User2

CPU CPU

Page 20: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multiprocessing

1

2

3

4

1 2 3 4CPU’s

Tasks/Users

SharedMemory

Page 21: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multitasking

• A single user can have multiple tasks running at the same time.

• Can be done with one or more processors.

• Used to be rare and for only expensive multiprocessing systems, but now most modern operating systems can do it.

Page 22: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

MultitaskingMemoryUser 1: Task1User 1: Task2User 1: Task3

CPU

User1

Page 23: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Multitasking

1

2

3

4

1 2 3 4CPU’s

Tasks Single User

Page 24: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Distributed Systems

CentralBank

ATM Buford ATM Perimeter

ATM Student CtrATM North Ave

Multiple computers working together with no central program “in charge.”

Page 25: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Distributed Systems

• Advantages:– No bottlenecks from sharing processors– No central point of failure– Processing can be localized for efficiency

• Disadvantages:– Complexity– Communication overhead– Distributed control

Page 26: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Questions?

Page 27: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Questions?

Page 28: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallelism

Page 29: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallelism

• Using multiple processors to solve a single task.

• Involves:– Breaking the task into meaningful

pieces– Doing the work on many

processors– Coordinating and putting the

pieces back together.

Page 30: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallelism

CPU

Memory

NetworkInterface

Page 31: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallelism

1

2

3

4

1 2 3 4CPU’s

Tasks

Page 32: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Pipeline Processing

Repeating a sequence of operations or pieces of a task.

Allocating each piece to a separate processor and chaining them together produces a pipeline, completing tasks faster.

A B C Dinput output

Page 33: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Example

• Suppose you have a choice between a washer and a dryer each having a 30 minutes cycle or

• A washer/dryer with a one hour cycle

• The correct answer depends on how much work you have to do.

Page 34: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

One Load

wash dry

combo

TransferOverhead

Page 35: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Three Loads

wash dry

combo

wash

wash

dry

dry

combocombo

Page 36: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Examples of Pipelined Tasks

• Automobile manufacturing• Instruction processing within a computer

1 5432

1 2 3 4 5

1 2 3 4 5

1 2 3 4 5

A

B

C

D1 2 3 4 5 6 70

time

Page 37: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Task Queues

P1 P2 P3 Pn

Super Task Queue

• A supervisor processor maintains a queue of tasks to be performed in shared memory.

• Each processor queries the queue, dequeues the next task and performs it.

• Task execution may involve adding more tasks to the task queue.

Page 38: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallelizing Algorithms

How much gain can we get from parallelizing an algorithm?

Page 39: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Parallel Bubblesort

93 87 74 65 57 45 33 27

9387 7465 5745 3327

9387 7465 5745 3327

We can use N/2 processors to do all the comparisons at once, “flopping” the pair-wise comparisons.

Page 40: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Runtime of Parallel Bubblesort

9387 7465 5745 33273

9387 7465 5745 33274

9387 7465 5745 33275

9387 7465 5745 33276

9387 7465 5745 33277

93877465574533278

Page 41: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Completion Time of Bubblesort

• Sequential bubblesort finishes in N2 time.• Parallel bubblesort finishes in N time.

Bubble Sort

parallel

O(N2)

O(N)

Page 42: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Product Complexity

• Got done in O(N) time, better than O(N2)• Each time “chunk” does O(N) work• There are N time chunks.• Thus, the amount of work is still O(N2)

• Product complexity is the amount of work per “time chunk” multiplied by the number of “time chunks” – the total work done.

Page 43: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Ceiling of Improvement

• Parallelization can reduce time, but it cannot reduce work. The product complexity cannot change or improve.

• How much improvement can parallelization provide?– Given an O(NLogN) algorithm and Log N

processors, the algorithm will take at least O(?) time.

– Given an O(N3) algorithm and N processors, the algorithm will take at least O(?) time.

O(N) time.

O(N2) time.

Page 44: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Number of Processors

• Processors are limited by hardware.• Typically, the number of processors is a

power of 2• Usually: The number of processors is a

constant factor, 2K

• Conceivably: Networked computers joined as needed (ala Borg?).

Page 45: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Adding Processors

• A program on one processor– Runs in X time

• Adding another processor– Runs in no more than X/2 time– Realistically, it will run in X/2 + time

because of overhead• At some point, adding processors will not

help and could degrade performance.

Page 46: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Overhead of Parallelization

• Parallelization is not free.• Processors must be controlled and coordinated.• We need a way to govern which processor does

what work; this involves extra work.• Often the program must be written in a special

programming language for parallel systems.• Often, a parallelized program for one machine

(with, say, 2K processors) doesn’t work on other machines (with, say, 2L processors).

Page 47: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

What We Know about Tasks

• Relatively isolated units of computation• Should be roughly equal in duration• Duration of the unit of work must be much

greater than overhead time• Policy decisions and coordination

required for shared data• Simpler algorithm are the easiest to

parallelize

Page 48: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Questions?

Page 49: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

More?

Page 50: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Matrix Multiplication

443434332432143134

44

34

24

14

3433323134

1

...

....

....

....

....

...

....

....

babababac

b

b

b

b

aaaac

bac

bacn

kkjikij

Page 51: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Inner Product Procedure

Procedure inner_prod(a, b, c isoftype in/out Matrix, i, j isoftype in Num)

// Compute inner product of a[i][*] and b[*][j]

Sum isoftype Num

k isoftype Num

Sum <- 0

k <- 1

loop

exitif(k > n)

sum <- sum + a[i][k] * b[k][j]

k < k + 1

endloop

endprocedure // inner_prod

Page 52: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Matrix definesa Array[1..N][1..N] of Num

N is // Declare constant defining size

// of arrays

Algorithm P_Demo

a, b, c isoftype Matrix Shared

server isoftype Num

Initialize(NUM_SERVERS)

// Input a and b here

// (code not shown)

i, j isoftype Num

Page 53: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

i <- 1

loop

exitif(i > N)

server <- (i * NUM_SERVERS) DIV N

j <- 1

loop

exitif(j > N)

RThread(server, inner_prod(a, b, c, i, j ))

j <- j + 1

endloop

i <- i + 1

endloop

Parallel_Wait(NUM_SERVERS)

// Output c here

endalgorithm // P_Demo

Page 54: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.

Questions?

Page 55: Concurrent Systems Parallelism. Final Exam Schedule CS1311 Sections L/M/N Tuesday/Thursday 10:00 A.M. Exam Scheduled for 8:00 Friday May 5, 2000 Physics.