Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Work-stealing Tree Scheduler

Work-stealing Tree Scheduler

Explanation of the work-stealing tree scheduler used in ScalaBlitz.

Aleksandar Prokopec

September 25, 2013
Tweet

More Decks by Aleksandar Prokopec

Other Decks in Programming

Transcript

  1. Irregular workload for { x <- 0 until width y

    <- 0 until height } image(x, y) = compute(x, y) N cycles 9
  2. Irregular workload for { x <- 0 until width y

    <- 0 until height } image(x, y) = compute(x, y) image(x, y) = compute(x, y) N cycles 10
  3. Workload function workload(n) – work spent on element n after

    the data-parallel operation completed 11
  4. Workload function Could be… Runtime value dependent for { x

    <- 0 until width y <- 0 until height } img(x, y) = compute(x, y) workload(n) – work spent on element n after the data-parallel operation completed 12
  5. Workload function Could be… Execution-schedule dependent for (n <- nodes)

    n.neighbours += new Node workload(n) – work spent on element n after the data-parallel operation completed 13
  6. Workload function Could be… Totally random for ((x, y) <-

    img.indices) img(x, y) = sample( x + random(), y + random() ) workload(n) – work spent on element n after the data-parallel operation completed 14
  7. Data-parallel scheduler 1. Linear speedup for the baseline workload Assign

    loop elements to workers without knowledge about the workload function. 16
  8. Data-parallel scheduler 1. Linear speedup for the baseline workload 2.

    Optimal speedup for irregular workloads Assign loop elements to workers without knowledge about the workload function. 17
  9. Static batching Decides on the worker-element assignment before the data-parallel

    operation begins. No knowledge → divide uniformly. Not optimal for even mildly irregular workloads. N cycles 19
  10. Fixed-size batching Workload-driven – decides during execution. N cycles progress

    Pros: lightweight Cons: minimum batch size, contention 28
  11. Task-based work-stealing N cycles 0..2 2..4 4..8 8..16 2..4 4..8

    8..16 T0 T1 0..2 steal – a rare event 33
  12. Task-based work-stealing Pros: can be adaptive - uses stealing information

    Cons: heavyweight - minimum batch size much larger N cycles 0..2 2..4 4..8 8..16 2..4 4..8 8..16 T0 T1 10..12 12..16 0..2 8..10 35
  13. Work-stealing tree 0 0 T0 N 0 50 T0 N

    owned owned T0: CAS 38
  14. Work-stealing tree 0 0 T0 N 0 50 T0 N

    0 N T0 N … owned owned completed T0: CAS T0: CAS What about stealing? 39
  15. Work-stealing tree 0 0 T0 N 0 50 T0 N

    0 N T0 N … owned owned completed 0 -51 T0 N T0: CAS T1: CAS stolen T0: CAS 40
  16. Work-stealing tree 0 50 T0 N 0 N T0 N

    … owned completed 0 -51 T0 N T0: CAS stolen T0: CAS 0 0 T0 N owned T1: CAS 41
  17. Work-stealing tree 0 50 T0 N 0 N T0 N

    … owned completed 0 -51 T0 N T0: CAS stolen 0 -51 T0 N expanded 50 50 T0 M M M T1 N T0: CAS 0 0 T0 N owned M = (50 + N) / 2 42
  18. Work-stealing tree 0 50 T0 N 0 N T0 N

    … owned completed 0 -51 T0 N T0: CAS stolen 0 -51 T0 N expanded 50 50 T0 M M M T1 N T0: CAS 0 0 T0 N owned M = (50 + N) / 2 T0 or T1: CAS 43
  19. Work-stealing tree 0 50 T0 N 0 N T0 N

    … owned completed 0 -51 T0 N T0: CAS stolen 0 -51 T0 N expanded 50 50 T0 M M M T1 N T0 or T1: CAS T0: CAS 0 0 T0 N owned M = (50 + N) / 2 44
  20. Work-stealing tree scheduling 1) find either a non-expanded, non-completed node

    2) if not found, terminate 3) if not owned, steal and/or expand, and descend 4) advance until node is completed or stolen 5) go to 1) 50
  21. Work-stealing tree scheduling 1) find either a non-expanded, non-completed node

    2) if not found, terminate 3) if not owned, steal and/or expand, and descend 4) advance until node is completed or stolen 5) go to 1) 1) find either a non-expanded, non-completed node 51
  22. Choosing the node to steal Find first, in-order traversal 2

    9 5 3 Catastrophic – a lot of stealing, huge trees 53
  23. Choosing the node to steal Find first, in-order traversal Find

    first, random order traversal 2 9 5 3 2 9 5 3 Catastrophic – a lot of stealing, huge trees 54
  24. Choosing the node to steal Find first, in-order traversal Find

    first, random order traversal 2 9 5 3 2 9 5 3 Catastrophic – a lot of stealing, huge trees Works reasonably well. 55
  25. Choosing the node to steal Find first, in-order traversal Find

    first, random order traversal Find most elements 2 9 5 3 2 9 5 3 2 9 5 3 Catastrophic – a lot of stealing, huge trees Works reasonably well. Generates least nodes. Seems to be best. 56