SlideShare a Scribd company logo
On Applying Or-Parallelism and Tabling to Logic Programs Possamai Lino Department of Computer Science University of Venice www.possamai.it/lino Logic Programming Lecture  February 2, 2007
Introduction After introduction of Prolog programming language, many reseachers concentrated their attention to the possibily of turning sequential Prolog interpreter into parallel once in order to speedup applications. This is an interesting area because Prolog allow implicit parallelism, so any code annotation are necessary. Another key-point of this article if the fact that SLD-derivations are not suitable for non-terminating programs (infinite failure) but using another derivation strategy we can assure the termination of a logic program (under certains circumnstances) . Earlier Prolog engine when compute a predicate just encountered, din’t remember the c.a.s. calculated, and so this is a waste of computer resouce. Tabling is the response to this problem.
Parallelism within Prolog while  (Query  ≠ 0) Begin select literal  B from Query; repeat select clause  (H:-Body) from Program; until (unify(H,B) or (no clauses left)); if (no clauses left) then FAIL. else   begin   ∂ =mostgeneralunifier(H,B);   Query=(Query-{B} U {Body})∂   end end.
Parallelism within Prolog These types of parallelism are named as: And-Parallelism   Appears from the non-determinism of the selection rule when more than one subgoal is present in the query or in the body of a clause. Or-Parallelism Derived from the non-determinism of the clause selected when more than one clause is applicable to the same subgoal. Unification Parallelism Appears during the process of unifying the arguments of a subgoal with those of a head clause for the predicate with the same name and arity. Many implementations have been proposed for each type, but only or-parallelism have good performance and simple implementation, so this is the choice of the article’s authors. The main advantages of using or-parallelism despite and-parallelism are: It doesn’t limit the Prolog’s power. It’s easy to extend the Prolog sequential engine to cope with this new feature. Can be exploited without any extra annotation.
Or-Parallelism (YapOr)
An Or-Parallelism Example p(L):-s(L,M),t(M,L). p(K):-r(K). q(1). q(2). s(2,3). s(4,5). t(3,3). t(3,2). r(1). r(3). ?- t(X,3),p(Y),q(Y). p(Y),q(Y) s(L,M),t(M,L),q(L) {X/3} {Y/L} r(K),q(K) {Y/K} t(5,4),q(4) t(3,2),q(2) {L/2,M/3} {L/4, M/5} {K/1} {K/3} q(1) q(3) W1 W1 W2 W1 W3 W2 W4 W1 q(2) Success Fail Success Fail
Or-Parallelism drawbacks Although at the first sight or-parallelism can be considerate an easy task to manage, it has some problems to take into account related to: Multiple binding representation The concurrent execution of alternative branches of the search tree can result in several conflicting bindings for shared variables. Consider, for example, the variable Y in the previous example. In this case, that variable is called conditional variable. Any problem for X variable (called unconditional variable). Work scheduling Even in this case a scheduling is necessary for minimizing the overhead of work assignments. As we know, this is a complex problem because of the dynamic nature of work in or-parallel systems. Before approching to these problems, is necessary to present the underlying level that we can see into each Prolog engine: the Warren Abstract Machine.
Wam, Warren Abstract Machine The Wam is a data structure (stack) necessary to the evaluation of Prolog programs and is widely used in every Prolog engine.. It can be represented as: PDL : area used for unification process. Trail : array of address that points to variables memorized into heap or local stack resetted upon backtracking. Stack : containts  environments  and  choice points . Heap : Memorize variables than can’t be stored in the stack. Code area : contains instruction for wam and Prolog compiled code.
How Or-Parallelism is implemented? Different models were proposed for exploiting or-parallelism, but only two of them are the best one’s. Those models maily differ in the mechanism employed for solving the problem of environment representation and so for the solution to the multiple binding presented above. Environment copying. It’s the most efficient way to cope with the multiple binding problem. We can considerate this techique as the lazy one. Used in some other Prolog engine, for example Sictus, Muse. Binding arrays. Consist on recording conditional bindings in a global data structure and attaching a unique identifier to each binding that identifies the branch to which the binding belongs.
Environment copying In this model, each worker mantains its own copy of the environment in which it can write without causing binding conflicts. When a variable is bound, the binding is stored in the private environment of the worker doing the binding. When a idle worker picks work from another worker, it copies all the stacks from the sharing worker. As a consequence, each worker can carry out execution exactly like a sequential system, requiring very little synchronization. Copying stacks is made efficient using the incremental copying technique. The idea of incremental copying is based on the fact that the idle worker could have already traversed a part of the seach tree that is common to the sharing worker, and thus it does not need to copy this part of stacks. N2 N5 N3 N4 N1 Q P Node without alternatives Node with alternatives Alt 1 Alt 2 Alt 3 Alt 1 Alt 2 Alt 3
Tabling (YapTab)
Tabling (YapTab) SLD-derivations are not suitable for non-terminating programs (infinite loop) but using another derivation strategy we can assure the termination of a logic program (under certains circumnstances) . Multiple calls to the same predicate, within the SLD-derivations, are considered like redundant evaluations. Tabling or memoing is a tecnhique that consist of remembering subcomputations and reusing their results in order to respond to later requests. Although various procedural semantics have been proposed for dealing with tabling, one has been gaining in popularity: SLG resolution.
Tabling (YapTab) Tabling is implemented using tries data structure that permit look up and possibly insertion to be performed in a single pass through a term. Table space can be accessed in different ways: To look up if a subgoal is in the table and if not insert it; To verify whether a newly found answer is already in the table, and if not insert it; To pick up answers to consumer nodes; To mark subgoals as completed. Correct design of the algorithms to access and manipulate the table data is a critical issue to obtain an efficient tabling system implementation. Scheduling is another issue to cope with: at several points the engine had to choose between continuing execution, backtracking, returning answer to  consumer nodes or performing completion.
SLG-resolution To manage tabling, we must expand SLD resolution to deal with tabling. A SLG system is a forest of SLG trees along with an associated  table . Root nodes of SLG trees are subgoals of tabled predicates. A SLG evaluation  Θ of a goal G, given a tabled program P, is a sequence of systems S 0 , S 1 , ... , S n  such that: S 0  is the forest of a single SLG tree rooted by G and the table {(G,emptyset,incomplete)} For each k, S k+1  is obtained from S k  by an application of one of the subsequent operations: New tabled SubGoal Call, Program Clause Resolution, Answer Resolution, New Answer, Completion. The Warren Abstract Machine introduced above, must be extended to cope with these new operations.
?-table path. path(X,Z):-path(X,Y),path(Y,Z). path(X,Z):-arc(X,Z). arc(a,b). arc(b,c). Tabling, an example ?-path(a,Z). path(a,Y),path(Y,Z) arc(a,Z) path(b,Z) path(b,Z) path(b,Y),path(Y,Z) arc(b,Z) path(c,Z) path(c,Z) path(c,Y),path(Y,Z) arc(c,Z) {Z/b} fail fail {Z/c} fail fail fail fail path(a,Z) path(b,Z) path(c,Z) {Z/b} {Z/c} {Z/c} {Z/c} path(c,Z) fail path(a,Y),path(Y,Z) Generator Node Consumer Node Interior Node Answer Subgoal
Or-Parallelism and Tabling (OPTYap) Or-Parallelism within Tabling (OPT) is the model introduced by the autors that allow concurrent execution of all available alternatives. This model is formed by a set of indipendent tabling engine that may share different common branches of the search tree during execution. So, each worker can be considered a sequential tabling engine that fully implement the tabling operations above mentioned. The or-parallel component is triggered to allow synchronized access to the shared parts of the execution tree, in order to get new job when a worker runs out of alternatives to exploit. In the OPT model a worker can keep its nodes private until reaching a sharing point. This is a key issue in reducing parallel overhead. They remark that it is common in or-parallel works to say that work is initially private, and that is made public after sharing. Worker suspension is a common characteristic of Or-P and Tabling. In the former because of side effects, a worker must wait until another worker terminate his job. In the second, arise when a node ask for evaluation of a tabled predicate but in the table this no answer just calculated. Worker are allowed to concurrently read and update the predicate table. To do so, workers need to be able to lock the table. Finer locking allows more parallelism while coarser locking has less overheads.
In this example, W 1  start evaluating the goal a(X). as a sequential  tabling engine should do. It uses the first clause, but there is no answer for the predicate and so it backtracks. At this point it uses the second clause and can calculate the first answer that is inserted in the table. W 1  continues to evaluate the second alternative. Now, suppose that W 2  ask for work and W 1  decide to share all its nodes, so the last b(X) alternative is assigned to W 2 . An OPT Example :-table a/1. a(X):-a(X). a(X):-b(X). b(1). b(X):- … b(X):- … ?-a(X). ?- a(X). a(X) b(X) {X/1} W2 W1 a(X) {X/1}   Shared Nodes Answer Subgoal
Performance, non-tabled programs Now, we are able to analyze what are the execution times of engines considered above (YapOr, YapTab, OPTYap) with respect to Yap, the sequential engine for Prolog programs and respect XSB system, the well know engine for tabling processing. First of all, we can see the performance and speedup of non-tabled programs. In this way, they have measured the overhead introduced by the model when running programs that do not take advantage of the particular extension. In the XSB case, execution times are worst than Yap due to the overhead for managing tabling and or-parallelism (10%, 5%, 17%). Good speedup when consider YapOr and OPTYap.
Performance, tabled programs For a complete analysis of performance, they had considered also tabled programs, in order to see if the YapTab engine is good. Linear speedup are obtained in five of seven programs considered (that represent the usual programs) but in two cases, the sequential version is faster than the parallel. This behaviour is not caused because workers became idle and start seaching for work, as usually happens with parallel execution of non-tabled programs, but there is a lot of the contention to access that work.
Index / References Introduction Parallelism within Prolog Or-Parallelism Example of Or-Parallelism Drawbacks Wam Models of parallelism Environment copy Tabling Example of Tabling SLG resolutions Or-Parallelism within Tabling Example of OPT model Experimental Results Non tabled programs Tabled Programs On Applying Or-Parallelism and Tabling to Logic Programs.  Ricardo Rocha, Fernando Silva and Vitor Santos Costa Theory and Practice of Logic Programming,  Volume 5, Issue 1-2, January 2005, pp 161-205

More Related Content

PPT
2 a stacks
PPT
2 b queues
PPT
1 list datastructures
PDF
Recursion Pattern Analysis and Feedback
PPT
Data structures
PDF
Libro de MATLAB
PPTX
(Recursion)ads
2 a stacks
2 b queues
1 list datastructures
Recursion Pattern Analysis and Feedback
Data structures
Libro de MATLAB
(Recursion)ads

What's hot (20)

PDF
Chap12 scr
PDF
Matlab for beginners, Introduction, signal processing
PDF
A recommender system for generalizing and refining code templates
PDF
New c sharp3_features_(linq)_part_iii
PPT
Fundamentals of matlab
PDF
Matlab-Data types and operators
PDF
Run time storage
PDF
Lesson 6 recursion
PPT
Introduction to data structures and Algorithm
PPTX
4. Recursion - Data Structures using C++ by Varsha Patil
PPT
Data structure
PPTX
application based Presentation on matlab simulink & related tools
PPT
Matlab day 1: Introduction to MATLAB
PDF
Lesson 1 overview
PPT
Introduction of data structure
PPT
MATLAB/SIMULINK for engineering applications: day 3
PPT
Chapter 7 ds
PDF
Scala for Machine Learning
PDF
(chapter 3) A Concise and Practical Introduction to Programming Algorithms in...
Chap12 scr
Matlab for beginners, Introduction, signal processing
A recommender system for generalizing and refining code templates
New c sharp3_features_(linq)_part_iii
Fundamentals of matlab
Matlab-Data types and operators
Run time storage
Lesson 6 recursion
Introduction to data structures and Algorithm
4. Recursion - Data Structures using C++ by Varsha Patil
Data structure
application based Presentation on matlab simulink & related tools
Matlab day 1: Introduction to MATLAB
Lesson 1 overview
Introduction of data structure
MATLAB/SIMULINK for engineering applications: day 3
Chapter 7 ds
Scala for Machine Learning
(chapter 3) A Concise and Practical Introduction to Programming Algorithms in...
Ad

Viewers also liked (17)

PDF
Frida kahlo presentation. mc kaylee miller. 7th hr
DOCX
GUERRERO PACIFISTA
PPT
Voluntary Employee Benefits
PPT
Slashdot.Org
PPTX
Opendag zaterdag 17 maart 2012 otc opleiding & trainingen curacao tony lin...
PPTX
Novo modelo do relatório de responsabilidade socioambiental sff - ganin
PPTX
Spanish presentation
PPS
Para que con tus santos te alabe
PDF
Uprising at Akwesasne by Dr Rugenstein
PDF
HBX Acceptance Letter
PPT
Sesión 2
PDF
Beeline RPO Dossier
DOCX
ENSAYO, PEDRO SANCHEZ ESCOBESDO CAPITULO 1
PDF
Online Classified Ad in Newspaper Whitianga, Mercury Bay | the Mercury Bay In...
PDF
Machine Learning and Data Mining: 08 Clustering: Hierarchical
PPTX
HERENCIA MATERNA O MITOCONDRIAL
Frida kahlo presentation. mc kaylee miller. 7th hr
GUERRERO PACIFISTA
Voluntary Employee Benefits
Slashdot.Org
Opendag zaterdag 17 maart 2012 otc opleiding & trainingen curacao tony lin...
Novo modelo do relatório de responsabilidade socioambiental sff - ganin
Spanish presentation
Para que con tus santos te alabe
Uprising at Akwesasne by Dr Rugenstein
HBX Acceptance Letter
Sesión 2
Beeline RPO Dossier
ENSAYO, PEDRO SANCHEZ ESCOBESDO CAPITULO 1
Online Classified Ad in Newspaper Whitianga, Mercury Bay | the Mercury Bay In...
Machine Learning and Data Mining: 08 Clustering: Hierarchical
HERENCIA MATERNA O MITOCONDRIAL
Ad

Similar to On Applying Or-Parallelism and Tabling to Logic Programs (20)

PDF
Control system Lab record
PDF
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
PDF
Rapport_Cemracs2012
PDF
GRAPH MATCHING ALGORITHM FOR TASK ASSIGNMENT PROBLEM
PPTX
Parallel algorithms
PDF
05 dataflow
PDF
Group Project
PDF
Functional Programming in Scala: Notes
PPTX
DAA-Module-5.pptx
PDF
A Domain-Specific Embedded Language for Programming Parallel Architectures.
PDF
Deep learning concepts
DOCX
Parallel programming Comparisions
PDF
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
PDF
Introduction to OpenMP (Performance)
PDF
A review of automatic differentiationand its efficient implementation
PPTX
Javascript
PPT
Parallel algorithms
PPTX
ScalaDays 2013 Keynote Speech by Martin Odersky
DOCX
Java mcq
Control system Lab record
BARRACUDA, AN OPEN SOURCE FRAMEWORK FOR PARALLELIZING DIVIDE AND CONQUER ALGO...
Rapport_Cemracs2012
GRAPH MATCHING ALGORITHM FOR TASK ASSIGNMENT PROBLEM
Parallel algorithms
05 dataflow
Group Project
Functional Programming in Scala: Notes
DAA-Module-5.pptx
A Domain-Specific Embedded Language for Programming Parallel Architectures.
Deep learning concepts
Parallel programming Comparisions
Open Problems in Automatically Refactoring Legacy Java Software to use New Fe...
Introduction to OpenMP (Performance)
A review of automatic differentiationand its efficient implementation
Javascript
Parallel algorithms
ScalaDays 2013 Keynote Speech by Martin Odersky
Java mcq

More from Lino Possamai (6)

PDF
Music Motive @ H-ack
PDF
Metodi matematici per l’analisi di sistemi complessi
PDF
Multidimensional Analysis of Complex Networks
PDF
Optimization of Collective Communication in MPICH
PPT
A static Analyzer for Finding Dynamic Programming Errors
PPT
Cure, Clustering Algorithm
Music Motive @ H-ack
Metodi matematici per l’analisi di sistemi complessi
Multidimensional Analysis of Complex Networks
Optimization of Collective Communication in MPICH
A static Analyzer for Finding Dynamic Programming Errors
Cure, Clustering Algorithm

Recently uploaded (20)

PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPTX
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PPTX
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
PDF
Network Security Unit 5.pdf for BCA BBA.
PPTX
Digital-Transformation-Roadmap-for-Companies.pptx
PPTX
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
PPTX
Programs and apps: productivity, graphics, security and other tools
PPTX
Cloud computing and distributed systems.
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PDF
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
Empathic Computing: Creating Shared Understanding
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
ACSFv1EN-58255 AWS Academy Cloud Security Foundations.pptx
Unlocking AI with Model Context Protocol (MCP)
Chapter 3 Spatial Domain Image Processing.pdf
Detection-First SIEM: Rule Types, Dashboards, and Threat-Informed Strategy
Network Security Unit 5.pdf for BCA BBA.
Digital-Transformation-Roadmap-for-Companies.pptx
KOM of Painting work and Equipment Insulation REV00 update 25-dec.pptx
Programs and apps: productivity, graphics, security and other tools
Cloud computing and distributed systems.
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
20250228 LYD VKU AI Blended-Learning.pptx
Per capita expenditure prediction using model stacking based on satellite ima...
Spectral efficient network and resource selection model in 5G networks
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
NewMind AI Weekly Chronicles - August'25 Week I
Architecting across the Boundaries of two Complex Domains - Healthcare & Tech...
Diabetes mellitus diagnosis method based random forest with bat algorithm
Empathic Computing: Creating Shared Understanding

