Logtalk 2.30.2 files.

git-svn-id: https://yap.svn.sf.net/svnroot/yap/trunk@1909 b08c6af1-5177-4d33-ba66-4b1c6b8b522a
This commit is contained in:
pmoura 2007-06-27 13:37:09 +00:00
parent 9fc2c47d53
commit b4daf479f8
5 changed files with 0 additions and 178 deletions

View File

@ -1,32 +0,0 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
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 single-threaded and multi-threaded versions
of the merge sort algorithm. Depending on the size of the lists that are
ordered, the single-threaded version is often faster due not only to the
overhead of thread creation on the multi-threaded version but also because
the merge of the sorted sub-lists, where the bulk of the sorting work is
performed, does not take advantage of multi-threading.
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

@ -1,50 +0,0 @@
=================================================================
Logtalk - Object oriented extension to Prolog
Release 2.29.5
Copyright (c) 1998-2007 Paulo Moura. All Rights Reserved.
=================================================================
% start by loading the example and the required library files:
| ?- logtalk_load(msort(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 sort it using a single thread:
?- generator::list(75000, List), time(msort(1)::msort(List, Sorted)).
% 4,864,942 inferences, 3.25 CPU in 3.42 seconds (95% CPU, 1496905 Lips)
List = [0.0923009, 0.443585, 0.72304, 0.945816, 0.501491, 0.311327, 0.597448, 0.915656, 0.666957|...],
Sorted = [1.39358e-06, 3.65916e-05, 4.01297e-05, 4.06822e-05, 5.07434e-05, 5.89827e-05, 6.09007e-05, 0.00010463, 0.000105771|...]
Yes
% generate a big list of random floats and then sort it using two threads:
?- generator::list(75000, List), time(msort(2)::msort(List, Sorted)).
% 300,072 inferences, 1.77 CPU in 1.15 seconds (153% CPU, 169532 Lips)
List = [0.0796181, 0.891391, 0.117642, 0.497486, 0.559702, 0.225095, 0.974507, 0.890696, 0.342357|...],
Sorted = [2.99566e-07, 5.43309e-06, 1.05778e-05, 3.20893e-05, 4.16823e-05, 4.74887e-05, 7.47632e-05, 0.00010165, 0.000111517|...]
Yes
% generate a big list of random floats and then sort it using four threads:
?- generator::list(75000, List), time(msort(4)::msort(List, Sorted)).
% 375,166 inferences, 1.65 CPU in 0.86 seconds (191% CPU, 227373 Lips)
List = [0.720675, 0.0274524, 0.430037, 0.335113, 0.381095, 0.448501, 0.176328, 0.447618, 0.353423|...],
Sorted = [7.91942e-06, 1.90435e-05, 2.04143e-05, 4.50762e-05, 6.8435e-05, 6.99459e-05, 8.55454e-05, 9.07958e-05, 0.000101131|...]
Yes

View File

@ -1,19 +0,0 @@
:- 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

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

View File

@ -1,73 +0,0 @@
:- object(msort(_Threads)).
:- info([
version is 1.0,
author is 'Paulo Moura',
date is 2007/03/24,
comment is 'Single-threaded and multi-threaded versions of the merge sort algorithm.',
parameters is ['Threads'- 'Number of threads to use in sorting. Valid values are 1, 2, and 4.']]).
:- 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),
msort(Threads, List, Sorted).
msort(1, List, Sorted) :-
st_msort(List, Sorted).
msort(2, List, Sorted) :-
mt_msort_2(List, Sorted).
msort(4, List, Sorted) :-
mt_msort_4(List, 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).
mt_msort_2(L, S) :-
split(L, L1, L2),
threaded((
st_msort(L1, S1),
st_msort(L2, S2))),
merge(S1, S2, S).
mt_msort_4(L, S) :-
split(L, L1, L2),
split(L1, L11, L12),
split(L2, L21, L22),
threaded((
st_msort(L11, S11),
st_msort(L12, S12),
st_msort(L21, S21),
st_msort(L22, S22))),
threaded((
merge(S11, S12, S1),
merge(S21, S22, S2))),
merge(S1, S2, S).
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.