Professional Documents
Culture Documents
Distribution
C A B
4 parallel additions
fib(3) fib(2)
fib(1) fib(1)
fib(3) fib(2)
fib(1) fib(1)
fib(3) fib(2)
fib(1) fib(1)
4 5 6 7 8 9
10 11 12 13 14 15
16 17
work is 17
Art of Multiprocessor Programming© Herlihy – 43
Shavit 2007
Fib Critical Path
fib(4)
2 7
3 4 6
5
Critical path length is 8
Art of Multiprocessor Programming© Herlihy – 45
Shavit 2007
Notation Watch
• TP = time on P processors
• T1 = work (time on 1 processor)
• T∞ = critical path length (time on ∞
processors)
4 parallel additions
4 spawned additions
spawned additions in
parallel
Partition, synch, etc
Art of Multiprocessor Programming© Herlihy – 54
Shavit 2007
Addition
• Critical Path length is
C A B
8 multiplications
4 additions
8 parallel
multiplications
Art of Multiprocessor Programming© Herlihy – 60
Shavit 2007
Multiplication
• Work is
Half-size parallel
multiplications
Tasks
User-level scheduler
Processors
Tasks
User-level scheduler
Threads
Kernel-level scheduler
Processors
T ≤ T1/PA + T∞(P-1)/PA
T ≤ T1/PA + T∞(P-1)/PA
T ≤ T1/PA + T∞(P-1)/PA
Actual time
T ≤ T1/PA + T∞(P-1)/PA
Work divided by
processor average
T ≤ T1/PA + T∞(P-1)/PA
T ≤ T1/PA + T∞(P-1)/PA
1 T
P A
T
p
i 1
i
1 T
T p
P
i
A i 1 Bound this!
work idle
Art of Multiprocessor Programming© Herlihy – 79
Shavit 2007
At the end ….
T
Total #tokens = p
i 1
i
work idle
work idle
work idle
fib(3) fib(2)
fib(1) fib(1)
fib(3) fib(2)
fib(1) fib(1)
Longest path
Art of Multiprocessor Programming© Herlihy – 86
Shavit 2007
Unexecuted sub-DAG
fib(4)
fib(3) fib(2)
p
i 1
i T1 T ( P 1)
1
T T1 T (P 1)
PA
Yes!
D’oh!
D’oh!
work
pushBottom
popBottom
1. Double-Ended Queue
Art of Multiprocessor Programming© Herlihy – 98
Shavit 2007
Obtain Work
•Obtain work
•Run thread until
•Blocks or terminates
popBottom
•Unblock node
•Spawn node
pushBottom
@&%$!!
empty
Blame the
victim!
CAS
top
top
top
top
top
top
top
CAS
top
Uh-Oh …
stamp
top
bottom
Runnable r = tasks[bottom];
int[] stamp = new int[1];
bottom
int oldTop = top.get(stamp), newTop = 0;
int oldStamp = stamp[0], newStamp = oldStamp + 1;
if (bottom > oldTop) return r;
if (bottom == oldTop){
bottom = 0;
if (top.CAS(oldTop, newTop, oldStamp, newStamp))
return r;
}
top.set(newTop,newStamp); return null;
} Art of Multiprocessor Programming© Herlihy – 137
Shavit 2007
Take Work
Runnable popBottom() {
I lose CAS
if (bottom == 0) return null; stamp
Thief must
bottom--; top
CAS
have won…
Runnable r = tasks[bottom];
int[] stamp = new int[1];
bottom
int oldTop = top.get(stamp), newTop = 0;
int oldStamp = stamp[0], newStamp = oldStamp + 1;
if (bottom > oldTop) return r;
if (bottom == oldTop){
bottom = 0;
if (top.CAS(oldTop, newTop, oldStamp, newStamp))
return r;
}
top.set(newTop,newStamp); return null;
} Art of Multiprocessor Programming© Herlihy – 138
Shavit 2007
Take Work
Runnable popBottom() {
if (bottom == 0) return null;
bottom--;
Runnable r = tasks[bottom];
int[] stamp = new int[1];
failed to get last item
int oldTop = top.get(stamp), newTop = 0;
2
d2+5e/2=4
5
b2+5 c/2=3
R I D DL E