Discussion:
Math::Prime::FastSieve v0.12
David Oswald
2012-05-30 19:01:03 UTC
Permalink
Thanks to some great patches from Dana Jacobsen (and some version
numbering snafu from me), we have arrived at Math::Prime::FastSieve
v0.12.

Don't bother with v0.11 (I uploaded with inconsistent version numbering).

v0.12 provides the following enhancements over v0.10:

The prime sieve's bit vector only contains odds, cutting the bit
vector's memory footprint in half, and improving speed performance of
building a sieve considerably (20-30% in some cases). This patch came
from Dana Jacobsen.

I've also taken Dana's suggestion and used unsigned longs internally
(and longs as parameters). This allows Perl's built with long support
to handle (theoretically) sieves up to 9.2e18. ( 2^64 / 2 --- if we
were passing unsigned longs as params it would be 2^64, but
Inline::CPP's typemap doesn't yet support unsigned longs, so we pass
longs).

Generating a sieve of 8_000_000_000 takes 8_000_000_000 / 8 / 2 bytes,
so about 477MB of RAM, and on one of my systems, generates the sieve
in about 40 seconds. A sieve of 3_000_000 can be produced in 1/240th
of a second on the same machine. To my knowledge, M::P::FS is the
fastest primes generator and toolkit on CPAN.

As before, this module depends on Inline::CPP and Inline::MakeMaker.
--
David Oswald
daoswald-***@public.gmane.org
Sisyphus
2012-05-31 01:16:16 UTC
Permalink
----- Original Message -----
From: "David Oswald"
Post by David Oswald
I've also taken Dana's suggestion and used unsigned longs internally
(and longs as parameters). This allows Perl's built with long support
to handle (theoretically) sieves up to 9.2e18. ( 2^64 / 2 --- if we
were passing unsigned longs as params it would be 2^64, but
Inline::CPP's typemap doesn't yet support unsigned longs, so we pass
longs).
IINM you can easily pass an unsigned long to a function that takes a long as
its parameter:

################################
use warnings;

use Inline Config =>
BUILD_NOISY => 1;

use Inline CPP => <<'EOCPP';

void bar(long x) {
unsigned long ul = x;
printf("%u", ul);
}

EOCPP

my $x = 4294967233;
bar($x); # prints 4294967233 for me
# on 5.14.0 and 5.6.2
################################

Is the typemapping of unsigned long that occurs in the perl typemap
unsuitable for Inline::CPP ? ... or is it just that not all versions of perl
provided typemapping of 'unsigned long' ?

If it's the latter, you could just supply your own typemap with the M::P::FS
source, for those versions of perl that don't typemap 'unsigned long'. The
typemap you provide would have a copy'n'paste of the 'unsigned long'
typemapping from one of the later perl typemaps.
At least, that approach worked with Inline::C.

Cheers,
Rob

Loading...