WORK STEALING SCHEDULER 2 6/16/2010 Work Stealing - - PowerPoint PPT Presentation

work stealing scheduler
SMART_READER_LITE
LIVE PREVIEW

WORK STEALING SCHEDULER 2 6/16/2010 Work Stealing - - PowerPoint PPT Presentation

1 6/16/2010 Work Stealing Scheduler WORK STEALING SCHEDULER 2 6/16/2010 Work Stealing Scheduler Announcements Text books Assignment 1 Assignment


slide-1
SLIDE 1

WORK ¡STEALING ¡ SCHEDULER ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

1 ¡

slide-2
SLIDE 2

Announcements ¡

  • Text ¡books ¡
  • Assignment ¡1 ¡
  • Assignment ¡0 ¡results ¡
  • Upcoming ¡Guest ¡lectures ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

2 ¡

slide-3
SLIDE 3

Recommended ¡Textbooks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

3 ¡

The ¡Art ¡of ¡MulLprocessor ¡ ¡ Programming ¡ Maurice ¡Herlihy, ¡Nir ¡Shavit ¡ PaQerns ¡for ¡Parallel ¡ Programming ¡ Timothy ¡MaQson, ¡et.al. ¡ Parallel ¡Programming ¡with ¡ ¡ MicrosoT ¡.NET ¡ hQp://parallelpaQerns.codeplex.com/ ¡

slide-4
SLIDE 4

Available ¡on ¡Website ¡

  • Assignment ¡1 ¡(due ¡two ¡weeks ¡from ¡now) ¡
  • Paper ¡for ¡Reading ¡Assignment ¡1 ¡(due ¡next ¡week) ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

4 ¡

slide-5
SLIDE 5

Assignment ¡0 ¡

  • Thanks ¡for ¡submiXng ¡ ¡
  • Provided ¡important ¡feedback ¡to ¡us ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

5 ¡

slide-6
SLIDE 6

Percentage ¡Students ¡Answering ¡Yes ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

6 ¡

0 ¡ 20 ¡ 40 ¡ 60 ¡ 80 ¡ 100 ¡

slide-7
SLIDE 7

Number ¡of ¡Yes ¡Answers ¡Per ¡Student ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

7 ¡

0 ¡ 2 ¡ 4 ¡ 6 ¡ 8 ¡ 10 ¡ 12 ¡ 14 ¡ 0 ¡ 1 ¡ 2 ¡ 3 ¡ 4 ¡ 5 ¡ 6 ¡ 7 ¡ 8 ¡

slide-8
SLIDE 8

Upcoming ¡Guest ¡Lectures ¡

  • Apr ¡12: ¡Todd ¡Mytkowicz ¡ ¡
  • How ¡to ¡(and ¡not ¡to) ¡measure ¡performance ¡
  • Apr ¡19: ¡Shaz ¡Qadeer ¡
  • Correctness ¡SpecificaLons ¡and ¡Data ¡Race ¡DetecLon ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

8 ¡

slide-9
SLIDE 9

Last ¡Lecture ¡Recap ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

9 ¡

slide-10
SLIDE 10

Last ¡Lecture ¡Recap ¡

  • Parallel ¡computaLon ¡can ¡be ¡represented ¡as ¡a ¡DAG ¡
  • Nodes ¡represent ¡sequenLal ¡computaLon ¡
  • Edges ¡represent ¡dependencies ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

10 ¡

Split ¡ SequenLal ¡ ¡Sort ¡ Merge ¡ SequenLal ¡Sort ¡ Time ¡

slide-11
SLIDE 11

Last ¡Lecture ¡Recap ¡

  • ¡ ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

11 ¡

slide-12
SLIDE 12

Last ¡Lecture ¡Recap ¡

  • ¡ ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

12 ¡

slide-13
SLIDE 13

Last ¡Lecture ¡Recap ¡

  • ¡ ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

13 ¡

slide-14
SLIDE 14

This ¡Lecture ¡

  • Design ¡of ¡a ¡greedy ¡scheduler ¡
  • Task ¡abstracLon ¡
  • TranslaLng ¡high-­‑level ¡abstracLons ¡to ¡tasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

14 ¡

slide-15
SLIDE 15

This ¡Lecture ¡

  • Design ¡of ¡a ¡greedy ¡scheduler ¡
  • Task ¡abstracLon ¡
  • TranslaLng ¡high-­‑level ¡abstracLons ¡to ¡tasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

15 ¡

.NET ¡ .NET ¡ Program ¡ Intel ¡ TBB ¡ TBB ¡ Program ¡ … ¡ Scheduler ¡

