Combining depth-first and breadth-first search in Prolog execution

Size: px
Start display at page:

Download "Combining depth-first and breadth-first search in Prolog execution"

Transcription

1 Combining depth-first and breadth-first search in Prolog execution Jordi Tubella and Antonio González Departament d Arquitectura de Computadors Universitat Politècnica de Catalunya, Campus Nord UPC, C/. Gran Capità, s/n., Edifici D Barcelona, Spain jordit@ac.upc.es Tel: Fax: ABSTRACT A new model for the execution of Prolog programs, called MEM (Multipath Execution Model), which combines a depth-first and breadth-first exploration of the search tree is presented. The breadth-first search allows more than one path (multiple potential solutions) to be explored at the same time. In this way, the computational cost of traversing the whole search tree associated to a program can be decreased because the MEM model reduces the overhead due to the execution of control instructions. This paper focuses on the description of the MEM model and its sequential implementation. Moreover, the MEM execution model can easily extended to exploit a new kind of parallelism, called path parallelism, which allows the parallel execution of unify operations related to simultaneously explored paths. Since these operations do not have any dependence among them, this type of parallelism can always be exploited. An architecture (PMA) to implement the MEM execution model on a parallel environment is also presented. PMA looks like a SIMD machine, with a Control Processor (CP), responsible for traversing the whole search tree, and several Unification Functional Units (UFUs), responsible for performing unify operations. KEYWORDS Execution models, depth-first search, breadth-first search, data parallelism, SIMD architecture. 1

2 1 INTRODUCTION Logic programming languages and, concretely, Prolog, as its most representative member, offer elegant features to write symbolic applications. Research in this area tries to design new execution models and specific architectures in order to achieve a more efficient execution of that kind of applications. This is also the objective of this paper. A Prolog program consists of a set of clauses and a query. From a declarative point of view, a program determines if the query can be inferred from the clauses for some variable bindings [7]. From a procedural point of view, the execution consists of applying inference steps to a resolvent, which initially is the program query, until it becomes empty. An inference step tries to unify the left-most goal in the resolvent with a clause whose head has the same predicate name and arity. In case there are more than one candidate clause to unify, clauses are tried in the order they are written. When the unification is successful, an inference has been performed and the left-most goal in the resolvent is substituted by all subgoals in the body of the clause. Then, execution attempts another inference step. When the unification fails, the backtracking process allows to try another inference step for the youngest goal that still has some candidate clauses to unify with. These are the basic points of the standard depth-first left-to-right sequential execution of a Prolog program [6]. Most sequential architectures oriented to Prolog are based on the Warren s Abstract Machine (WAM) [1]. This machine defines a set of data types, registers, memory areas, and instructions to implement the standard depth-first execution model of Prolog. WAM instructions can be divided in control instructions, which are responsible for managing the traversal of the SLD-tree related to a program, and unify instructions, which perform the basic unification operation of Prolog semantics. The main contribution of this abstract machine has been the description of the implicit control component in a Prolog program in an imperative way. This allowed the change from an interpretative execution of Prolog programs to the execution of compiled WAM code. WAM implementations map the abstract machine into a general purpose computer architecture or design specific architectures to execute more efficiently WAM programs [5]. A disadvantage of the standard execution comes from the repeated computation of the same resolvent after a new solution to a goal is found. Different executions of a given goal of the same resolvent operate on different binding environments corresponding to different paths of the search tree, but the repeated execution of the same control instructions is a source of overhead. A new model, called Multipath Execution Model (MEM), that overcomes this overhead by allowing to explore more than one path of the search tree at the same time, is proposed in this paper. In this model, control instructions are executed only once for all paths being simultaneously explored, while unification instructions are repeated for each path. The way to achieve the exploration of more than one path at the same time is allowing a goal to be traversed in breadth-first order. In this way, the breadth execution of a goal tries to find all solutions to that goal before proceeding with the next goal. The drawback of a breadth-first search is that the computation state related to all the paths being simultaneously explored must be stored in memory. So, due to the limitation of available memory, an exhaustive breadth exploration may not be feasible and a partial breadth-first search combined with a depth-first search and backtracking can be more adequate. When a certain number of potential solutions has been obtained, the execution shifts from a breadth-first to a depth-first search. Apart from the advantage of avoiding the execution of control instructions, an additional 2

3 benefit of the MEM execution model is the possibility of performing parallel unifications. A parallel unification unifies two Prolog terms for all paths being simultaneously traversed. The unifications performed in each path are independent because each path has its own binding environment stored in memory. We call this type of parallelism path parallelism. Path parallelism is different from unification parallelism [2]. In unification parallelism, parallel unifications are performed on different arguments of a goal for a single binding environment. In this case, there may be data dependences among the unifications. In path parallelism, the parallel execution corresponds to unifications of the same argument for different binding environments. In this case there are no data dependences. Path parallelism should not be confused with data parallelism. Data parallelism consists in the concurrent treatment of multiple bindings of a variable. After binding a variable to multiple values, execution can continue in parallel exploring subtrees in an independent way. For each one of these subtrees, just one of the bindings is visible. In path parallelism, variables get multiple bindings as a result of the execution of a non-deterministic goal. When all bindings are collected, parallelism is exploited when unify operations are performed on variables with multiple bindings. A preliminary definition of the MEM execution model was presented in [10]. In [8] D. A. Smith presents Multilog as a data parallel language that computes solutions to any arbitrary goal into a set of environments, and subsequent goals execute in this set of environments, with unification being performed in parallel. Multilog and MEM have been carried out concurrently but independently. They have similar objectives although their implementations are rather different. Another related work is the DAP Prolog system proposed in [3]. This proposal extends the standard implementation of Prolog in order to support sets of data and exploits data parallelism for managing the different elements of a set. Again, the same differences explained before between data and path parallelism exists between DAP and MEM. In addition, the source of parallelism in DAP is due only to facts while, in MEM, multiple bindings to the same variable can be obtained as a result of any type and number of clauses. In this paper, the MEM execution model and a sequential implementation are described. In addition, an architecture (PMA) to fully exploit a parallel execution of MEM is introduced. The paper is organized as follows. Section 2 reviews the standard depth-first execution model of Prolog and its implementation using WAM. Section 3 describes the Multipath Execution Model, along with several issues of its implementation. Section 4 compares a sequential execution of both models. Section 5 describes the parallel execution of MEM, and finally, the main conclusions are described in section 6. 2 DEPTH-FIRST EXECUTION OF PROLOG In this section, the standard depth-first left-to-right execution model of a Prolog engine, and its implementation using the Warren s Abstract Machine (WAM) are reviewed. 2.1 Standard execution model In the standard execution model, the computation state, which identifies the state of a Prolog engine at each moment, is represented by means of a resolvent R, a binding environment BE, and a stack of goals SG, that is, CS = {R, BE, SG} 3

4 goal_selection f_clause_selection b_clause_selection success unification success inference fail fail backtracking Figure 1: Basic execution loop of a Prolog engine based on the standard model. where R contains the remaining goals to solve the program query, BE contains all bindings performed by unification operations since the start of the execution, and SG contains elements of the form {R, BE}, representing resolvents and their associated binding environments that can lead to alternative program solutions. Initially, R is the program query, and BE and SG are empty. CS initial = {R = {program_query}, BE =, SG = } Given a resolvent R = {G 1, G 2,..., G n }, a solution to goal G 1 is found when the resolvent becomes R = {G 2,..., G n }. A solution to the program is found when R becomes empty, and the substitutions to the variables are obtained through BE. All solutions are found when R and SG are empty. A Prolog engine continually performs inference attempts on R in order to find a program solution, as shown in figure 1. The computation of all solutions to a program corresponds to a depth-first left-to-right traversal of the associated SLD-tree. The update of the computation state at each inference attempt and the SLD-tree traversal are performed as follows. Given a resolvent R = {G 1, G 2,..., G n }, goal_selection chooses the left-most goal in R (G 1 ), attempting to perform an inference by means of its unification with a clause head having the same predicate name and arity. F_clause_selection chooses the first written candidate clause. If there are no candidate clauses, the backtracking process is started. If there is more than one candidate clause, the resolvent (R) and the binding environment (BE) are pushed onto SG. This point corresponds to a node in the SLD-tree, which has as many child branches as candidate clauses to unify with goal G 1. Then, execution continues unifying goal G 1 with the head of the chosen clause G 1 :- G 11, G 12,..., G 1m. The unification operation determines whether these two first-order predicates match and, in that case, computes the most general unifier. If the unification succeeds, an inference has been performed. Bindings of the most general unifier are added to BE and goal G 1 in R is substituted by all the subgoals in the body of the clause, that is the resolvent becomes R = {G 11, G 12, G 1m, G 2,..., G n }. Then, execution continues attempting another inference in R. If the unification of G 1 and the G 1 fails, the backtracking operation updates R and BE with the value of the topmost element in S. Then, b_clause_selection chooses the next candidate clause not tried yet to unify with the left-most goal in R. In the case that this clause 4

5 is the last candidate to unify with, the topmost element in SG is popped. Then, execution continues with another unification operation. Figure 2 shows the SLD-tree associated to a sample program and the computation state after the second inference. 2.2 Implementation based on the WAM The Warren s Abstract Machine (WAM) has become a widely accepted architectural model to implement the standard Prolog depth-first left-to-right execution model. This abstract machine consists of the following basic architectural elements: Prolog terms: variables, constants, structures and lists. Data structures: choice points, which contain information about the elements pushed on SG; and environments, which contain permanent variables and information to update R when a solution to a goal is found.?- p, q, r. WAM EXAMPLE p :- p1, p2. p11. q. p :- p3. p12. q. p. p13. r. p1 :- p11, p12, p13. p2. p1. p3. a) Sample program (goal arguments are not shown). q p1 q p q q R = {p11, p12, p13, p2, q, r} SG = stack[{{p, q,r},be}, {p1,p2,q,r},be}} BE= {{variable/binding},...} b) SLD-tree c) Computation state after the second inference CODE STACK HEAP TRAIL CP P?- p:- p:- p. p1:- p p q r p1 p2 p3 p11 p12 p13 E B ENVIRONMENT?- CP CHOICE POINT p ENVIRONMENT p CP CHOICE POINT p1 HB H lists structures unsafe vars. bound variables d) WAM representation of the computation state after the second inference Figure 2: SLD-tree, computatation state and its representation in the WAM. 5

6 is Memory areas: code, which contains the WAM code and a table with the strings representing the atoms of the program; heap, which contains compound terms and unsafe variables; stack, which contains choice points and environments; and trail, which is a stack of addresses of bound variables used by the backtracking process. Registers: P and CP, which are pointers to the code area; E, which points to the current environment; B, which points to the current choice point; B0, which is used to implement the search tree pruning performed by a cut operator; H and HB, which are pointers to the heap; TR, which points to the topmost element in the trail; and A i, which contain the argument terms of a goal and temporary terms. Instruction set: WAM instructions can be classified in control instructions, which manage choice points, environments, execution flow, creation of terms, etc.; unify instructions, which perform the basic unification process between two terms; and indexing instructions, an optimization issue oriented to reduce the number of candidate clauses to unify with a goal depending on the type of the arguments. Let us suppose the computation state CS = {R, BE, SG} in a certain moment of the execution R = {G 111, G 112,..., G 11n, G 12,..., G 1m, G 2,..., G l } SG = {{R G11, BE G11 }, {R G1, BE G1 }} BE = {{variable/binding},... } Its representation and the implementation of the basic operations using the WAM are detailed next. A graphic view of the computation state for a particular case can be seen in figure 2.d. Representation of R: WAM instructions for the goals in the resolvent are stored in the code area. Register P points to the left-most goal in the resolvent G 111 ; the rest of the goals belonging to the same clause are sequentially accessed; register CP points to the goal to be executed when all the subgoals belonging to the current clause are solved G 12 ; and environments store the addresses of the remaining goals {G 2 }. Representation of SG: Elements in SG of the form {R, BE} are stored in choice points. R is identified by storing in the choice point the contents of registers A i, CP and E. Obviously, a complete copy of BE is not stored due to the amount of memory it needs. Only the necessary information to restore a BE in backtracking is stored in a choice point. Representation of BE: Bindings of variables are stored in different memory areas depending on the type of the variable. There are three types of variables: temporary, which are variables used only by one goal of a clause, and stored in registers A i ; permanent, which are variables used by more than one goal, and stored in environments; and unsafe variables, which are permanent variables when the environment where they are located is eliminated. These variables are stored in the heap. Also note that when a variable binding is a compound term (list or structure), the elements of the compound term are stored in the heap. Thus, the bindings of variables are stored in the heap, in the environments, or in registers A i. To obtain the substitution of a variable, a dereference operation follows the chain of bindings that unifications may have created. Implementation of clause selection: There are three control instructions to implement clause selection: TRY, RETRY and TRUST. TRY is executed in f_clause_selection when a choice point is to be created. It stores the address of the next candidate clause in the choice point. RETRY and TRUST are executed in b_clause_selection, the former when there are more than one candidate clause to try, and the latter when there is only one. 6

7 In that case, the choice point is removed. Clause selection is performed by updating register P with the initial address of the clause, stored in the choice point. Implementation of unification: Arguments of the goal to be unified are stored in registers A i. The unification is done argument by argument by different WAM instructions. Whenever an argument in the head of the clause is a ground term, WAM optimizes the unification with specific instructions. If the argument is a compound term, their elements are sequentially unified. When the argument in the head of the clause is not a ground term, a call to the general unification procedure is performed. This procedure uses a small stack, called PDL, when both arguments are compound terms. Bindings obtained by the unification are stored directly in BE. To implement the restoring of BE in backtracking, addresses of variables to be bound are stored in the trail if the variable may be later unbound, that is, if it is younger than the current choice point. To do this, register HB and B are used to know which variables are older than the current choice point. Implementation of backtracking: The basic backtracking function is to update R and BE in the computation state with the topmost element in SG. R is updated getting registers A i, CP and E from the current choice point. BE is restored by untrailing the variables bound since the creation of the current choice point. Backtracking also performs garbage collection. In the heap memory, it is done by updating register H to the value it had when the current choice point was created, while in the stack and trail memories is implicitly done by their LIFO structure. One disadvantage we want to stress about the standard execution model is the repeated computation of the same resolvent for each solution of the same goal. Given the resolvent R={G 1, G 2,..., G n }, each solution of goal G 1 proceeds to solve the same resolvent R ={G 2,..., G n }. For different executions of R, unify instructions operate with bindings belonging to different BEs but the same control instructions are repeated in each execution of R. This is a source of overhead due to the restriction of executing only one path of the search tree at the same time imposed by the depth-first search. 3 PARTIAL BREADTH-FIRST EXECUTION OF PROLOG In the previous section, the repeated execution of the same control instructions has been identified as a source of overhead in the standard execution model. This overhead could be avoided if goals were allowed to be executed in breadth-first order, although a new overhead may appear to manage the breadth execution. Traditionally, a breadth-first search has not been considered for an efficient Prolog execution due to the amount of memory needed to implement it and the additional overhead to manage it. Nevertheless, its advantages may encourage further work. In this section, a combined depth-first and breadth-first execution model, and the main issues when implementing it are presented. 3.1 Multipath Execution Model (MEM) The main objective of the Multipath Execution Model (MEM) is to traverse more than one path of the SLD-tree at the same time. In order to make that possible, it is necessary to explore some paths of the search tree in breadth-first order until a point where all those paths share the same resolvent. As stated before, this point corresponds to the solution of a goal. In this point, all the paths are joined and execution proceeds to explore them simultaneously. The MEM model requires an attribute for each goal in a resolvent that specifies the kind of search for that goal: depth-first or breadth-first. Intuitively, the goals that may be explored in breadth-first order are those that have a large number of solutions, because the reduction in 7

8 the overhead of executing control instructions may be greater than the overhead imposed by the breadth management. The programmer, who has a detailed knowledge of his program, should specify the kind of search for each goal of the program. Alternatively, this could be done by the compiler, but whether it could do this task effectively is an open question that remains to be studied. The implicit value of this attribute is depth-first. A goal to be searched in breadth-first order must be preceded by a breadth operator. The model does not impose any modification on the standard Prolog semantics, and syntax must be only modified to include this new operator. Apart from this, for the MEM description we will refer to a MAX_PATHS parameter, which corresponds to the maximum number of paths that can be traversed at the same time during the execution. In the MEM execution model there are two kind of paths: CURRENT paths, which are those being traversed with the objective to become solutions to a breadth goal or to the program; and SOLUTION paths, which are those paths suspended as solutions to previous breadth goals. The computation state in the MEM model is now represented by the current breadth goal CBG, the current resolvent CR, a set of current binding environments SCBE, a set of breadth goals SBG, and a stack of goals SG, that is CS MEM = {CBG, CR, SCBE, SBG, SG} The function of each element of the computation state is next detailed. The computation state for a sample program is shown in figure 5.c. CBG specifies the breadth goal being solved, and consists of two elements: CBG = {NR, BNL}. A breadth goal is identified by the resolvent once the breadth goal is solved (NR), and the breadth nesting level (BNL). The objective of NR is to identify the point where the breadth goal is invoked, and the objective of BNL is to identify different instances of recursive breadth goals, when they are the last goal of a clause. CR specifies the remaining goals to solve CBG. SCBE contains the binding environments corresponding to the CURRENT paths. SBG contains information about breadth goals with pending alternatives to explore. This information consists of three elements: SBG = {BG, SSBE, NBG}. BG is the identification of the breadth goal; SSBE are all the binding environments associated to the SOLUTION paths already found to the breadth goal; and NBG is the next breadth goal to solve once BG is solved. SG is a stack of goals with pending clauses to try. Each element is of the form {BG, R, SBE}. BG is a breadth goal with pending clauses; R is the resolvent to solve BG; and SBE are the binding environments associated to the paths that are visible for that goal. Initially, one path is explored with its binding environment empty, and SG and SBG are empty. CS MEM,initial = {CBG = {,0}, CR = {program_query}, SCBE = { }, SBG =, SG = } A breadth goal CBG is said to be solved when CR becomes empty, and there are as many solutions to CBG as elements in SCBE. Each element in SCBE when goal CBG={,0} is solved corresponds to a solution to the program. All solutions to a program are found when CBG= {,0}, CR=, SG=, and SBG=. As in the standard execution model, a Prolog engine based on MEM continually performs 8

9 goal_selection f_clause_selection success unification success b_clause_selection fail fail inference no breadth_goal_solved? yes breadth? yes backtrack? no no yes join_of_paths backward Figure 3: Basic operations of a Prolog engine based on the MEM model. inference attempts over the computation state. The basic MEM operations are summarized in figure 3 and explained in the next paragraph. In addition, the representation of the MEM-tree associated to the execution of a program is also explained. In fact, a MEM-tree is another way to represent a SLD-tree, with the characteristics that the same SLD-tree can have more than one equivalent MEM-tree, depending on the value of MAX_PATHS. Figure 4 depicts the shape of a general MEM-tree and figure 5.b shows the particular MEM-tree for the same sample program used in figure 2, where some goals have been annotated to be breadth searched. In that example, MAX_PATHS may be any number greater than 8. Goal_selection inference. selects the left-most goal in CR in order to attempt to perform an F_clause_selection selects a clause to be unified with the left-most goal in the resolvent. In case there are more than one candidate clause, they are tried in the order they are written. Let us suppose that the resolvent of the computation state in a certain moment is CR={G 1, G 2,..., G n } and the first candidate clause to try is G 1 :- G 11,..., G 1m. If G 1 has a breadth attribute, a new breadth goal is added to SBG with no solutions found so far, and CBG and CR are updated: SBG SBG {G 1,, CBG} CBG G 1 = {{G 2,..., G n } NR CBG, BNL CBG +1} CR {G 1 } If there are more than one candidate clause to unify with, {CBG,CR, SCBE} is pushed onto SG. This point corresponds to a node in the MEM-tree. We represent the nodes related to breadth goals with a triangular shape. Execution continues unifying G 1 with G 1. Unification is performed for every CURRENT path, that is, one for every element in SCBE. The unification operation fails if each local unification fails, otherwise succeeds. 9

10 BNL = 2 BNL = 1 Pending Alternatives BNL = 0 BNL = 3 CURRENT paths SOLUTION paths Figure 4: Shape of a general MEM-tree. Binding environments related to failed paths are eliminated from SCBE. If unification succeeds, the number of inferences carried out is equal to the number of CURRENT paths. The left-most goal in the resolvent is substituted by all the subgoals in the body of the clause, and bindings representing the most general unifier performed in each path are added to the corresponding element in SCBE: CR {body(c), G 2,..., G n } SCBE {BE 1 θ 1,..., BE p θ p } Whenever the current resolvent in the computation state becomes empty the breadth goal CBG is solved. This point is represented with a square node in the MEM-tree. At this time, it is decided whether the execution continues with a breadth-first or a depth-first exploration of the MEM-tree, that is, with a backward or a join_of_paths operation. Breadth exploration is possible if two conditions are held. The first condition restricts the breadth-first search to those cases where it is helpful, that is, the topmost element in SG can lead to more solutions to the same breadth goal. The second condition restricts the breadthfirst search to MAX_PATHS paths. If the sum of the number of CURRENT and SOLUTION paths in the case another MEM-tree branch was taken exceeded MAX_PATHS, the breadth-first search would not be allowed. This restriction is introduced in the execution model for implementation reasons. Thus, the memory requirements of a given implementation can be 10

11 controlled by the MAX_PATHS parameter. In the MEM model, when a unification fails, execution does not continue immediately with a backtracking operation. There is a backtrack condition that considers the existence in SBG of a breadth goal with SOLUTION paths and no possibility to obtain more solutions. In this case, a join_of_paths operation is executed. Otherwise, a backward operation is executed. The join_of_paths operation joins all SOLUTION paths found so far to the youngest breadth goal of the MEM-tree, and become CURRENT paths. This action is represented with a dashed line in the MEM-tree. The join_of_paths also updates CR and CBG: SCBE SCBE SSBE SBG(CBG) CR NR CBG CBG NBG SBG(CBG) The backward operation is performed if the breadth or the backtrack condition allows to explore the youngest branch alternative of the MEM-tree. The main actions of the backward operation are to store any CURRENT path as a SOLUTION path in SBG, and to restore the computation state with the value of the topmost element in SG: SBG {BG 1,..., {CBG, {SSBE SCBE}, NBG},...,BG s } CBG, CR, SCBE topmost(sg, {BG, R, SBE}) B_clause_selection selects the next candidate clause to be unified with the left-most goal in CR. In case this clause is the last one, the topmost element is SG is popped. 3.2 Implementation issues of the MAM The abstract machine to execute MEM, called Multipath Abstract Machine (MAM), is based on the WAM. The main differences that have been introduced are the following. A new memory area, called MBE (Multi-Binding Environment), is added, with space to store MAX_PATHS binding environments. This memory is divided into three sections: UNSAFE, containing bindings of unsafe variables; PERM, containing bindings of permanent variables; and TRAIL, containing information to restore the state of a binding environment. In MAM, all variables may have multiple bindings, and the address of a variable is an index to MBE and it is the same for all the binding environments. The dereference operation takes a variable and an index to MBE and returns its substitution for a specific binding environment. There are two new registers HV and EV pointing to the first free variable in MBE_UNSAFE and MBE_PERM, respectively, and a new register vector TR[MAX_PATHS] pointing to the top of MBE_TRAIL for each binding environment. An additional global structure is needed to store SBG. This structure does not contain explicitly the binding environments for previously computed solutions to breadth goals, but indices to the binding environments in MBE. The MAM instructions are the same as in the WAM but their semantics are slightly modified in order to manage multiple binding environments. Those instructions referencing a variable must repeat its operation for every element in SCBE. To implement indexing instructions in a more efficient way, a new data structure is needed, called switch point. A switch point is pushed onto the STACK when a SWITCH_ON_TERM instruction is executed, and behaves like a choice point. The number of child alternatives of a switch point corresponds to the number of different Prolog terms that the first argument register is bound to. Each CURRENT path when creating a switch point is traversed in only one branch alternative, and 11

12 ?- breadth p, breadth q, r. MAM EXAMPLE p :- breadth p1, p2. p11. q. p :- p3. p12. q. p. p13. r. p1 :- p11, p12, p13. p2. p1. p3. a)sample program breadth node solution join of paths p1 p CBG = p1 CR = {p11, p12, p13} SCBE= {BE 0 } SBG = {{ p,{},?- }, {p1,{}, p} SG=stack[{p,{p},{BE 0 }}, {p1, {p1}, {BE 0 }}] q where breadth goals are?- = {,0} p = {{q,r},1} p1 = {{p2, q, r}, 2} b) MEM-tree c) Computation state after the second inference BE i CODE (P, CP) SBG (CBG) HEAP (H, HB) STACK (E, B, B0) MBE_UNSAFE (HV) MBE_PERM (EV) MBE_TRAIL (TR[]) MAX_PATHS d) Memory areas and main registers in MAM. Figure 5: A MEM-tree, a MAM computation state, and MAM memory areas and registers. backtracking operations are never performed when taking an alternative from a switch point. HEAP memory in MAM stores only compound terms, while STACK memory stores choice points, environments and switch points. Figure 5.d shows a graphic view of the memory areas and main registers used by MAM. An important issue is the efficiency in implementing the backward operation. This operation restores the computation state with the value of the topmost element in SG, that is, from the topmost choice point in the STACK memory. If the path to be restored is a SOLUTION path, a new BE must be allocated from MBE in order to store the bindings for another path. The new allocated BE becomes the SOLUTION path, after copying the contents of the 12

13 Benchmark WAM MAM MAX_PATHS Speed-up cube tri waltz queens bits bits-pal Table 1: Running times (seconds) for sequential WAM and MAM emulators. MAX_PATHS refers to the value the MAM emulator behaves better. previous SOLUTION path, and this previous SOLUTION path becomes CURRENT, after performing the backtracking operation. If the path to be restored had failed in previous unifications, it becomes CURRENT after the backtracking process. This means that BEs associated to failed paths are not eliminated from memory while it is possible to require the restoration of its contents, that is, the path is stored in a previous choice point. 4 COMPARISON WAM vs. MAM We have implemented sequential emulators for both WAM and MAM abstract machines. A set of benchmark programs have been run on a workstation based on an ALPHA AXP microprocessor in order to measure its different behavior. The benchmarks are: cube, which solves the Instant Insanity puzzle from [9] (64 solutions); tri, being the triangle program (structure version) of Evan Tick (133 solutions); waltz, performing a line labeling problem (8640 solutions); queens8, that finds all ways to place 8 queens in a chess board without attacking among them; bits, that computes all lists of 17 binary elements ( solutions); and bits-pal, that finds all palindromic lists of 17 binary elements using linear time reverse (512 solutions). The last two benchmarks were taken from [8]. Results are shown in table 1. We can observe that the sequential breadth-first execution performed by MAM may be advantageous over a standard WAM implementation. Note that the figures presented in table 1 compare two different execution models running on the same hardware. Therefore, the improvements achieved by MAM, although not spectacular, are significant since they are obtained without any additional hardware. In the next section, we will show that this improvement can be magnified by a implementation in a parallel environment. The possible gain of MAM over WAM depends on the ratio of control instructions over total instructions executed, the overhead imposed by the breadth implementation, and the number of solutions to breadth goals. The advantage of a sequential execution of MEM relies on avoiding the execution of control instructions. If the number of control instructions and the number of solutions of breadth goals is high enough, it may overcome the overhead imposed by the breadth-first exploration. Results confirm the feasibility of an execution model based on a combined depth-first and breadth-first search. 5 PARALLEL EXECUTION OF MEM In addition to the advantage of avoiding the execution of control instructions, another benefit of the MEM execution model is the possibility of executing in parallel the unification 13

14 operations needed to unify two Prolog terms for each binding environment in the computation state. We call this kind of parallelism path parallelism. The sources of parallelism [4] most related to path parallelism are unification parallelism and data parallelism. In unification parallelism, parallel unifications are related to different arguments of a goal for a single binding environment. In this case, there may be data dependences among the unifications. In path parallelism, the parallel execution corresponds to unifications of the same argument for different binding environments. In this case there are no data dependences. Moreover, memory accesses do not conflict when accessing different binding environments if each one is stored in different local memories. In data parallelism, parallel processes explore the same subtree for different values of the same variable. In this way, data parallelism is called sometimes data-or parallelism. In path parallelism, parallel operations correspond to the access or unification of multiple binding variables. Path parallelism leads to finer granularity tasks than data parallelism. Figure 6 shows an overview of the Parallel Multipath Architecture (PMA) proposed for a parallel execution of the MEM model. It consists of a Control Processor (CP) and Unification Functional Units (UFUs). The CP memory stores global data: CODE, SBG, HEAP and STACK; while UFUs local memories store binding environments. In this way, the MBE is distributed over the UFUs. The system has some similarities with SIMD machines. The CP is responsible for traversing the search tree. When executing an instruction that accesses a variable, a command is delivered to those UFUs related to the paths being currently traversed. The CP must wait for the completion of a UFU command when it involves a unification. In this case, it is necessary to update the number of current paths if the unification fails. There are also UFU commands that store a term in the binding environment. In this case, the CP may continue its execution after delivering the command. UFUs fetch continually instructions to be executed from a command buffer (CB), and update their binding environments accordingly. In case of a unification command, each UFU signals a successful or a failure status to the CP. An implementation of PMA on a multiprocessor system is being done. In this case, CP and UFUs can be mapped on different processors, and the memory space can be easily adapted to the shared view of the multiprocessor. The analysis of this implementation will be helpful to design more precisely the parallel PMA architecture. MEM CODE SBG HEAP CB CB CB STACK UFU UFU UFU CPU BE_UNSAFE BE_PERM BE_UNSAFE BE_PERM BE_UNSAFE BE_PERM BE_TRAIL MEM BE_TRAIL MEM BE_TRAIL MEM Figure 6: PMA architecture. CP UFU 1 UFU i UFU N 14

15 6 CONCLUSIONS A new execution model for Prolog programs (MEM) that combines a depth-first and a breadthfirst exploration of the search tree has been presented. The main characteristics of MEM is the simultaneous traversal of more than one path of the SLD-tree. A modification of the Warren s Abstract Machine to accommodate the features of the MEM model has also been presented. Results from a sequential implementation of MEM show that performance improvement of MEM over the standard depth-first traversal depends on three factors: the overhead added by the breadth-first search management, the ratio of the number of control instructions over the total number of executed instructions, and the average number of paths being simultaneously traversed. The results presented in this paper confirm that a combined depth-first and breadth-first search is advantageous over the standard depth-first search for programs containing goals with a large number of solutions. The simultaneous traversal of more than one path enables the exploitation of a new kind of parallelism, that we call path parallelism. In path parallelism, accesses or unifications in the binding environments related multiple paths being simultaneously traversed may be executed in parallel. This type of parallelism, which is different from data and unification parallelism, may contribute to increase substantially the performance of the system. Although path parallelism is fine-grained, it can be exploited very efficiently because the amount of synchronization and data sharing that it requires is rather low. A SIMD-like architecture (PMA) to execute in parallel the MEM model has also been introduced. REFERENCES [1] H. Aït Kaci. Warren s Abstract Machine. MIT Press, [2] W.V. Citrin. Parallel Unification Scheduling in Prolog. Technical report # UCB/CSD 88/ 415, Berkeley University [3] P. Kacsuk. DAP Prolog: A Parallel Array Extension of Prolog. In Proc. of CONPAR88, British Computer Society (editor) [4] P. Kacsuk and M. Wise (editors). Implementations of Distributed Prolog. John Wiley & Sons [5] P.M. Kogge. The Architecture of Symbolic Computers. McGraw-Hill, [6] M. Korsloot and H. Mulder. Sequential Architecture Models for Prolog. New Generation Computing, vol. 9, [7] J. W. Lloyd. Foundations of Logic Programming. Springer-Verlag, [8] D. A. Smith. Multilog: Data Or-Parallel Logic Programming. In Proc. of ICLP 93. MIT Press, [9] E. Tick. Parallel Logic Programming. MIT Press, [10] J. Tubella and A. González. MEM: A New Execution Model for Prolog. Microprocessing and Microprogramming, vol. 39, North-Holland,

A Partial Breadth-First Execution Model for Prolog*

A Partial Breadth-First Execution Model for Prolog* A Partial Breadth-First Execution Model for Prolog* Jordi Tubella and Antonio Gonzilez Departament d Arquitectura de Computadors Universitat Politkcnica de Catalunya - Barcelona - Spain Abstract MEM (Multipath

More information

Exploiting Path Parallelism in Logic Programming*

Exploiting Path Parallelism in Logic Programming* Exploiting Path Parallelism in Logic Programming* Jordi Tubella and Antonio Gonz6lez Universitat Politkcnica de Catalunya C/. Gran CapitA, s/n. - Edifici D6 E-08071 Barcelona (Spain) e-mail: {jordit,antonio}@ac.upc.es

More information

On the BEAM Implementation

On the BEAM Implementation On the BEAM Implementation Ricardo Lopes 1,Vítor Santos Costa 2, and Fernando Silva 1 1 DCC-FC and LIACC, Universidade do Porto, Portugal {rslopes,fds}@ncc.up.pt 2 COPPE-Sistemas, Universidade Federal

More information

Implementação de Linguagens 2016/2017

Implementação de Linguagens 2016/2017 Implementação de Linguagens Ricardo Rocha DCC-FCUP, Universidade do Porto ricroc @ dcc.fc.up.pt Ricardo Rocha DCC-FCUP 1 Logic Programming Logic programming languages, together with functional programming

More information

PUP: An Architecture to Exploit Parallel Unification in Prolog

PUP: An Architecture to Exploit Parallel Unification in Prolog PUP: An Architecture to Exploit Parallel Unification in Prolog l Chien Chen Ashok Singhal Yale N. Patt Computer Science Division University of California, Berkeley ABSTRACT The architecture described in

More information

Prolog Programming. Lecture Module 8

Prolog Programming. Lecture Module 8 Prolog Programming Lecture Module 8 Prolog Language Prolog is unique in its ability to infer facts from the given facts and rules. In Prolog, an order of clauses in the program and goals in the body of

More information

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments

Programming Languages Third Edition. Chapter 10 Control II Procedures and Environments Programming Languages Third Edition Chapter 10 Control II Procedures and Environments Objectives Understand the nature of procedure definition and activation Understand procedure semantics Learn parameter-passing

More information

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2

What needs to be kept track of ffl The current substitution ffl The current goal ffl The clause currently in use ffl Backtrack Information 2 Prolog Implementation ffl The Generic Idea: Everything except unification. ffl An Introduction to the WAM: Flat unification only. 1 What needs to be kept track of ffl The current substitution ffl The current

More information

PALS: Efficient Or-Parallel Execution of Prolog on Beowulf Clusters

PALS: Efficient Or-Parallel Execution of Prolog on Beowulf Clusters PALS: Efficient Or-Parallel Execution of Prolog on Beowulf Clusters K. Villaverde and E. Pontelli H. Guo G. Gupta Dept. Computer Science Dept. Computer Science Dept. Computer Science New Mexico State University

More information

Thread-Based Competitive Or-Parallelism

Thread-Based Competitive Or-Parallelism Thread-Based Competitive Or-Parallelism Paulo Moura 1,3, Ricardo Rocha 2,3, and Sara C. Madeira 1,4 1 Dep. of Computer Science, University of Beira Interior, Portugal {pmoura, smadeira}@di.ubi.pt 2 Dep.

More information

tuprolog with exceptions

tuprolog with exceptions tuprolog with exceptions Enrico Denti December 16, 2010 Abstract This document describes the new support for ISO Prolog exceptions in tuprolog 2.2. Please notice that this document is not intended to replace

More information

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table

The basic operations defined on a symbol table include: free to remove all entries and free the storage of a symbol table SYMBOL TABLE: A symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is associated with information relating

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 July 5, 2007 14.00-15.30 This exam (8 pages) consists of 60 True/False

More information

Lecture 21: Relational Programming II. November 15th, 2011

Lecture 21: Relational Programming II. November 15th, 2011 Lecture 21: Relational Programming II November 15th, 2011 Lecture Outline Relational Programming contd The Relational Model of Computation Programming with choice and Solve Search Strategies Relational

More information

Operational Semantics

Operational Semantics 15-819K: Logic Programming Lecture 4 Operational Semantics Frank Pfenning September 7, 2006 In this lecture we begin in the quest to formally capture the operational semantics in order to prove properties

More information

Efficient Instance Retrieval of Subgoals for Subsumptive Tabled Evaluation of Logic Programs arxiv: v1 [cs.pl] 27 Jul 2011

Efficient Instance Retrieval of Subgoals for Subsumptive Tabled Evaluation of Logic Programs arxiv: v1 [cs.pl] 27 Jul 2011 Under consideration for publication in Theory and Practice of Logic Programming Efficient Instance Retrieval of Subgoals for Subsumptive Tabled Evaluation of Logic Programs arxiv:07.5556v [cs.pl] 7 Jul

More information

Infinite Derivations as Failures

Infinite Derivations as Failures Infinite Derivations as Failures Andrea Corradi and Federico Frassetto DIBRIS, Università di Genova, Italy name.surname@dibris.unige.it Abstract. When operating on cyclic data, programmers have to take

More information

Programming Languages Third Edition. Chapter 7 Basic Semantics

Programming Languages Third Edition. Chapter 7 Basic Semantics Programming Languages Third Edition Chapter 7 Basic Semantics Objectives Understand attributes, binding, and semantic functions Understand declarations, blocks, and scope Learn how to construct a symbol

More information

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004

Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 Principles of Programming Languages Topic: Scope and Memory Professor Louis Steinberg Fall 2004 CS 314, LS,BR,LTM: Scope and Memory 1 Review Functions as first-class objects What can you do with an integer?

More information

A Simple Code Improvement Scheme for Prolog. Saumya K. Debray. Department of Computer Science The University of Arizona Tucson, AZ 85721, USA

A Simple Code Improvement Scheme for Prolog. Saumya K. Debray. Department of Computer Science The University of Arizona Tucson, AZ 85721, USA A Simple Code Improvement Scheme for Prolog Saumya K. Debray Department of Computer Science The University of Arizona Tucson, AZ 85721, USA Abstract The generation of efficient code for Prolog programs

More information

ACHARACTERIZATION OF PROLOG EXECUTION MARK ANDREW FRIEDMAN

ACHARACTERIZATION OF PROLOG EXECUTION MARK ANDREW FRIEDMAN ACHARACTERIZATION OF PROLOG EXECUTION by MARK ANDREW FRIEDMAN Athesis submitted in partial fulfillment of the requirements for the degree of Doctor of Philosophy (Computer Science) at the UNIVERSITY OF

More information

Dept. of Comp. Eng. and Info. Sc.,Bilkent University, Bilkent,Ankara,Turkey

Dept. of Comp. Eng. and Info. Sc.,Bilkent University, Bilkent,Ankara,Turkey Variable Ages In A WAM Based System Ilyas Cicekli Dept. of Comp. Eng. and Info. Sc.,Bilkent University, 06533 Bilkent,Ankara,Turkey Abstract We present a new method to represent variable bindings in the

More information

DDS Dynamic Search Trees

DDS Dynamic Search Trees DDS Dynamic Search Trees 1 Data structures l A data structure models some abstract object. It implements a number of operations on this object, which usually can be classified into l creation and deletion

More information

Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Harald Gall, Prof. Dr.

Stacks, Queues & Trees. The Stack Interface. The Stack Interface. Harald Gall, Prof. Dr. Stacks, Queues & Trees Harald Gall, Prof. Dr. Institut für Informatik Universität Zürich http://seal.ifi.uzh.ch The Stack Interface Stack Data structure holding several items. New items added to the top

More information

Logic Languages. Hwansoo Han

Logic Languages. Hwansoo Han Logic Languages Hwansoo Han Logic Programming Based on first-order predicate calculus Operators Conjunction, disjunction, negation, implication Universal and existential quantifiers E A x for all x...

More information

Using Prolog and CLP for. Designing a Prolog Processor

Using Prolog and CLP for. Designing a Prolog Processor Using Prolog and CLP for Designing a Prolog Processor Abstract This paper presents the LPCAD (Logic Programming-based system for CAD) system for designing complex microprogrammed processors using Prolog

More information

Incremental Flow Analysis. Andreas Krall and Thomas Berger. Institut fur Computersprachen. Technische Universitat Wien. Argentinierstrae 8

Incremental Flow Analysis. Andreas Krall and Thomas Berger. Institut fur Computersprachen. Technische Universitat Wien. Argentinierstrae 8 Incremental Flow Analysis Andreas Krall and Thomas Berger Institut fur Computersprachen Technische Universitat Wien Argentinierstrae 8 A-1040 Wien fandi,tbg@mips.complang.tuwien.ac.at Abstract Abstract

More information

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types

This lecture covers: Prolog s execution strategy explained more precisely. Revision of the elementary Prolog data types This lecture covers: Prolog s execution strategy explained more precisely The execution strategy has been presented as simply placing all matching clauses onto the stack. In fact, Prolog is slightly more

More information

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill

Binding and Storage. COMP 524: Programming Language Concepts Björn B. Brandenburg. The University of North Carolina at Chapel Hill Binding and Storage Björn B. Brandenburg The University of North Carolina at Chapel Hill Based in part on slides and notes by S. Olivier, A. Block, N. Fisher, F. Hernandez-Campos, and D. Stotts. What s

More information

Incremental Copying Garbage Collection for WAM-based Prolog systems

Incremental Copying Garbage Collection for WAM-based Prolog systems Incremental Copying Garbage Collection for WAM-based Prolog systems Ruben Vandeginste Bart Demoen Department of Computer Science, Katholieke Universiteit Leuven, Belgium {ruben,bmd}@cs.kuleuven.ac.be Abstract

More information

CS301 - Data Structures Glossary By

CS301 - Data Structures Glossary By CS301 - Data Structures Glossary By Abstract Data Type : A set of data values and associated operations that are precisely specified independent of any particular implementation. Also known as ADT Algorithm

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 4 Thomas Wies New York University Review Last week Control Structures Selection Loops Adding Invariants Outline Subprograms Calling Sequences Parameter

More information

Warren s Abstract Machine

Warren s Abstract Machine Warren s Abstract Machine A Tutorial Reconstruction Hassan A ıt-kaci ICLP 91 Pre-Conference Tutorial [1] I dedicate this modest work to a most outstanding WAM I am referring of course to Wolfgang Amadeus

More information

Prolog. Intro to Logic Programming

Prolog. Intro to Logic Programming Prolog Logic programming (declarative) Goals and subgoals Prolog Syntax Database example rule order, subgoal order, argument invertibility, backtracking model of execution, negation by failure, variables

More information

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011

Lecture 5: Declarative Programming. The Declarative Kernel Language Machine. September 12th, 2011 Lecture 5: Declarative Programming. The Declarative Kernel Language Machine September 12th, 2011 1 Lecture Outline Declarative Programming contd Dataflow Variables contd Expressions and Statements Functions

More information

The Metalanguage λprolog and Its Implementation

The Metalanguage λprolog and Its Implementation The Metalanguage λprolog and Its Implementation Gopalan Nadathur Computer Science Department University of Minnesota (currently visiting INRIA and LIX) 1 The Role of Metalanguages Many computational tasks

More information

Parallel Execution of Logic Programs: Back to the Future (??)

Parallel Execution of Logic Programs: Back to the Future (??) Parallel Execution of Logic Programs: Back to the Future (??) Enrico Pontelli Dept. Computer Science Overview 1. Some motivations [Logic Programming and Parallelism] 2. The Past [Types of Parallelism,

More information

Implementação de Linguagens

Implementação de Linguagens Implementação de Linguagens de Programação Lógica Extended Andorra Model Ricardo Lopes rslopes@ncc.up.pt DCC-FCUP Tópicos Avançados de Informática Mestrado em Informática 2005/06 The Andorra Principle

More information

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How?

! Those values must be stored somewhere! Therefore, variables must somehow be bound. ! How? A Binding Question! Variables are bound (dynamically) to values Subprogram Activation! Those values must be stored somewhere! Therefore, variables must somehow be bound to memory locations! How? Function

More information

Runtime Environments I. Basilio B. Fraguela

Runtime Environments I. Basilio B. Fraguela Runtime Environments I Basilio B. Fraguela Runtime System Responsibilities Allocation of storage for program data Sometimes also deallocation Garbage collection Management of data structures the compiled

More information

Constructive Search Algorithms

Constructive Search Algorithms Constructive Search Algorithms! Introduction Historically the major search method for CSPs Reference: S.W.Golomb & L.D.Baumert (1965) Backtrack Programming, JACM 12:516-524 Extended for Intelligent Backtracking

More information

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version:

SISTEMI EMBEDDED. Stack, Subroutine, Parameter Passing C Storage Classes and Scope. Federico Baronti Last version: SISTEMI EMBEDDED Stack, Subroutine, Parameter Passing C Storage Classes and Scope Federico Baronti Last version: 20160314 Stack A stack is an abstract data structure managed according to a last-in-first-out

More information

SAT solver of Howe & King as a logic program

SAT solver of Howe & King as a logic program SAT solver of Howe & King as a logic program W lodzimierz Drabent June 6, 2011 Howe and King [HK11b, HK11a] presented a SAT solver which is an elegant and concise Prolog program of 22 lines. It is not

More information

Multi-paradigm Declarative Languages

Multi-paradigm Declarative Languages Michael Hanus (CAU Kiel) Multi-paradigm Declarative Languages ICLP 2007 1 Multi-paradigm Declarative Languages Michael Hanus Christian-Albrechts-University of Kiel Programming Languages and Compiler Construction

More information

Logic Programming and Resolution Lecture notes for INF3170/4171

Logic Programming and Resolution Lecture notes for INF3170/4171 Logic Programming and Resolution Lecture notes for INF3170/4171 Leif Harald Karlsen Autumn 2015 1 Introduction This note will explain the connection between logic and computer programming using Horn Clauses

More information

Prolog-2 nd Lecture. Prolog Predicate - Box Model

Prolog-2 nd Lecture. Prolog Predicate - Box Model Prolog-2 nd Lecture Tracing in Prolog Procedural interpretation of execution Box model of Prolog predicate rule How to follow a Prolog trace? Trees in Prolog use nested terms Unification Informally Formal

More information

Compiler Theory. (Semantic Analysis and Run-Time Environments)

Compiler Theory. (Semantic Analysis and Run-Time Environments) Compiler Theory (Semantic Analysis and Run-Time Environments) 005 Semantic Actions A compiler must do more than recognise whether a sentence belongs to the language of a grammar it must do something useful

More information

Chapter 5 Names, Binding, Type Checking and Scopes

Chapter 5 Names, Binding, Type Checking and Scopes Chapter 5 Names, Binding, Type Checking and Scopes Names - We discuss all user-defined names here - Design issues for names: -Maximum length? - Are connector characters allowed? - Are names case sensitive?

More information

CMSC 331 Final Exam Section 0201 December 18, 2000

CMSC 331 Final Exam Section 0201 December 18, 2000 CMSC 331 Final Exam Section 0201 December 18, 2000 Name: Student ID#: You will have two hours to complete this closed book exam. We reserve the right to assign partial credit, and to deduct points for

More information

CONSIDERATIONS CONCERNING PARALLEL AND DISTRIBUTED ARCHITECTURE FOR INTELLIGENT SYSTEMS

CONSIDERATIONS CONCERNING PARALLEL AND DISTRIBUTED ARCHITECTURE FOR INTELLIGENT SYSTEMS CONSIDERATIONS CONCERNING PARALLEL AND DISTRIBUTED ARCHITECTURE FOR INTELLIGENT SYSTEMS 1 Delia Ungureanu, 2 Dominic Mircea Kristaly, 3 Adrian Virgil Craciun 1, 2 Automatics Department, Transilvania University

More information

Part I Logic programming paradigm

Part I Logic programming paradigm Part I Logic programming paradigm 1 Logic programming and pure Prolog 1.1 Introduction 3 1.2 Syntax 4 1.3 The meaning of a program 7 1.4 Computing with equations 9 1.5 Prolog: the first steps 15 1.6 Two

More information

CSE 504: Compiler Design. Runtime Environments

CSE 504: Compiler Design. Runtime Environments Runtime Environments Pradipta De pradipta.de@sunykorea.ac.kr Current Topic Procedure Abstractions Mechanisms to manage procedures and procedure calls from compiler s perspective Runtime Environment Choices

More information

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology

Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology Faculty of Electrical Engineering, Mathematics, and Computer Science Delft University of Technology exam Compiler Construction in4020 January 19, 2006 14.00-15.30 This exam (8 pages) consists of 60 True/False

More information

DATA STRUCTURE AND ALGORITHM USING PYTHON

DATA STRUCTURE AND ALGORITHM USING PYTHON DATA STRUCTURE AND ALGORITHM USING PYTHON Advanced Data Structure and File Manipulation Peter Lo Linear Structure Queue, Stack, Linked List and Tree 2 Queue A queue is a line of people or things waiting

More information

Algorithm Design Techniques (III)

Algorithm Design Techniques (III) Algorithm Design Techniques (III) Minimax. Alpha-Beta Pruning. Search Tree Strategies (backtracking revisited, branch and bound). Local Search. DSA - lecture 10 - T.U.Cluj-Napoca - M. Joldos 1 Tic-Tac-Toe

More information

Today's Topics. CISC 458 Winter J.R. Cordy

Today's Topics. CISC 458 Winter J.R. Cordy Today's Topics Last Time Semantics - the meaning of program structures Stack model of expression evaluation, the Expression Stack (ES) Stack model of automatic storage, the Run Stack (RS) Today Managing

More information

G Programming Languages - Fall 2012

G Programming Languages - Fall 2012 G22.2110-003 Programming Languages - Fall 2012 Lecture 2 Thomas Wies New York University Review Last week Programming Languages Overview Syntax and Semantics Grammars and Regular Expressions High-level

More information

Symbol Tables Symbol Table: In computer science, a symbol table is a data structure used by a language translator such as a compiler or interpreter, where each identifier in a program's source code is

More information

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1

CSE P 501 Compilers. Java Implementation JVMs, JITs &c Hal Perkins Winter /11/ Hal Perkins & UW CSE V-1 CSE P 501 Compilers Java Implementation JVMs, JITs &c Hal Perkins Winter 2008 3/11/2008 2002-08 Hal Perkins & UW CSE V-1 Agenda Java virtual machine architecture.class files Class loading Execution engines

More information

Register Allocation in a Prolog Machine

Register Allocation in a Prolog Machine Register Allocation in a Prolog Machine Saumya K. Debray Department of Computer Science State University of New York at Stony Brook Stony Brook, NY 11794 Abstract: We consider the Prolog Engine described

More information

Runtime support for region-based memory management in Mercury

Runtime support for region-based memory management in Mercury Runtime support for region-based memory management in Mercury Quan Phan*, Zoltan Somogyi**, Gerda Janssens* * DTAI, KU Leuven, Belgium. ** Computer Science and Software Engineering Department, University

More information

Backtracking. Chapter 5

Backtracking. Chapter 5 1 Backtracking Chapter 5 2 Objectives Describe the backtrack programming technique Determine when the backtracking technique is an appropriate approach to solving a problem Define a state space tree for

More information

Qualifying Exam in Programming Languages and Compilers

Qualifying Exam in Programming Languages and Compilers Qualifying Exam in Programming Languages and Compilers University of Wisconsin Fall 1991 Instructions This exam contains nine questions, divided into two parts. All students taking the exam should answer

More information

6.821 Programming Languages Handout Fall 2002 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science

6.821 Programming Languages Handout Fall 2002 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science 6.821 Programming Languages Handout Fall 2002 MASSACHVSETTS INSTITVTE OF TECHNOLOGY Department of Electrical Engineering and Compvter Science Problem Set 8 Problem 1: Concurrency Dr. Brian Storm is working

More information

Process Management And Synchronization

Process Management And Synchronization Process Management And Synchronization In a single processor multiprogramming system the processor switches between the various jobs until to finish the execution of all jobs. These jobs will share the

More information

NOTE: Answer ANY FOUR of the following 6 sections:

NOTE: Answer ANY FOUR of the following 6 sections: A-PDF MERGER DEMO Philadelphia University Lecturer: Dr. Nadia Y. Yousif Coordinator: Dr. Nadia Y. Yousif Internal Examiner: Dr. Raad Fadhel Examination Paper... Programming Languages Paradigms (750321)

More information

Agenda. CS301 Session 20. A logic programming trick. A simple Prolog program. Introduction to logic programming Examples Semantics

Agenda. CS301 Session 20. A logic programming trick. A simple Prolog program. Introduction to logic programming Examples Semantics CS301 Session 20 Introduction to logic programming Examples Semantics Agenda 1 2 A logic programming trick A two-way translator in two lines of code: translate([],[]). translate([word Words],[Mot Mots])

More information

1 Process Coordination

1 Process Coordination COMP 730 (242) Class Notes Section 5: Process Coordination 1 Process Coordination Process coordination consists of synchronization and mutual exclusion, which were discussed earlier. We will now study

More information

(low) Code Area. feature symbol table type symbol table addtype table. unification table feature_val table HEAP STACK

(low) Code Area. feature symbol table type symbol table addtype table. unification table feature_val table HEAP STACK AN ABSTRACT MACHINE FOR ATTRIBUTE VALUE LOGICS Bob Carpenter Yan Qu Computational Linguistics Program, Carnegie Mellon University carp+@cmu.edu yqu@cs.cmu.edu Abstract A direct abstract machine implementation

More information

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation

Chapter 16. Logic Programming. Topics. Predicate Calculus and Proving Theorems. Resolution. Resolution: example. Unification and Instantiation Topics Chapter 16 Logic Programming Proving Theorems Resolution Instantiation and Unification Prolog Terms Clauses Inference Process Backtracking 2 Predicate Calculus and Proving Theorems A use of propositions

More information

Prolog. Logic Programming vs Prolog

Prolog. Logic Programming vs Prolog Language constructs Prolog Facts, rules, queries through examples Horn clauses Goal-oriented semantics Procedural semantics How computation is performed? Comparison to logic programming 1 Logic Programming

More information

Chapter 5. Names, Bindings, and Scopes

Chapter 5. Names, Bindings, and Scopes Chapter 5 Names, Bindings, and Scopes Chapter 5 Topics Introduction Names Variables The Concept of Binding Scope Scope and Lifetime Referencing Environments Named Constants 1-2 Introduction Imperative

More information

Prolog Cut: Summary. CSC324 Logic & Relational Programming Illustrated in Prolog. Prolog Cut: Summary. Non-deterministic Programming

Prolog Cut: Summary. CSC324 Logic & Relational Programming Illustrated in Prolog. Prolog Cut: Summary. Non-deterministic Programming Prolog Cut: Summary CSC324 Logic & Relational Programming Illustrated in Prolog Afsaneh Fazly Cut (! ) can be used to: remove duplicate (& unnecessary) responses. remove incorrect responses. improve efficiency

More information

SEMANTIC ANALYSIS TYPES AND DECLARATIONS

SEMANTIC ANALYSIS TYPES AND DECLARATIONS SEMANTIC ANALYSIS CS 403: Type Checking Stefan D. Bruda Winter 2015 Parsing only verifies that the program consists of tokens arranged in a syntactically valid combination now we move to check whether

More information

CSC 533: Organization of Programming Languages. Spring 2005

CSC 533: Organization of Programming Languages. Spring 2005 CSC 533: Organization of Programming Languages Spring 2005 Language features and issues variables & bindings data types primitive complex/structured expressions & assignments control structures subprograms

More information

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard

FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 ( Marks: 1 ) - Please choose one The data of the problem is of 2GB and the hard FINALTERM EXAMINATION Fall 2009 CS301- Data Structures Question No: 1 The data of the problem is of 2GB and the hard disk is of 1GB capacity, to solve this problem we should Use better data structures

More information

Automatic Memory Management in newlisp

Automatic Memory Management in newlisp SS Procedia Computer Science 18 (2013) 159 16 8 International Conference on Computational Science, ICCS 2013 Automatic Memory Management in newlisp German Molt, Miguel caballer, EloyRomero, Carlos dealfonso

More information

Run Time Environments

Run Time Environments Run Time Environments ALSU Textbook Chapter 7.1 7.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Preliminaries During the execution of a program, the same name in the source

More information

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far

Semantic Analysis. Outline. The role of semantic analysis in a compiler. Scope. Types. Where we are. The Compiler so far Outline Semantic Analysis The role of semantic analysis in a compiler A laundry list of tasks Scope Static vs. Dynamic scoping Implementation: symbol tables Types Statically vs. Dynamically typed languages

More information

An Object Model for Multiparadigm

An Object Model for Multiparadigm 1 of 7 03/02/2007 15:37 http://www.dmst.aueb.gr/dds/pubs/conf/1994-oopsla-multipar/html/mlom.html This is an HTML rendering of a working paper draft that led to a publication. The publication should always

More information

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions)

CIS 1.5 Course Objectives. a. Understand the concept of a program (i.e., a computer following a series of instructions) By the end of this course, students should CIS 1.5 Course Objectives a. Understand the concept of a program (i.e., a computer following a series of instructions) b. Understand the concept of a variable

More information

Single-pass Static Semantic Check for Efficient Translation in YAPL

Single-pass Static Semantic Check for Efficient Translation in YAPL Single-pass Static Semantic Check for Efficient Translation in YAPL Zafiris Karaiskos, Panajotis Katsaros and Constantine Lazos Department of Informatics, Aristotle University Thessaloniki, 54124, Greece

More information

Programmiersprachen (Programming Languages)

Programmiersprachen (Programming Languages) 2016-05-13 Preface Programmiersprachen (Programming Languages) coordinates: lecturer: web: usable for: requirements: No. 185.208, VU, 3 ECTS Franz Puntigam http://www.complang.tuwien.ac.at/franz/ps.html

More information

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions

Overview. CMSC 330: Organization of Programming Languages. Concurrency. Multiprocessors. Processes vs. Threads. Computation Abstractions CMSC 330: Organization of Programming Languages Multithreaded Programming Patterns in Java CMSC 330 2 Multiprocessors Description Multiple processing units (multiprocessor) From single microprocessor to

More information

Data Structure. IBPS SO (IT- Officer) Exam 2017

Data Structure. IBPS SO (IT- Officer) Exam 2017 Data Structure IBPS SO (IT- Officer) Exam 2017 Data Structure: In computer science, a data structure is a way of storing and organizing data in a computer s memory so that it can be used efficiently. Data

More information

COMP2411 Lecture 20: Logic Programming Examples. (This material not in the book)

COMP2411 Lecture 20: Logic Programming Examples. (This material not in the book) COMP2411 Lecture 20: Logic Programming Examples (This material not in the book) There are several distinct but often equivalent ways to think about logic programs 1. As computing logical consequences of

More information

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu.

Symbol Tables. ASU Textbook Chapter 7.6, 6.5 and 6.3. Tsan-sheng Hsu. Symbol Tables ASU Textbook Chapter 7.6, 6.5 and 6.3 Tsan-sheng Hsu tshsu@iis.sinica.edu.tw http://www.iis.sinica.edu.tw/~tshsu 1 Definitions Symbol table: A data structure used by a compiler to keep track

More information

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011

Lecture 6: The Declarative Kernel Language Machine. September 13th, 2011 Lecture 6: The Declarative Kernel Language Machine September 13th, 2011 Lecture Outline Computations contd Execution of Non-Freezable Statements on the Abstract Machine The skip Statement The Sequential

More information

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction

Lecture 13: Object orientation. Object oriented programming. Introduction. Object oriented programming. OO and ADT:s. Introduction Lecture 13: Object orientation Object oriented programming Introduction, types of OO languages Key concepts: Encapsulation, Inheritance, Dynamic binding & polymorphism Other design issues Smalltalk OO

More information

Global Dataow Analysis of Prolog. Andreas Krall and Thomas Berger. Institut fur Computersprachen. Technische Universitat Wien. Argentinierstrae 8

Global Dataow Analysis of Prolog. Andreas Krall and Thomas Berger. Institut fur Computersprachen. Technische Universitat Wien. Argentinierstrae 8 The VAM AI { an Abstract Machine for Incremental Global Dataow Analysis of Prolog Andreas Krall and Thomas Berger Institut fur Computersprachen Technische Universitat Wien Argentinierstrae 8 A-1040 Wien

More information

A High-Level Implementation of Non-Deterministic, Unrestricted, Independent And-Parallelism

A High-Level Implementation of Non-Deterministic, Unrestricted, Independent And-Parallelism A High-Level Implementation of Non-Deterministic, Unrestricted, Independent And-Parallelism Amadeo Casas 1 Manuel Carro 2 Manuel V. Hermenegildo 1,2 amadeo@cs.unm.edu mcarro@fi.upm.es herme@{fi.upm.es,cs.unm.edu}

More information

Logic Programming Languages

Logic Programming Languages Logic Programming Languages Introduction Logic programming languages, sometimes called declarative programming languages Express programs in a form of symbolic logic Use a logical inferencing process to

More information

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine.

1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 1. true / false By a compiler we mean a program that translates to code that will run natively on some machine. 2. true / false ML can be compiled. 3. true / false FORTRAN can reasonably be considered

More information

JavaScript CS 4640 Programming Languages for Web Applications

JavaScript CS 4640 Programming Languages for Web Applications JavaScript CS 4640 Programming Languages for Web Applications 1 How HTML, CSS, and JS Fit Together {css} javascript() Content layer The HTML gives the page structure and adds semantics Presentation

More information

3 SOLVING PROBLEMS BY SEARCHING

3 SOLVING PROBLEMS BY SEARCHING 48 3 SOLVING PROBLEMS BY SEARCHING A goal-based agent aims at solving problems by performing actions that lead to desirable states Let us first consider the uninformed situation in which the agent is not

More information

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University

G Programming Languages Spring 2010 Lecture 4. Robert Grimm, New York University G22.2110-001 Programming Languages Spring 2010 Lecture 4 Robert Grimm, New York University 1 Review Last week Control Structures Selection Loops 2 Outline Subprograms Calling Sequences Parameter Passing

More information

Chapter 13 Reduced Instruction Set Computers

Chapter 13 Reduced Instruction Set Computers Chapter 13 Reduced Instruction Set Computers Contents Instruction execution characteristics Use of a large register file Compiler-based register optimization Reduced instruction set architecture RISC pipelining

More information

CS558 Programming Languages

CS558 Programming Languages CS558 Programming Languages Fall 2016 Lecture 3a Andrew Tolmach Portland State University 1994-2016 Formal Semantics Goal: rigorous and unambiguous definition in terms of a wellunderstood formalism (e.g.

More information

UNIT 4 Branch and Bound

UNIT 4 Branch and Bound UNIT 4 Branch and Bound General method: Branch and Bound is another method to systematically search a solution space. Just like backtracking, we will use bounding functions to avoid generating subtrees

More information

GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATION SEMESTER: III

GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATION SEMESTER: III GUJARAT TECHNOLOGICAL UNIVERSITY MASTER OF COMPUTER APPLICATION SEMESTER: III Subject Name: Operating System (OS) Subject Code: 630004 Unit-1: Computer System Overview, Operating System Overview, Processes

More information