Re: Sieve of Erastosthenes optimized to the max

Liste des GroupesRevenir à cl c++ 
Sujet : Re: Sieve of Erastosthenes optimized to the max
De : vir.campestris (at) *nospam* invalid.invalid (Vir Campestris)
Groupes : comp.lang.c++
Date : 03. Jul 2024, 11:25:15
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <v638ud$25623$1@dont-email.me>
References : 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
User-Agent : Mozilla Thunderbird
On 02/07/2024 07:20, Tim Rentsch wrote:
I got the code.  There were some line wrappings but I just went
through and fixed those by hand.  After fixing the problem line
wraps I was able to compile and run the code (I used std=c++17,
which apparently works okay).  I did a simple check to make sure
the primes being found are right, which they do indeed seem to
be.  I haven't really experimented with changing the code;  I
only just ran it with various bounds on what primes to find,
mostly to get a sense of the performance.
 I admit I don't understand the scheme the code is using.  It
looks to me like the code is doing divisions and remainders a
lot, which my code basically doesn't do at all (it does do one
division for each prime up to the square root of the limit of
primes being sought, but that's all).  I know the big template
near the beginning is crucial to understanding what the code is
doing, but I haven't been able to figure out what abstraction
that template is supposed to represent.  The core of my program
is between 50 and 60 lines, and all pretty straightforward.
 Is there some suggestion you could make or a question you would
like to ask?  What can I do that might be helpful?
I checked. The modulus operations (%) are easy to check for.
There are two for each prime number. Not for each multiple of it, but for the primes themselves.
And there's one in the "get" function that checks to see if a number is prime.
The complexity is at least partly due to an optimisation.
You'll recall perhaps that Bonita's original code preset the entire bitmap to aa - which is faster than setting all the numbers divisible by 2. I pointed out that you don't even need to set them, and set off to write code that stored odd numbers only.
But then I realised that if you store the mask for 3 only you get a pattern. It has one odd word at the beginning, then a repeating pattern of 3 words. It doesn't matter what the word size is.
This is equally true of 5, 7, 11 and the first few primes. It's also true if you set the mask up for 3 and 5 together - except this time the repeat length is 15.
And it's far faster to duplicate those 3, or 15, or 3*5*7, words than to do each prime individually.
There comes a point where it isn't worth it though - the repeat length for all the primes up to 31 is 1.5E12.
Exactly when it stops being worthwhile isn't obvious.
Then you came along with the mod30 suggestion. There is still a repeat length though, and it's still worth merging masks for small primes together rather than doing each one individually. But the code is bigger. MUCH bigger.
Andy