slide-16
SLIDE 16

(Simple) ¡Tasks ¡

  • A ¡node ¡in ¡the ¡DAG ¡
  • ExecuLng ¡a ¡task ¡generates ¡dependent ¡subtasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

16 ¡

Split(16) ¡ Merge(16) ¡ Split(8) ¡ Merge(8) ¡ Sort(4) ¡ Sort(4) ¡ Split(8) ¡ Merge(8) ¡ Sort(4) ¡ Sort(4) ¡

slide-17
SLIDE 17

(Simple) ¡Tasks ¡

  • A ¡node ¡in ¡the ¡DAG ¡
  • ExecuLng ¡a ¡task ¡generates ¡dependent ¡subtasks ¡
  • Note: ¡Task ¡C ¡is ¡generated ¡by ¡A ¡or ¡B, ¡whoever ¡finishes ¡last ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

17 ¡

Split(16) ¡ Merge(16) ¡ Split(8) ¡ Merge(8) ¡ Sort(4) ¡ Sort(4) ¡ Split(8) ¡ Merge(8) ¡ Sort(4) ¡ Sort(4) ¡ C ¡ A ¡ B ¡

slide-18
SLIDE 18

Design ¡Constraints ¡of ¡the ¡Scheduler ¡

  • The ¡DAG ¡is ¡generated ¡dynamically ¡
  • Based ¡on ¡inputs ¡and ¡program ¡control ¡flow ¡
  • The ¡graph ¡is ¡not ¡known ¡ahead ¡of ¡Lme ¡
  • The ¡amount ¡of ¡work ¡done ¡by ¡a ¡task ¡is ¡dynamic ¡
  • The ¡weight ¡of ¡each ¡node ¡is ¡not ¡know ¡ahead ¡of ¡Lme ¡
  • Number ¡of ¡processors ¡P ¡can ¡change ¡at ¡runLme ¡
  • Hardware ¡processors ¡are ¡shared ¡with ¡other ¡processes, ¡kernel ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

18 ¡

slide-19
SLIDE 19

Design ¡Requirements ¡of ¡the ¡Scheduler ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

19 ¡

slide-20
SLIDE 20

Design ¡Requirements ¡of ¡the ¡Scheduler ¡

  • Should ¡be ¡greedy ¡
  • A ¡processor ¡cannot ¡be ¡idle ¡when ¡tasks ¡are ¡pending ¡
  • Should ¡limit ¡communicaLon ¡between ¡processors ¡
  • Should ¡schedule ¡related ¡tasks ¡in ¡the ¡same ¡processor ¡
  • Tasks ¡that ¡are ¡likely ¡to ¡access ¡the ¡same ¡cachelines ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

20 ¡

slide-21
SLIDE 21

AQempt ¡0: ¡Centralized ¡Scheduler ¡

  • “Manager ¡distributes ¡tasks ¡to ¡others” ¡
  • Manager: ¡assigns ¡tasks ¡to ¡workers, ¡ensures ¡no ¡worker ¡

is ¡idle ¡

  • Workers: ¡On ¡task ¡compleLon, ¡submit ¡generated ¡tasks ¡

to ¡the ¡manager ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

21 ¡

slide-22
SLIDE 22

AQempt ¡1: ¡Centralized ¡Work ¡Queue ¡

  • “All ¡processors ¡share ¡a ¡common ¡work ¡queue” ¡
  • Every ¡processor ¡dequeues ¡a ¡task ¡from ¡the ¡work ¡queue ¡
  • On ¡task ¡compleLon, ¡enqueue ¡the ¡generated ¡tasks ¡to ¡

the ¡work ¡queue ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

22 ¡

slide-23
SLIDE 23

AQempt ¡2: ¡Work ¡Sharing ¡

  • “Loaded ¡workers ¡share” ¡
  • Every ¡processor ¡pushes ¡and ¡pops ¡tasks ¡into ¡a ¡local ¡

work ¡queue ¡

  • When ¡the ¡work ¡queue ¡gets ¡large, ¡send ¡tasks ¡to ¡other ¡

processors ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

23 ¡

slide-24
SLIDE 24

Disadvantages ¡of ¡Work ¡Sharing ¡

  • If ¡all ¡processors ¡are ¡busy, ¡ ¡each ¡will ¡spend ¡Lme ¡trying ¡

to ¡offload ¡

  • “Perform ¡communicaLon ¡when ¡busy” ¡
  • Difficult ¡to ¡know ¡the ¡load ¡on ¡processors ¡
  • A ¡processor ¡with ¡two ¡large ¡tasks ¡might ¡take ¡longer ¡than ¡a ¡

processor ¡with ¡five ¡small ¡tasks ¡

  • Tasks ¡might ¡get ¡shared ¡mulLple ¡Lmes ¡before ¡being ¡

executed ¡

  • Some ¡processors ¡can ¡be ¡idle ¡while ¡others ¡are ¡loaded ¡
  • Not ¡greedy ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

24 ¡

slide-25
SLIDE 25

AQempt ¡3: ¡Work ¡Stealing ¡

  • “Idle ¡workers ¡steal” ¡
  • Each ¡processor ¡maintains ¡a ¡local ¡work ¡queue ¡
  • Pushes ¡generated ¡tasks ¡into ¡the ¡local ¡queue ¡
  • When ¡local ¡queue ¡is ¡empty, ¡steal ¡a ¡task ¡from ¡another ¡

processor ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

25 ¡

slide-26
SLIDE 26

Nice ¡ProperLes ¡of ¡Work ¡Stealing ¡

  • ¡ ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

26 ¡

slide-27
SLIDE 27

Nice ¡ProperLes ¡of ¡Work ¡Stealing ¡

  • ¡ ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

27 ¡

slide-28
SLIDE 28

Work ¡Stealing ¡Queue ¡Datastructure ¡

  • A ¡specialized ¡deque ¡(Double-­‑Ended ¡Queue) ¡with ¡three ¡
  • peraLons: ¡
  • Push ¡: ¡Local ¡processor ¡adds ¡newly ¡created ¡tasks ¡ ¡
  • Pop ¡ ¡ ¡: ¡Local ¡processor ¡removes ¡task ¡to ¡execute ¡
  • Steal ¡: ¡Remote ¡processors ¡remove ¡tasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

28 ¡

Push ¡

slide-29
SLIDE 29

Work ¡Stealing ¡Queue ¡Datastructure ¡

  • A ¡specialized ¡deque ¡(Double-­‑Ended ¡Queue) ¡with ¡three ¡
  • peraLons: ¡
  • Push ¡: ¡Local ¡processor ¡adds ¡newly ¡created ¡tasks ¡ ¡
  • Pop ¡ ¡ ¡: ¡Local ¡processor ¡removes ¡task ¡to ¡execute ¡
  • Steal ¡: ¡Remote ¡processors ¡remove ¡tasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

29 ¡

Push ¡ Pop? ¡ Steal? ¡ Pop? ¡ Steal? ¡

slide-30
SLIDE 30

Work ¡Stealing ¡Queue ¡Datastructure ¡

  • A ¡specialized ¡deque ¡(Double-­‑Ended ¡Queue) ¡with ¡three ¡
  • peraLons: ¡
  • Push ¡: ¡Local ¡processor ¡adds ¡newly ¡created ¡tasks ¡ ¡
  • Pop ¡ ¡ ¡: ¡Local ¡processor ¡removes ¡task ¡to ¡execute ¡
  • Steal ¡: ¡Remote ¡processors ¡remove ¡tasks ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

30 ¡

Push ¡ Steal ¡ Pop ¡

slide-31
SLIDE 31

Advantages ¡

  • Stealers ¡don’t ¡interact ¡with ¡local ¡processor ¡when ¡the ¡

queue ¡has ¡more ¡than ¡one ¡task ¡

  • Popping ¡recently ¡pushed ¡tasks ¡improves ¡locality ¡
  • Stealers ¡take ¡the ¡oldest ¡tasks, ¡which ¡are ¡likely ¡to ¡be ¡

the ¡largest ¡(in ¡pracLce) ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

31 ¡

Push ¡ Steal ¡ Pop ¡

slide-32
SLIDE 32

For ¡Assignment ¡1 ¡

  • We ¡provide ¡an ¡implementaLon ¡of ¡Work ¡Stealing ¡

Queue ¡

  • This ¡implementaLon ¡is ¡thread-­‑safe ¡
  • Clients ¡can ¡concurrently ¡call ¡the ¡push, ¡pop, ¡steal ¡operaLons ¡
  • You ¡don’t ¡need ¡to ¡use ¡addiLonal ¡locks ¡or ¡other ¡

synchronizaLon ¡

  • Implement ¡the ¡scheduler ¡logic ¡and ¡stealing ¡strategy ¡
  • Hint: ¡this ¡implementaLon ¡is ¡single ¡threaded ¡

6/16/2010 ¡ Work ¡Stealing ¡Scheduler ¡

32 ¡