• Like
  • Save
On Applying Or-Parallelism and Tabling to Logic Programs
Upcoming SlideShare
Loading in...5
×

Thanks for flagging this SlideShare!

Oops! An error has occurred.

On Applying Or-Parallelism and Tabling to Logic Programs

  • 1,343 views
Published

Lecture about Or-Parallelism and Tabling applied to Logic Programming

Lecture about Or-Parallelism and Tabling applied to Logic Programming

Published in Technology
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
No Downloads

Views

Total Views
1,343
On SlideShare
0
From Embeds
0
Number of Embeds
1

Actions

Shares
Downloads
0
Comments
0
Likes
3

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 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.
  • 5. Or-Parallelism (YapOr)
  • 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
  • 11. Tabling (YapTab)
  • 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