________________________________________________________________________

This file is part of Logtalk <https://logtalk.org/>  
Copyright 1998-2021 Paulo Moura <pmoura@logtalk.org>  
SPDX-License-Identifier: Apache-2.0

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
________________________________________________________________________


% start by loading the loading the example:

| ?- logtalk_load(primes(loader)).
...


% NOTE: the example queries below use a SWI-Prolog proprietary predicate 
% time/1 in order to get accurate goal times. This predicate is also found 
% on recent development versions of YAP and XSB. For other Prolog compilers, 
% replace the time/1 call by any appropriate timing calls (e.g. cputime/0).


% calculate the prime numbers in a given interval using a single thread:

?- time(primes(1)::primes(1, 500000, Primes)).
% 67,657,303 inferences, 11.98 CPU in 12.31 seconds (97% CPU, 5647521 Lips)

Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23|...]

Yes


% calculate the prime numbers in a given interval by splitting the interval 
% in two sub-intervals and using a thread per sub-interval:

?- time(primes(2)::primes(1, 500000, Primes)).
% 77 inferences, 11.73 CPU in 7.48 seconds (157% CPU, 7 Lips)

Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23|...]

Yes


% calculate the prime numbers in a given interval by splitting the interval 
% in four sub-intervals and using a thread per sub-interval:

?- time(primes(4)::primes(1, 500000, Primes)).
% 143 inferences, 11.62 CPU in 4.00 seconds (290% CPU, 12 Lips)

Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23|...]

Yes


% calculate the prime numbers in a given interval by splitting the interval 
% in eight sub-intervals and using a thread per sub-interval:

?- time(primes(8)::primes(1, 500000, Primes)).
% 323 inferences, 11.56 CPU in 3.30 seconds (350% CPU, 28 Lips)

Primes = [2, 3, 5, 7, 11, 13, 17, 19, 23|...]

Yes
