The CHR e Language Introduction Operational Semantics Conclusion Decentralized Execution of Constraint Handling Rules for Ensembles Edmund S. L. Lam Iliano Cervesato sllam@qatar.cmu.edu iliano@cmu.edu Carnegie Mellon University, Qatar Department of Computer Science Funded by the Qatar National Research Fund as project NPRP 09-667-1-100 (Effective Programming for Large Distributed Ensembles) 16th Sept 2013, PPDP’13
The CHR e Language Introduction Operational Semantics Conclusion Outline Introduction 1 The CHR e Language 2 Operational Semantics 3 Conclusion 4
The CHR e Language Introduction Operational Semantics Conclusion Main-stream Distributed Programming Distributed programming is fast becoming inevitable ! Multicore architectures Cloud computing and big data Mobile smart phones and tablets Main-stream demand for software that: Execute in a decentralized manner. Communicate and coordinate as a collective ensemble. We explore adapting Constraint Handling Rules (CHR) for this purpose! Its declarative and concurrent. Online (Computation can start on partial inputs) Anytime (Computation can be interrupted for approximate)
The CHR e Language Introduction Operational Semantics Conclusion Constraint Handling Rules (CHR), Traditionally General form of a CHR rule: Simplified Heads Body Rule Name ���� ���� ���� @ \ ⇐ ⇒ | r P S G B ���� ���� Propagated Heads Guards CHR rules are applied to a multiset of constraints, known as the constraint store St . Informally: If we have P ⊎ S in St , such that G is true, then replace S in St with B . Short forms: If P is empty, we write r @ S ⇐ ⇒ G | B . If S is empty, we write r @ P = ⇒ G | B .
The CHR e Language � � � � Introduction Operational Semantics Conclusion Constraint Handling Rules (CHR), Traditionally Example of CHR Program: Find all shortest path 5 l 0 l 1 base @ edge ( X , Y , D ) = ⇒ path ( X , Y , D ) 1 elim @ path ( X , Y , D1 ) \ path ( X , Y , D2 ) ⇐ ⇒ D1 ≤ D2 | true 8 l 2 l 3 trans @ edge ( X , Y , D1 ) , path ( Y , Z , D2 )= ⇒ X � = Z | path ( X , Z , D1 + D2 ) 2 Example of CHR derivations ( e for edge , p for path ) : � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) � � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) , p ( l 0 , l 1 , 5 ) � base ∗ � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 2 , 2 ) , p ( l 3 , l 2 , 8 ) � baseX 3 � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 2 , 2 ) , p ( l 3 , l 2 , 8 ) trans , p ( l 0 , l 2 , 7 ) � � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 2 , 2 ) , p ( l 3 , l 2 , 8 ) trans , p ( l 0 , l 2 , 7 ) , p ( l 0 , l 2 , 9 ) � � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 2 , 2 ) , e ( l 3 , l 2 , 8 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 2 , 2 ) , p ( l 3 , l 2 , 8 ) elim , p ( l 0 , l 2 , 7 ) �
The CHR e Language � � � � � � � � � � � � � � � � Introduction Operational Semantics Conclusion Why Decentralized and Distribute Solving? CHR e Traditional CHR CHR Solver 1 CHR Solver 2 ... ... rewrites � rewrites � CHR Solver CHR Store 1 CHR Store 2 rewrites � CHR Store CHR Solver 3 CHR Solver 4 rewrites � rewrites � CHR Store 3 CHR Store 4 ... ... Exploiting distributed computing resources. (e.g., shortest path, page rank, minimal spanning tree, distributed sorting) Not feasible for centralized storage. (e.g., P2P mobile applications, embedded device programming)
The CHR e Language Introduction Operational Semantics Conclusion Outline Introduction 1 The CHR e Language 2 Operational Semantics 3 Conclusion 4
The CHR e Language � � � � � � � Introduction Operational Semantics Conclusion Recalling “Find Shortest Path” in CHR 4 5 l 0 l 1 base @ edge ( X , Y , D ) = ⇒ path ( X , Y , D ) 1 elim @ path ( X , Y , D1 ) \ path ( X , Y , D2 ) ⇐ ⇒ D1 ≤ D2 | true 11 3 8 trans @ edge ( X , Y , D1 ) , path ( Y , Z , D2 )= ⇒ X � = Z | path ( X , Z , D1 + D2 ) l 2 l 3 2 � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 0 , 4 ) , e ( l 1 , l 2 , 2 ) , e ( l 2 , l 0 , 11 ) , e ( l 3 , l 2 , 8 ) , e ( l 3 , l 1 , 3 ) � ∗ � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 0 , 4 ) , e ( l 1 , l 2 , 2 ) , e ( l 2 , l 0 , 11 ) , e ( l 3 , l 2 , 8 ) , e ( l 3 , l 1 , 3 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 0 , 4 ) , p ( l 1 , l 2 , 2 ) , p ( l 2 , l 0 , 11 ) , p ( l 3 , l 2 , 8 ) , p ( l 3 , l 1 , 3 ) � ∗ � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 0 , 4 ) , e ( l 1 , l 2 , 2 ) , e ( l 2 , l 0 , 11 ) , e ( l 3 , l 2 , 8 ) , e ( l 3 , l 1 , 3 ) , p ( l 0 , l 1 , 5 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 0 , 4 ) , p ( l 1 , l 2 , 2 ) , p ( l 2 , l 0 , 11 ) , p ( l 3 , l 2 , 8 ) , p ( l 3 , l 1 , 3 ) , p ( l 0 , l 2 , 9 ) , p ( l 0 , l 2 , 7 ) , p ( l 1 , l 0 , 13 ) , p ( l 1 , l 3 , 5 ) , p ( l 2 , l 1 , 16 ) , p ( l 2 , l 3 , 12 ) , p ( l 3 , l 0 , 19 ) , p ( l 3 , l 0 , 7 ) , p ( l 3 , l 2 , 5 ) � ... ∗ � e ( l 0 , l 1 , 5 ) , e ( l 0 , l 3 , 1 ) , e ( l 1 , l 0 , 4 ) , e ( l 1 , l 2 , 2 ) , e ( l 2 , l 0 , 11 ) , e ( l 3 , l 2 , 8 ) , e ( l 3 , l 1 , 3 ) , p ( l 0 , l 1 , 4 ) , p ( l 0 , l 2 , 6 ) , p ( l 0 , l 3 , 1 ) , p ( l 1 , l 0 , 4 ) , p ( l 1 , l 2 , 2 ) , p ( l 1 , l 3 , 5 ) , p ( l 2 , l 0 , 11 ) , p ( l 2 , l 1 , 15 ) , p ( l 2 , l 3 , 12 ) , p ( l 3 , l 0 , 19 ) , p ( l 3 , l 1 , 3 ) , p ( l 3 , l 2 , 5 ) � How can we distribute the constraints, but still collectively solve?
The CHR e Language � � � � � � � Introduction Operational Semantics Conclusion Explicit Location Annotations 4 5 l 0 l 1 base @ [ X ] edge ( Y , D ) = ⇒ [ X ] path ( Y , D ) 1 elim @ [ X ] path ( Y , D1 ) \ [ X ] path ( Y , D2 ) ⇐ ⇒ D1 ≤ D2 | true 11 3 8 trans @ [ X ] edge ( Y , D1 ) , [ Y ] path ( Z , D2 )= ⇒ X � = Z | [ X ] path ( Z , D1 + D2 ) l 2 l 3 2 Location l 0 Location l 1 Location l 2 Location l 3 � e ( l 1 , 5 ) , e ( l 3 , 1 ) � � e ( l 0 , 4 ) , e ( l 2 , 2 ) � � e ( l 0 , 11 ) � ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) � e ( l 0 , 4 ) , e ( l 2 , 2 ) � e ( l 2 , 8 ) , e ( l 1 , 3 ) � , p ( l 1 , 5 ) , p ( l 3 , 1 ) � , p ( l 0 , 4 ) , p ( l 2 , 2 ) � ∗ � e ( l 0 , 11 ) ∗ � e ( l 2 , 8 ) , e ( l 1 , 3 ) , p ( l 0 , 11 ) � ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) � e ( l 0 , 4 ) , e ( l 2 , 2 ) , p ( l 2 , 8 ) , p ( l 1 , 3 ) � , p ( l 1 , 5 ) , p ( l 3 , 1 ) , p ( l 0 , 4 ) , p ( l 2 , 2 ) ... , p ( l 2 , 9 ) , p ( l 2 , 7 ) � , p ( l 0 , 13 ) , p ( l 3 , 5 ) � ... ∗ � e ( l 0 , 11 ) ∗ � e ( l 2 , 8 ) , e ( l 1 , 3 ) , p ( l 0 , 11 ) ... ... , p ( l 0 , 19 ) , p ( l 1 , 3 ) , p ( l 1 , 15 ) ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) � e ( l 0 , 4 ) , e ( l 2 , 2 ) , p ( l 2 , 5 ) � , p ( l 3 , 12 ) � , p ( l 1 , 4 ) , p ( l 2 , 6 ) , p ( l 0 , 4 ) , p ( l 2 , 2 ) , p ( l 3 , 1 ) � , p ( l 3 , 5 ) � How to execute in decentralized manner, yet preserve soundness (w.r.t abstract CHR semantics)?
The CHR e Language � � � � � � � Introduction Operational Semantics Conclusion Multiset Matching in CHR e Rules 4 5 base @ [ X ] edge ( Y , D ) = ⇒ [ X ] path ( Y , D ) l 0 l 1 1 elim @ [ X ] path ( Y , D1 ) \ [ X ] path ( Y , D2 ) ⇐ ⇒ D1 ≤ D2 | true 11 3 8 trans @ [ X ] edge ( Y , D1 ) , [ Y ] path ( Z , D2 )= ⇒ X � = Z | [ X ] path ( Z , D1 + D2 ) l 2 l 3 2 Location l 0 Location l 1 � e ( l 1 , 5 ) , e ( l 3 , 1 ) � � e ( l 0 , 4 ) , e ( l 2 , 2 ) � ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) , p ( l 1 , 5 ) , p ( l 3 , 1 ) � � e ( l 0 , 4 ) , e ( l 2 , 2 ) , p ( l 0 , 4 ) , p ( l 2 , 2 ) � ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) , p ( l 1 , 5 ) , p ( l 3 , 1 ) � e ( l 0 , 4 ) , e ( l 2 , 2 ) , p ( l 0 , 4 ) , p ( l 2 , 2 ) , p ( l 2 , 9 ) , p ( l 2 , 7 ) � , p ( l 0 , 13 ) , p ( l 3 , 5 ) � ... ... ∗ ∗ � e ( l 1 , 5 ) , e ( l 3 , 1 ) , p ( l 1 , 4 ) , p ( l 2 , 6 ) � e ( l 0 , 4 ) , e ( l 2 , 2 ) , p ( l 0 , 4 ) , p ( l 2 , 2 ) , p ( l 3 , 1 ) � , p ( l 3 , 5 ) � Stark difference between base and elim rules, and the trans rule.
Recommend
More recommend