Logtalk 2.30.1 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1903 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura
2007-06-12 10:39:47 +00:00
parent 84f478c301
commit 6b4bde14e1
475 changed files with 6213 additions and 6424 deletions

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
This folder contains some examples of multi-threading programming.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% load the example:

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the example and the required library files:

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the example and the required library files:

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the loading the example:

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the loading the example:

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the example and the required library files:

View File

@@ -1,18 +1,18 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.
This folder contains a simple multi-threading example with calculating
prime numbers in a given interval. Try to run the example in single and
multi-processor (or multi-core) computers and compare the results. Most
Prolog compilers allows you to measure the time taken for proving a goal
using proprietary predicates.
This folder contains a simple example of calculating prime numbers in a
given interval using multiple threads. Try to run the example in single
and multi-processor (or multi-core) computers and compare the results.
Most Prolog compilers allows you to measure the time taken for proving
a goal using proprietary predicates.
Note that this example is only meant to illustrate how to use Logtalk
multi-threading predicates, not to taken as the efficient solution for

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the loading the example:

View File

@@ -0,0 +1,32 @@
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
================================================================
To load this example and for sample queries, please see the SCRIPT file.
This folder contains a multi-threading implementation of the merge sort
algorithm. Depending on the size of the lists that are ordered, using
only one thread can be faster. The number of threads to use in sorting
is set using the msort/1 object parameter. You may need to adjust the
size of the memory areas used by your Prolog compiler, depending on the
size of the lists you want to sort.
This example uses a simple implementation of the merge sort algorithm,
intended only to illustrate Logtalk multi-threading features. For any
other purpose, you may find the following paper a worthwhile reading:
@incollection{ apt93modular,
author = "Krzysztof R. Apt and Dino Pedreschi",
title = "Modular Termination Proofs for Logic and Pure Prolog Programs.",
booktitle = "116",
month = "31",
publisher = "Centrum voor Wiskunde en Informatica (CWI)",
address = "ISSN 0169-118X",
pages = "35",
year = "1993",
url = "citeseer.ist.psu.edu/apt93modular.html" }

View File

@@ -0,0 +1,83 @@
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
================================================================
% start by loading the example and the required library files:
| ?- logtalk_load(sorting(loader)).
...
% NOTE: the example queries below use a SWI-Prolog proprietary predicate
% time/1 in order to get accurate goal times. For other Prolog compilers,
% replace the time/1 call by any appropriate timing calls (e.g. cputime/0).
% generate a big list of random floats and then merge sort it using a single thread:
?- generator::list(20000, List), time(msort(1)::msort(List, Sorted)).
% 1,145,746 inferences, 0.40 CPU in 0.43 seconds (93% CPU, 2864365 Lips)
List = [0.326219, 0.545052, 0.21687, 0.0500493, 0.772745, 0.805005, 0.574483, 0.301708, 0.670021|...],
Sorted = [1.39358e-06, 0.000206126, 0.00026088, 0.000299165, 0.000362691, 0.000397709, 0.000539889, 0.000574419, 0.000578717|...]
Yes
% generate a big list of random floats and then merge sort it using two threads:
?- generator::list(20000, List), time(msort(2)::msort(List, Sorted)).
% 80,067 inferences, 0.32 CPU in 0.21 seconds (150% CPU, 250209 Lips)
List = [0.963245, 0.666814, 0.3841, 0.281952, 0.806571, 0.608224, 0.623344, 0.138888, 0.867367|...],
Sorted = [5.89827e-05, 0.00010463, 0.000105771, 0.000171936, 0.00022632, 0.000378509, 0.000392918, 0.00041885, 0.000482844|...]
Yes
% generate a big list of random floats and then merge sort it using four threads:
?- generator::list(20000, List), time(msort(4)::msort(List, Sorted)).
% 80,079 inferences, 0.32 CPU in 0.16 seconds (204% CPU, 250247 Lips)
List = [0.0923009, 0.443585, 0.72304, 0.945816, 0.501491, 0.311327, 0.597448, 0.915656, 0.666957|...],
Sorted = [3.65916e-05, 4.06822e-05, 5.07434e-05, 6.09007e-05, 0.000134275, 0.000190491, 0.00024128, 0.000361441, 0.000412926|...]
Yes
% generate a big list of random floats and then quick sort it using a single thread:
?- generator::list(20000, List), time(qsort(1)::qsort(List, Sorted)).
% 1,145,746 inferences, 0.40 CPU in 0.43 seconds (93% CPU, 2864365 Lips)
List = [0.326219, 0.545052, 0.21687, 0.0500493, 0.772745, 0.805005, 0.574483, 0.301708, 0.670021|...],
Sorted = [1.39358e-06, 0.000206126, 0.00026088, 0.000299165, 0.000362691, 0.000397709, 0.000539889, 0.000574419, 0.000578717|...]
Yes
% generate a big list of random floats and then quick sort it using two threads:
?- generator::list(20000, List), time(qsort(2)::qsort(List, Sorted)).
% 80,067 inferences, 0.32 CPU in 0.21 seconds (150% CPU, 250209 Lips)
List = [0.963245, 0.666814, 0.3841, 0.281952, 0.806571, 0.608224, 0.623344, 0.138888, 0.867367|...],
Sorted = [5.89827e-05, 0.00010463, 0.000105771, 0.000171936, 0.00022632, 0.000378509, 0.000392918, 0.00041885, 0.000482844|...]
Yes
% generate a big list of random floats and then quick sort it using four threads:
?- generator::list(20000, List), time(qsort(4)::qsort(List, Sorted)).
% 80,079 inferences, 0.32 CPU in 0.16 seconds (204% CPU, 250247 Lips)
List = [0.0923009, 0.443585, 0.72304, 0.945816, 0.501491, 0.311327, 0.597448, 0.915656, 0.666957|...],
Sorted = [3.65916e-05, 4.06822e-05, 5.07434e-05, 6.09007e-05, 0.000134275, 0.000190491, 0.00024128, 0.000361441, 0.000412926|...]
Yes