Date Sujet#  Auteur
30 Jun 24 * Re: Sieve of Erastosthenes optimized to the max54Vir Campestris
2 Jul 24 `* Re: Sieve of Erastosthenes optimized to the max53Tim Rentsch
2 Jul 24  +- Re: Sieve of Erastosthenes optimized to the max1Vir Campestris
3 Jul 24  `* Re: Sieve of Erastosthenes optimized to the max51Vir Campestris
15 Jul 24   +- Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
20 Jul 24   +* Re: Sieve of Erastosthenes optimized to the max48Tim Rentsch
25 Jul 24   i`* OT: Re: Sieve of Erastosthenes optimized to the max47Vir Campestris
10 Aug 24   i +* Re: OT: Re: Sieve of Erastosthenes optimized to the max44Tim Rentsch
12 Aug 24   i i+* Re: OT: Re: Sieve of Erastosthenes optimized to the max2Vir Campestris
16 Aug 24   i ii`- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
15 Aug 24   i i`* Re: OT: Re: Sieve of Erastosthenes optimized to the max41Vir Campestris
16 Aug 24   i i `* Re: OT: Re: Sieve of Erastosthenes optimized to the max40Tim Rentsch
16 Aug 24   i i  +* Re: OT: Re: Sieve of Erastosthenes optimized to the max38Bonita Montero
16 Aug 24   i i  i+- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
19 Aug 24   i i  i+* Re: OT: Re: Sieve of Erastosthenes optimized to the max19Vir Campestris
20 Aug 24   i i  ii`* Re: OT: Re: Sieve of Erastosthenes optimized to the max18Bonita Montero
20 Aug 24   i i  ii `* Re: OT: Re: Sieve of Erastosthenes optimized to the max17Bonita Montero
20 Aug 24   i i  ii  +- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
20 Aug 24   i i  ii  `* Re: OT: Re: Sieve of Erastosthenes optimized to the max15Vir Campestris
20 Aug 24   i i  ii   +- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
26 Aug 24   i i  ii   `* Re: OT: Re: Sieve of Erastosthenes optimized to the max13Tim Rentsch
27 Aug 24   i i  ii    `* Re: OT: Re: Sieve of Erastosthenes optimized to the max12Bonita Montero
1 Sep 24   i i  ii     `* Re: OT: Re: Sieve of Erastosthenes optimized to the max11Vir Campestris
2 Sep 24   i i  ii      `* Re: OT: Re: Sieve of Erastosthenes optimized to the max10Tim Rentsch
2 Sep 24   i i  ii       +- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
3 Sep 24   i i  ii       `* Re: OT: Re: Sieve of Erastosthenes optimized to the max8Vir Campestris
28 Sep 24   i i  ii        `* Re: OT: Re: Sieve of Erastosthenes optimized to the max7Tim Rentsch
28 Sep 24   i i  ii         `* Re: OT: Re: Sieve of Erastosthenes optimized to the max6Keith Thompson
2 Oct 24   i i  ii          `* Re: OT: Re: Sieve of Erastosthenes optimized to the max5Vir Campestris
2 Oct 24   i i  ii           +- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
7 Oct 24   i i  ii           `* Re: OT: Re: Sieve of Erastosthenes optimized to the max3Tim Rentsch
20 Oct 24   i i  ii            `* Re: OT: Re: Sieve of Erastosthenes optimized to the max2Vir Campestris
4 Nov 24   i i  ii             `- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
19 Aug 24   i i  i+* Re: OT: Re: Sieve of Erastosthenes optimized to the max12Vir Campestris
20 Aug 24   i i  ii+* Re: OT: Re: Sieve of Erastosthenes optimized to the max4red floyd
20 Aug 24   i i  iii+* Re: OT: Re: Sieve of Erastosthenes optimized to the max2Vir Campestris
26 Aug 24   i i  iiii`- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
26 Aug 24   i i  iii`- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
20 Aug 24   i i  ii+* Re: OT: Re: Sieve of Erastosthenes optimized to the max3Bonita Montero
20 Aug 24   i i  iii+- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
20 Aug 24   i i  iii`- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Bonita Montero
20 Aug 24   i i  ii`* Re: OT: Re: Sieve of Erastosthenes optimized to the max4Bonita Montero
22 Aug 24   i i  ii `* Re: OT: Re: Sieve of Erastosthenes optimized to the max3Vir Campestris
22 Aug 24   i i  ii  `* Re: OT: Re: Sieve of Erastosthenes optimized to the max2Bonita Montero
22 Aug 24   i i  ii   `- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Vir Campestris
22 Aug 24   i i  i`* Re: OT: Re: Sieve of Erastosthenes optimized to the max5Vir Campestris
23 Aug 24   i i  i +* Re: OT: Re: Sieve of Erastosthenes optimized to the max3red floyd
26 Aug 24   i i  i i+- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
28 Sep 24   i i  i i`- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Andrey Tarasevich
26 Aug 24   i i  i `- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
19 Aug 24   i i  `- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
11 Aug 24   i +- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
11 Aug 24   i `- Re: OT: Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch
23 Jul 24   `- Re: Sieve of Erastosthenes optimized to the max1Tim Rentsch

Haut de la page

Les messages affichés proviennent d'usenet.

NewsPortal