Maintaining SP Relationships Efficiently, on-the-fly
description
Transcript of Maintaining SP Relationships Efficiently, on-the-fly
![Page 1: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/1.jpg)
Maintaining SP Relationships Efficiently, on-the-fly
Jeremy Fineman
![Page 2: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/2.jpg)
The Problem
• Fork-Join (e.g. Cilk) programs have threads that operate either in series or logically parallel.
• Want to query relationship between two threads as the program runs.
• For example, Nondeterminator uses relationship between two threads as basis for determinacy race.
![Page 3: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/3.jpg)
Parse Tree
• Represent SP-DAG as a parse tree• S nodes show series relationships• P nodes are parallel relationships
a c
b
dS
P
d
a
S
cb
![Page 4: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/4.jpg)
Least Common Ancestor
• SP-Bags uses LCA lookup.• LCA of b and d is an S-node
– So b and d are in series
• Cost is (v,v) per query (in Nondeterminator)
S
P
d
a
S
cb
![Page 5: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/5.jpg)
Two Complementary Walks
• At S-node, always walk left then right• At P-node, can go left then right, or right then left
S
P
d
a
S
cb
![Page 6: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/6.jpg)
Two Complementary Walks
• Produce two orders of threads:– a b c d– a c b d
• Notice b || c, and orders differ between b and c.
S
P
d
a
S
cb
![Page 7: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/7.jpg)
Two Complementary Walks
• Claim: If e1 precedes e2 in one walk, and e2 precedes e1 in the other, then e1 || e2.
S
P
d
a
S
cb
![Page 8: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/8.jpg)
Maintaining both orders in a single tree walk
• Walk of tree represents execution of program. – Can execute program twice, but execution
could be nondeterministic.– Instead, maintain both thread orderings on-the-
fly, in a single pass.
![Page 9: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/9.jpg)
Order Maintenance Problem
• We need a data structure which supports the following operations:– Insert(X,Y): Place Y after X in the list.– Precedes(X,Y): Does X come before Y?
![Page 10: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/10.jpg)
Naïve Order Maintenance Structure
• Naïve Implementation is just a linked list
![Page 11: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/11.jpg)
Naïve Order Maintenance Insert
• Insert(X,Y) does standard linked list insert
X
Y
![Page 12: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/12.jpg)
Naïve Order Maintenance Insert
• Insert(X,Y) does standard linked list insert
X
Y
![Page 13: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/13.jpg)
Naïve Order Maintenance Insert
• Insert(X,Y) does standard linked list insert
X
Y
![Page 14: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/14.jpg)
Naïve Order Maintenance Query
• Precedes(X,Z) looks forward in list.
X Z
![Page 15: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/15.jpg)
Naïve Order Maintenance Query
• Precedes(X,Z) looks forward in list.
X Z
![Page 16: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/16.jpg)
Naïve Order Maintenance Query
• Precedes(X,Z) looks forward in list.
X Z
![Page 17: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/17.jpg)
Naïve Order Maintenance Query
• Precedes(X,Z) looks forward in list.
X Z
![Page 18: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/18.jpg)
The algorithm
• Recall, we are thinking in terms of parse tree.
• Maintain two order structures.
• When executing node x:– Insert children of x after x in the lists.– Ordering of children depends on whether x is
an S or P node.
![Page 19: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/19.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
![Page 20: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/20.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
![Page 21: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/21.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
![Page 22: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/22.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
![Page 23: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/23.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
![Page 24: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/24.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
![Page 25: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/25.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
![Page 26: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/26.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
b
c
c
b
![Page 27: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/27.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
b
c
c
b
![Page 28: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/28.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
b
c
c
b
![Page 29: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/29.jpg)
ExampleS1
P
d
a
S2
cb
Order 1:
Order 2:
S1
S1
S2
S2
d
d
a
a
P
P
b
c
c
b
![Page 30: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/30.jpg)
Analysis
• Correctness does not depend on execution– Any valid serial or parallel execution produces
correct results.• Inserts after x in orders only happen when x
executes.
• Only one processor will ever insert after x.
• Running time depends on implementation of order maintenance data structure.
![Page 31: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/31.jpg)
Serial Running Time
• Current Nondeterminator does serial execution.
• Can have O(T1) queries and inserts.
• Naïve implementation is – O(n) time for query of n-element list. – O(1) time for insert.
– Total time is very poor: O(T12)
![Page 32: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/32.jpg)
Use Dietz and Sleator Order Maintenance Structure
• Essentially a linked list with labels.
• Queries are O(1): just compare the labels.
• Inserts are O(1) amortized cost.– On some inserts, need to perform relabel.
• O(T1) operations only takes O(T1) time.
– Gives us linear time Nondeterminator. Better than SP-bags algorithm.
![Page 33: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/33.jpg)
Parallel Problem
• Dietz and Sleator relabels on inserts– Does not work concurrently.
• Lock entire structure on insert?– Query is still O(1).
– Single relabel can cost O(T1) operations.
• Critical path increases to O(T1)
• Running time is O(T1/p + T1).
![Page 34: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/34.jpg)
Parallel Problem Solution
• Leverage the Cilk scheduler:– There are only O(pT) steals
• There is no contention on subcomputations done by single processor between steals.– We do not need to lock every insert.
![Page 35: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/35.jpg)
Parallel Problem Solution
• Top level is global ordering of subcomputations.• Bottom level is local ordering of subcomputation
performed on single processor.• On a steal, insert O(1) nodes into global structure.
Global StructureSize: O(pT)
![Page 36: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/36.jpg)
Parallel Running Time
• An insert into a local order structure is still O(1).• An insert into the global structure involves locking
the entire global structure.– May need to wait for p processors to insert serially.
– Amortized cost is O(p) per insert.
– Only O(pT) inserts into global structure.
• Total work and waiting time is O(T1 + p2T)
– Running time is O(T1/p + pT)
![Page 37: Maintaining SP Relationships Efficiently, on-the-fly](https://reader034.fdocuments.net/reader034/viewer/2022051623/56815a83550346895dc7f1cc/html5/thumbnails/37.jpg)
Questions?