View File

@@ -0,0 +1,19 @@
:- object(generator).
:- info([
version is 1.0,
author is 'Paulo Moura',
date is 2007/03/22,
comment is 'Simple object defining a predicate for generating lists of random values.']).
:- public(list/2).
list(0, []).
list(N, [R| Rs]) :-
N > 0,
N2 is N - 1,
random::random(R),
list(N2, Rs).
:- end_object.

View File

@@ -0,0 +1,4 @@
:- initialization((
logtalk_load(library(random_loader), [reload(skip)]),
logtalk_load([generator, qsort, msort]))).

View File

@@ -0,0 +1,57 @@
:- object(msort(_Threads)).
:- info([
version is 1.1,
author is 'Paulo Moura and Paul Crocker',
date is 2007/03/30,
comment is 'Multi-threaded implementation of the merge sort algorithm.',
parameters is ['Threads'- 'Number of threads to use in sorting. Valid values are 1, 2, 4, 8, etc.']]).
:- threaded.
:- public(msort/2).
:- mode(msort(+list, -list), one).
:- info(msort/2, [
comment is 'Sorts a list of terms into ascending order.',
argnames is ['List', 'Sorted']]).
msort(List, Sorted) :-
parameter(1, Threads),
mt_msort(Threads, List, Sorted).
mt_msort(1, List, Sorted) :-
st_msort(List, Sorted).
mt_msort(N, List, Sorted) :-
N > 1,
N2 is N//2,
split(List, List1, List2),
threaded((
mt_msort(N2, List1, Sorted1),
mt_msort(N2, List2, Sorted2)
)), !, % SWI-Prolog needs help with determinism detection
merge(Sorted1, Sorted2, Sorted).
st_msort([], []).
st_msort([X], [X]).
st_msort([X, Y| Xs], Ys) :-
split([X, Y| Xs], X1s, X2s),
st_msort(X1s, Y1s),
st_msort(X2s, Y2s),
merge(Y1s, Y2s, Ys).
split([], [], []).
split([X| Xs], [X| Ys], Zs) :-
split(Xs, Zs, Ys).
merge([X| Xs], [Y| Ys], [X| Zs]) :-
X =< Y, !,
merge(Xs, [Y| Ys], Zs).
merge([X| Xs], [Y| Ys], [Y| Zs]) :-
X > Y, !,
merge([X | Xs], Ys, Zs).
merge([], Xs, Xs) :- !.
merge(Xs, [], Xs).
:- end_object.

View File

@@ -0,0 +1,50 @@
:- object(qsort(_Threads)).
:- info([
version is 1.0,
author is 'Paul Croker and Paulo Moura',
date is 2007/03/29,
comment is 'Multi-threaded version of the quick sort algorithm.',
parameters is ['Threads'- 'Number of threads to use in sorting. Valid values are 1, 2, 4, 8, 16, 32, etc.']]).
:- threaded.
:- public(qsort/2).
:- mode(qsort(+list, -list), one).
:- info(qsort/2, [
comment is 'Sorts a list of terms into ascending order.',
argnames is ['List', 'Sorted']]).
qsort(List, Sorted) :-
parameter(1, Threads),
qsort(List, [], Sorted, Threads).
qsort([], Sorted, Sorted, _).
qsort([Pivot| Rest], Acc, Sorted, N) :-
( N =:= 1 ->
quicksort([Pivot| Rest], Acc, Sorted)
; N2 is N//2,
partition(Rest, Pivot, Smaller0, Bigger0),
threaded((
qsort(Smaller0, [Pivot| Bigger], Sorted, N2),
qsort(Bigger0, Acc, Bigger, N2)
)), ! % SWI-Prolog needs help with determinism detection
).
partition([], _, [], []).
partition([X| Xs], Pivot, Smalls, Bigs) :-
( X < Pivot ->
Smalls = [X| Rest],
partition(Xs, Pivot, Rest, Bigs)
; Bigs = [X| Rest],
partition(Xs, Pivot, Smalls, Rest)
).
quicksort([], Sorted, Sorted).
quicksort([Pivot| Rest], Acc, Sorted) :-
partition(Rest, Pivot, Smaller0, Bigger0),
quicksort(Smaller0, [Pivot| Bigger], Sorted),
quicksort(Bigger0, Acc, Bigger).
:- end_object.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
To load this example and for sample queries, please see the SCRIPT file.

View File

@@ -1,9 +1,9 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
================================================================
Logtalk - Open source object-oriented logic programming language
Release 2.30.1
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
================================================================
% start by loading the loading the example: