Docsity

Introduction to Parallelism - Operating System Design and Implementation - Lecture Slides, Slides of Operating Systems

Partial preview of the text

Download Introduction to Parallelism - Operating System Design and Implementation - Lecture Slides and more Slides Operating Systems in PDF only on Docsity!

Introduction

to

Parallelism

I.^

Why

is^ parallel

processing

so^

important

now?

II. What’s

new

and

different

with

parallelism?

III. Parallel

Programming

Models

A^ Brief

History

of^

Parallel

Processing

-^ Initial

Focus

(starting

in^ 1970’s):

“Supercomputers”

for^

Scientific

Computing

C.mmp at

CMU

(1971) 16 PDP

‐^11 processors

Cray^ XMP^

(circa

4 vector

processors

Thinking

Machines

CM‐^2

(circa

65,536 1

‐bit^ processors

2048 floating

‐point

co‐processors

SGI^ UV

1000cc

‐NUMA

(today)

4096 processor

cores

Blacklight at

the^ Pittsburgh Supercomputer

Center

A^ Brief

History

of^

Parallel

Processing

-^ Initial

Focus

(starting

in^ 1970’s):

“Supercomputers”

for^

Scientific

Computing

-^ Another

Driving

Application

(starting

in^ early

90’s):

Databases

-^ Inflection

point

in^ 2004:

Intel

hits

the

Power

Density

Wall

Pat Gelsinger, ISSCC 2001

Intel's Big Shift After Hitting Technical Wall

The warning came first from a group of hobbyists that tests the speeds of computer chips. Thisyear, the group discovered that the Intel Corporation's newest microprocessor was runningslower and hotter than its predecessor.What they had stumbled upon was a major threat to Intel's longstanding approach to dominatingthe semiconductor industry - relentlessly raising the clock speed of its chips.Then two weeks ago, Intel, the world's largest chip maker, publicly acknowledged that it had hita "thermal wall" on its microprocessor line. As a result, the company is changing its productstrategy and disbanding one of its most advanced design groups. Intel also said that it wouldabandon two advanced chip development projects, code-named Tejas and Jayhawk.Now, Intel is embarked on a course already adopted by some of its major rivals: obtaining morecomputing power by stamping multiple processors on a single chip rather than straining toincrease the speed of a single processor.…

From

the

New

York

Times

John Markoff, New York Times, May 17, 2004

Parallel

Machines

Today

Examples

from

Apple’s

product

line:

(Images

iPhone from apple.com)

5s 2 A^

cores

iPad Retina 2 A6X

cores (+^ 4 graphics

cores)

MacBook

Pro^ Retina

15”

4 Intel

Core

i7^ cores

iMac 4 Intel

Core

i5^ cores

Mac^ Pro 12 Intel

Xeon

E5^ cores

Example

“Multicore”

Processor:

Intel

Core

i

-^ Cores:

six 3.

GHz Nahelem processors (with

2 ‐way

“Hyper

‐Threading”)

-^ Caches:

64KB

L1 (private),

256KB

L2 (private),

12MB

L3 (shared)

Intel

Core

i7‐980X (6 cores)

Counting

Hardware

Threads:

Some

Terminology

In^ the

Old

Days

(pre

–^1

processor

(aka

“CPU”,

“core”)

per

chip

-^ each

chip

lives

in^ a^

“socket”

Today:

-^ X processor chips (each

in^ a

socket)

-^ Y “cores”

per

processor

chip

-^ Z hardware

threads per

core

if^ Hyper

‐Threading

enabled)

-^ total

OS‐

visible

hardware

threads =

X x^

Y x^ Z

Example: dual

‐socket

6 ‐core

Intel

Core

i7’s with

2 ‐way

Hyper

‐Threading

^ 2 x

6 x^

2 =^ 24 hardware

threads

What’s

Fundamentally

New

for

the

Programmer?

-^ Programs

now

contain

multiple

threads

that

must

(i)^ communicate

(i.e.

share

data)

and

(ii)^ coordinate

(i.e.

synchronize)

with

each

other

efficiently

for^

the^

sake

of^ improving

overall

performance.

-^ While

these

concepts

may

seem

familiar,

the

tradeoffs

are a^ bit

different

when:

-^ there

is^ physical

parallelism,

and

-^ performance

is^ paramount.

Shared

Address

Space

Model

-^ Analogy:

like

cooperating

by^ reading

and

writing

on^ a

shared

chalk

board

-^ Mechanism: -^ threads

share

a^ common

virtual

address

space in

memory

-^ can

communicate

through

normal

memory

reads

and

writes

-^ Cartoon

view:

-^ Examples:

OpenMP (compiler

pragmas;

gcc –fopenmp

),^ Intel’s TBB (C++

library)

CPU^

0

CPU^

1

CPU^

2

CPU^

N … Memory X:^1

Y:^2

Load

%eax

^ Y

Store

3 

X

Message

Passing

Model

-^ Analogy:

like

communicating

by^ sending

email

-^ Mechanism: -^ send() and

receive() primitives

support

inter

‐thread

messaging

-^ each

thread’s

virtual

address

space

is^ private to

that

thread

-^ Cartoon

view:

-^ Example: Message

Passing

Interface (MPI),

www.open

… ‐mpi.org

CPU^

0

Memory

0

CPU^

1

Memory

1

CPU^

N^

Memory

N

Interconnection

Network

X:^ ABCD

Y:^ ____

To:^1

From:

0 Data:

ABCD

send(target_thread,&X,length,…);

receive(&Y,&from,

…);

Example

Program:

Grid

Solver

-^ Simplified

version

of^ a

physical

simulation

(using

Guass

‐Seidel

method)

-^ On

each

time

step:

-^ calculate

new

value for

interior

points,

as^ shown

above

-^ add

up^ differences

between

new

and

old values

over

all^ points

-^ if

overall

difference

<^ threshold,

terminate

(otherwise,

on^ to

next

time

step)

A[i,j]

= 0.2 x (A[i,j]+A[i,j-1]+A[i-1,j]+

A[i,j+1]+A[i+1,j])

Updating

interior

points

(per

time

step):

Sequential

Version

of^

Grid

Solver

1.^ int

n;^

//^ size

of^ matrix:

(n^ +

2-by-n

+^ 2)

elements

2.^ float

****A,**

diff

=^ 0;

3.^ main()4.^ begin5.^

read(n);

//^ read

input

parameter:

matrix

size

6.^

A^ ^

malloc

( a^ 2-d

array

of^ size

n^ +^

2 by^

n^ +^2

doubles

);

7.^

initialize(A);

//^ initialize

the^

matrix

A^ somehow

8.^

Solve(A);

//^ call

the^

routine

to^ solve

equation

9.^ end

main

10.^ procedure

Solve(A)

//^ solve

the^

equation

system

11.^

float

****A;**

//^ A^

is^ an

(n^ +

2)-by-(n

+^ 2)

array

12.^ begin13.^

int^ i,

j,^ done

=^ 0;

14.^

float

diff

=^ 0,

temp;

15.^

while

(!done)

do^

//^ outermost

loop

over

sweeps

16.^

diff^

=^ 0;^

//^ initialize

maximum

difference

to^0

17.^

for^ i

^^1

to^ n

do^

//^ sweep

over

interior

points

of^ grid

18.^

for^ j

^^1

to^ n

do

19.^

temp^

=^ A[i,j];

//^ save

old^

value

of^ element

20.^

A[i,j]

^ 0.

*****^ (A[i,j]

+^ A[i,j-1]

+^ A[i-1,j]

+

21.^

A[i,j+1]

+^ A[i+1,j]);

//^

compute

average

22.^

diff^

+=^ abs(A[i,j]

-^ temp); 23.^

end^ for

24.^

end^ for

25.^

if^ (diff/(nn)*

<^ TOL)

then

done

=^ 1;

26.^

end^ while

27.^ end

procedure

Partitioning

the

Grid

Solver

-^ One

approach: – assign

contiguous

sets

of^ rows to

threads

-^ Helps

minimize

communication

(assuming

row

‐major

memory

layout)

-^ Why?

Thread

Thread

Thread

Thread

Next

Step

in^

Creating

a^ Parallel

Program:

Orchestration

-^ Partitioning

steps:

independent

of^ parallel

programming

model

-^ Orchestration:

very

much

dependent

on^ parallel

programming

P^0 model

Tasks

(unitsof work)

Work

per^

Thread

Processors

P^1 P^2

P^3

p^0

p^1 p^2

p^3

p^0

p^1 p^2

p^3

Partitioning

SequentialComputation

ParallelProgram

Decomposition

Assignment

Orchestration

Mapping