next up previous
Next: Provided predicates and those Up: Syntax of KL1 Previous: List

   
Pragma for priority

Logic programming language KL1 has concurrency (possibility to perform parallel execution) in any level. In other words, a program written in KL1 necessarily runs in parallel if we have infinite number of processors and infinite memory space. Of course such situations are impossible. The number of processors is limited in our real world. Sequentially, the concurrency will appear in a real world computer as numbers of spawned processes in a single processor.

The memory space is also limited in real world. There is no way to directly manage memory in KL1. Program would stop if sufficient memory is not available. Therefore, we have to find a pragmatic solution against limitation of resources.

In KL1, pragma is provided for that. pragma is a kind of meta-level operand, by which program execution is controlled. Memory consumption problem is typically revealed in generator-consumer model [Tanenbaum, 1987]. If a process generates excess data which can not be consumed by other process(es), segmentation fault may occur. In this case, generally speaking, the consumer has to have higher priority than the generator. By using pragma, for example, the priority can be set as follows:



goal :- generator@lower_priority(X),consumer@lower_priority(0).



where X is a positive integer.

However, in complicated programs, some adjustment of priorities is often needed. There are some tips to set priorities from my experience.

1.
Priority operands should be described as many as possible. Using Pragma is only way to directly control execution of programs in KL1.

2.
Recursively called predicates should have higher priority such as:



recursive_goal :-
        some_predicate@lower_priority(X),    /* X > 0 */
        recursive_goal@lower_priority(0).



3.
However, sometimes excess recursive calls may cause some problems such as bus error. In this case, the following way suppress recursive calls so that the number of reductions is suppressed. This may solve the problems.



recursive_goal :-
  some_predicate@lower_priority(X),       /* X >> 0 */
  another_predicate@lower_priority(Y),    /* Y is nearly equal 0
                                            or equal 0*/
  recursive_goal@lower_priority(0).



4.
Collecting answers is a very critical problem in logic programming languages. There is no ``global variable'' in this type of languages, so you have to send the answers to the first called process as an message. A predicate sending the message should have the highest priority in many cases. However, this is not general solution.

5.
We can not set a priority to generic ``method''. A generic ``method'' should be encapsulated by a predicate, and be set an appropriate priority. However, generic method random number generator is exceptional.


next up previous
Next: Provided predicates and those Up: Syntax of KL1 Previous: List
Satoshi OOta
1999-03-06