Concurrent Order Maintenance Seth Gilbert (Collaboration with Jeremy Fineman and Michael Bender) 6/8/2004 MIT CSAIL - 6.895 Final Presentation 1 Order Maintenance • Problem: – Insert(Item, Predecessor) • Inserts Item after Predecessor • Returns pointer to item – Precedes(A, B) • Does item A precede item B? • Solutions: • Dietz, Sleator, Order Maintenance Problem, 1987 • Bender, Cole, Demaine, Farach-Colton, Zito, 2002 6/8/2004 MIT CSAIL - 6.895 Final Presentation 2 Example Insert(A, 0) Insert(B, A) Insert(C, B) Insert(D, B) Insert Cost: O(log n) (C, 76) 0 (A, 50) 6/8/2004 MIT CSAIL - 6.895 Final Presentation (B, 75) 100 (C, 87) 3 Example Precedes(A, C)? Insert Cost: O(log n) Precedes Cost: O(1) 100 0 (A, 50) 6/8/2004 MIT CSAIL - 6.895 Final Presentation (B, 75) (C, 87) 4 Outline • Introduction • Indirection • Results – Total Work – O log p T1 + p·T∞ – O 1 T1 + p(1+ε)·T∞ , 0 < ε ≤ 0.5 ε • Non-blocking Implementations • Conclusion 6/8/2004 MIT CSAIL - 6.895 Final Presentation 5 Getting Constant Time • Maintain n/log n lists of size log n Insert(B, A) Insert(A, 0) Insert(C, A) 75 50 0 0 log n 0 n log n (A, 3)(C, 4) (B, 5) 6/8/2004 MIT CSAIL - 6.895 Final Presentation 6 Getting Constant Time • • O(n·log n) to insert n items Maintain n/log n lists of size log n n log n • log n = O(n) Maintain lists of size log n – Easy! – No reorganization => constant time ops – Each insert divides tag space in half… 6/8/2004 MIT CSAIL - 6.895 Final Presentation 7 Outline • Introduction • Indirection • Results – Total Work – O log p T1 + p·T∞ – O 1 T1 + p(1+ε)·T∞ , 0 < ε ≤ 0.5 ε • Non-blocking Implementations • Conclusion 6/8/2004 MIT CSAIL - 6.895 Final Presentation 8 Parallel Problems • Lock during inserts? – Queries are still fast – Inserts may be slow • Focus on Cilk graph (Non-Determinator) ≤ T1 Precedes queries ≤ p·T∞ Insert ops (steal attempts) • Desired goal: O(T1 + p·T∞) work • Reality: slower… 6/8/2004 MIT CSAIL - 6.895 Final Presentation 9 Applications • Non-Determinator • Cache-oblivious B-Trees • Distributed Search Data Structures 6/8/2004 MIT CSAIL - 6.895 Final Presentation 10 Small Number Processors • If p ≤ log n, use indirection 0 p 0 p 0 log n 0 T∞ log n 75 50 0 log n – Waiting time per processor: T∞ log n log n = O(T∞) – Total waiting time: O(p·T∞) 6/8/2004 MIT CSAIL - 6.895 Final Presentation 11 One Level Indirection • Assume p is not so small 0 0 0 T∞ log n 75 50 p p 0 log n 0 log n • How expensive is ordering p elements? – Waiting time per insert O(p) – Total waiting time: p2·T∞ • Total work: O(T1 + p2·T∞) 6/8/2004 MIT CSAIL - 6.895 Final Presentation 12 More Indirection • If p > log n, but not too big: T∞ log n 50 0 0 k = log p + 1 loglog n log n 0 0 logkn = p·log n 0 • Precedes: O(log p) • Total: O log p T1 + p·T∞ 6/8/2004 log n MIT CSAIL - 6.895 Final Presentation log n log n Better when: p2 T1 < T∞ log p 13 Variable Indirection • Trade-off between queries and inserts: 0 pεk = p pε 0 k=1 ε pε 0 • 0 < ε ≤ 0.5 0 • Precedes: 1/ε • Total: O 1 T1 + p(1+ε)·T∞ ε 6/8/2004 T∞ log n 50 0 MIT CSAIL - 6.895 Final Presentation pε log(n) 14 More Indirection (Again) T∞ log n 50 0 pε 0 k=1 ε • ε= pε 0 0 1 log(n) 0 log p 0 • Precedes: log p pε 0 log(n) log(pε) + 1 loglog(n) log(n) • Total: O log p T1 + p·T∞ 6/8/2004 MIT CSAIL - 6.895 Final Presentation 15 Outline • Introduction • Indirection • Results – Total Work – O log p T1 + p·T∞ – O 1 T1 + p(1+ε)·T∞ , 0 < ε ≤ 0.5 ε • Non-blocking Implementations • Conclusion 6/8/2004 MIT CSAIL - 6.895 Final Presentation 16 Non-Blocking • Assume DCAS – Compares two addresses with old values – DCAS(A, B, old-A, old-B, new-A, new-B) • if ((*A == old-A) && (*B == old-B)) *A = new-A *B = new-B • Lock-freedom / Obstruction-freedom – Some operation is always able to make progress • Start with linked-list implementation 6/8/2004 MIT CSAIL - 6.895 Final Presentation 17 Concurrent Reorganization • How to ensure that operations make progress? – Precedes queries can always proceed – Always renumber monotonically increasing • How to ensure Insert does not interfere? – Increment “owner” field of predecessor – Only Insert or Renumber if you own the predecessor – Backoff 6/8/2004 MIT CSAIL - 6.895 Final Presentation 18 Conclusion • Concurrent Order Maintenance – T1 Precedes queries – pT∞ Inserts (steals) – p Processors • Results – Total Work – O log p T1 + p·T∞ – O 1 T1 + p(1+ε)·T∞ , 0 < ε ≤ 0.5 ε 6/8/2004 MIT CSAIL - 6.895 Final Presentation 19 Conclusion • Concurrent Order Maintenance – T1 Precedes queries – pT∞ Inserts (steals) – p Processors • Results – Total Work – O loglog p T1 + p·T∞ –O 6/8/2004 1 T1 + p(1+ε)·T∞ , 0 < ε ≤ 0.5 log ε MIT CSAIL - 6.895 Final Presentation 20 Backup Slides 6/8/2004 MIT CSAIL - 6.895 Final Presentation 21 Binary Tree 63% 1 0 73% 00 01 10 11 85% 000 001 010 011 100 101 110 111 100% (C, 0) (E, (B, 1) (B, 2) (A, 5) (F, 6) (D, 7) N 0 6/8/2004 MIT CSAIL - 6.895 Final Presentation 22 Bad Example p p·log(p) 6/8/2004 MIT CSAIL - 6.895 Final Presentation 23 Why does it work? • Concurrent reorganization can only help • Successful insert implies some processor made progress – No worse than starting after insert completes • At worst, same as locking: – Begin after operation completes 6/8/2004 MIT CSAIL - 6.895 Final Presentation 24