On Applying Or-Parallelism and Tabling to Logic Programs

  • 1. On Applying Or-Parallelism and Tabling to Logic Programs Possamai Lino Department of Computer Science University of Venice www.possamai.it/lino Logic Programming Lecture February 2, 2007
  • 2. Introduction After introduction of Prolog programming language, many reseachers concentrated their attention to the possibily of turning sequential Prolog interpreter into parallel once in order to speedup applications. This is an interesting area because Prolog allow implicit parallelism, so any code annotation are necessary. Another key-point of this article if the fact that SLD-derivations are not suitable for non-terminating programs (infinite failure) but using another derivation strategy we can assure the termination of a logic program (under certains circumnstances) . Earlier Prolog engine when compute a predicate just encountered, din’t remember the c.a.s. calculated, and so this is a waste of computer resouce. Tabling is the response to this problem.
  • 3. Parallelism within Prolog while (Query ≠ 0) Begin select literal B from Query; repeat select clause (H:-Body) from Program; until (unify(H,B) or (no clauses left)); if (no clauses left) then FAIL. else begin ∂ =mostgeneralunifier(H,B); Query=(Query-{B} U {Body})∂ end end.
  • 4. Parallelism within Prolog These types of parallelism are named as: And-Parallelism Appears from the non-determinism of the selection rule when more than one subgoal is present in the query or in the body of a clause. Or-Parallelism Derived from the non-determinism of the clause selected when more than one clause is applicable to the same subgoal. Unification Parallelism Appears during the process of unifying the arguments of a subgoal with those of a head clause for the predicate with the same name and arity. Many implementations have been proposed for each type, but only or-parallelism have good performance and simple implementation, so this is the choice of the article’s authors. The main advantages of using or-parallelism despite and-parallelism are: It doesn’t limit the Prolog’s power. It’s easy to extend the Prolog sequential engine to cope with this new feature. Can be exploited without any extra annotation.
  • 6. An Or-Parallelism Example p(L):-s(L,M),t(M,L). p(K):-r(K). q(1). q(2). s(2,3). s(4,5). t(3,3). t(3,2). r(1). r(3). ?- t(X,3),p(Y),q(Y). p(Y),q(Y) s(L,M),t(M,L),q(L) {X/3} {Y/L} r(K),q(K) {Y/K} t(5,4),q(4) t(3,2),q(2) {L/2,M/3} {L/4, M/5} {K/1} {K/3} q(1) q(3) W1 W1 W2 W1 W3 W2 W4 W1 q(2) Success Fail Success Fail
  • 7. Or-Parallelism drawbacks Although at the first sight or-parallelism can be considerate an easy task to manage, it has some problems to take into account related to: Multiple binding representation The concurrent execution of alternative branches of the search tree can result in several conflicting bindings for shared variables. Consider, for example, the variable Y in the previous example. In this case, that variable is called conditional variable. Any problem for X variable (called unconditional variable). Work scheduling Even in this case a scheduling is necessary for minimizing the overhead of work assignments. As we know, this is a complex problem because of the dynamic nature of work in or-parallel systems. Before approching to these problems, is necessary to present the underlying level that we can see into each Prolog engine: the Warren Abstract Machine.
  • 8. Wam, Warren Abstract Machine The Wam is a data structure (stack) necessary to the evaluation of Prolog programs and is widely used in every Prolog engine.. It can be represented as: PDL : area used for unification process. Trail : array of address that points to variables memorized into heap or local stack resetted upon backtracking. Stack : containts environments and choice points . Heap : Memorize variables than can’t be stored in the stack. Code area : contains instruction for wam and Prolog compiled code.
  • 9. How Or-Parallelism is implemented? Different models were proposed for exploiting or-parallelism, but only two of them are the best one’s. Those models maily differ in the mechanism employed for solving the problem of environment representation and so for the solution to the multiple binding presented above. Environment copying. It’s the most efficient way to cope with the multiple binding problem. We can considerate this techique as the lazy one. Used in some other Prolog engine, for example Sictus, Muse. Binding arrays. Consist on recording conditional bindings in a global data structure and attaching a unique identifier to each binding that identifies the branch to which the binding belongs.
  • 10. Environment copying In this model, each worker mantains its own copy of the environment in which it can write without causing binding conflicts. When a variable is bound, the binding is stored in the private environment of the worker doing the binding. When a idle worker picks work from another worker, it copies all the stacks from the sharing worker. As a consequence, each worker can carry out execution exactly like a sequential system, requiring very little synchronization. Copying stacks is made efficient using the incremental copying technique. The idea of incremental copying is based on the fact that the idle worker could have already traversed a part of the seach tree that is common to the sharing worker, and thus it does not need to copy this part of stacks. N2 N5 N3 N4 N1 Q P Node without alternatives Node with alternatives Alt 1 Alt 2 Alt 3 Alt 1 Alt 2 Alt 3
  • 12. Tabling (YapTab) SLD-derivations are not suitable for non-terminating programs (infinite loop) but using another derivation strategy we can assure the termination of a logic program (under certains circumnstances) . Multiple calls to the same predicate, within the SLD-derivations, are considered like redundant evaluations. Tabling or memoing is a tecnhique that consist of remembering subcomputations and reusing their results in order to respond to later requests. Although various procedural semantics have been proposed for dealing with tabling, one has been gaining in popularity: SLG resolution.
  • 13. Tabling (YapTab) Tabling is implemented using tries data structure that permit look up and possibly insertion to be performed in a single pass through a term. Table space can be accessed in different ways: To look up if a subgoal is in the table and if not insert it; To verify whether a newly found answer is already in the table, and if not insert it; To pick up answers to consumer nodes; To mark subgoals as completed. Correct design of the algorithms to access and manipulate the table data is a critical issue to obtain an efficient tabling system implementation. Scheduling is another issue to cope with: at several points the engine had to choose between continuing execution, backtracking, returning answer to consumer nodes or performing completion.
  • 14. SLG-resolution To manage tabling, we must expand SLD resolution to deal with tabling. A SLG system is a forest of SLG trees along with an associated table . Root nodes of SLG trees are subgoals of tabled predicates. A SLG evaluation Θ of a goal G, given a tabled program P, is a sequence of systems S 0 , S 1 , ... , S n such that: S 0 is the forest of a single SLG tree rooted by G and the table {(G,emptyset,incomplete)} For each k, S k+1 is obtained from S k by an application of one of the subsequent operations: New tabled SubGoal Call, Program Clause Resolution, Answer Resolution, New Answer, Completion. The Warren Abstract Machine introduced above, must be extended to cope with these new operations.
  • 15. ?-table path. path(X,Z):-path(X,Y),path(Y,Z). path(X,Z):-arc(X,Z). arc(a,b). arc(b,c). Tabling, an example ?-path(a,Z). path(a,Y),path(Y,Z) arc(a,Z) path(b,Z) path(b,Z) path(b,Y),path(Y,Z) arc(b,Z) path(c,Z) path(c,Z) path(c,Y),path(Y,Z) arc(c,Z) {Z/b} fail fail {Z/c} fail fail fail fail path(a,Z) path(b,Z) path(c,Z) {Z/b} {Z/c} {Z/c} {Z/c} path(c,Z) fail path(a,Y),path(Y,Z) Generator Node Consumer Node Interior Node Answer Subgoal
  • 16. Or-Parallelism and Tabling (OPTYap) Or-Parallelism within Tabling (OPT) is the model introduced by the autors that allow concurrent execution of all available alternatives. This model is formed by a set of indipendent tabling engine that may share different common branches of the search tree during execution. So, each worker can be considered a sequential tabling engine that fully implement the tabling operations above mentioned. The or-parallel component is triggered to allow synchronized access to the shared parts of the execution tree, in order to get new job when a worker runs out of alternatives to exploit. In the OPT model a worker can keep its nodes private until reaching a sharing point. This is a key issue in reducing parallel overhead. They remark that it is common in or-parallel works to say that work is initially private, and that is made public after sharing. Worker suspension is a common characteristic of Or-P and Tabling. In the former because of side effects, a worker must wait until another worker terminate his job. In the second, arise when a node ask for evaluation of a tabled predicate but in the table this no answer just calculated. Worker are allowed to concurrently read and update the predicate table. To do so, workers need to be able to lock the table. Finer locking allows more parallelism while coarser locking has less overheads.
  • 17. In this example, W 1 start evaluating the goal a(X). as a sequential tabling engine should do. It uses the first clause, but there is no answer for the predicate and so it backtracks. At this point it uses the second clause and can calculate the first answer that is inserted in the table. W 1 continues to evaluate the second alternative. Now, suppose that W 2 ask for work and W 1 decide to share all its nodes, so the last b(X) alternative is assigned to W 2 . An OPT Example :-table a/1. a(X):-a(X). a(X):-b(X). b(1). b(X):- … b(X):- … ?-a(X). ?- a(X). a(X) b(X) {X/1} W2 W1 a(X) {X/1} Shared Nodes Answer Subgoal
  • 18. Performance, non-tabled programs Now, we are able to analyze what are the execution times of engines considered above (YapOr, YapTab, OPTYap) with respect to Yap, the sequential engine for Prolog programs and respect XSB system, the well know engine for tabling processing. First of all, we can see the performance and speedup of non-tabled programs. In this way, they have measured the overhead introduced by the model when running programs that do not take advantage of the particular extension. In the XSB case, execution times are worst than Yap due to the overhead for managing tabling and or-parallelism (10%, 5%, 17%). Good speedup when consider YapOr and OPTYap.
  • 19. Performance, tabled programs For a complete analysis of performance, they had considered also tabled programs, in order to see if the YapTab engine is good. Linear speedup are obtained in five of seven programs considered (that represent the usual programs) but in two cases, the sequential version is faster than the parallel. This behaviour is not caused because workers became idle and start seaching for work, as usually happens with parallel execution of non-tabled programs, but there is a lot of the contention to access that work.
  • 20. Index / References Introduction Parallelism within Prolog Or-Parallelism Example of Or-Parallelism Drawbacks Wam Models of parallelism Environment copy Tabling Example of Tabling SLG resolutions Or-Parallelism within Tabling Example of OPT model Experimental Results Non tabled programs Tabled Programs On Applying Or-Parallelism and Tabling to Logic Programs. Ricardo Rocha, Fernando Silva and Vitor Santos Costa Theory and Practice of Logic Programming, Volume 5, Issue 1-2, January 2005, pp 161-205