Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

"America is a stronger nation for the ACLU's uncompromising effort." -- President John F. Kennedy


devel / comp.lang.c++ / Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

SubjectAuthor
* Sieve of Erastosthenes optimized to the maxBonita Montero
+* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
| `* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  +* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|  |`* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  | +* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  | |`- Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  | `* Re: Sieve of Erastosthenes optimized to the maxred floyd
|  |  `* Re: Sieve of Erastosthenes optimized to the maxTim Rentsch
|  |   `* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  |    `* Re: Sieve of Erastosthenes optimized to the maxTim Rentsch
|  |     `* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|  |      `- Re: Sieve of Erastosthenes optimized to the maxTim Rentsch
|  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|   `* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|    +- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|    +- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|    `* Re: Sieve of Erastosthenes optimized to the maxTim Rentsch
|     `* Re: Sieve of Erastosthenes optimized to the maxVir Campestris
|      `- Re: Sieve of Erastosthenes optimized to the maxTim Rentsch
+* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
| `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|   `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|    `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|     `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|      `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|       `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|        `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|         `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          +* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |`* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          | `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |   `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |    `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |     `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |      `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       +* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | +* Re: Sieve of Erastosthenes optimized to the maxDavid Brown
|          |       | |`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | | `* Re: Sieve of Erastosthenes optimized to the maxDavid Brown
|          |       | |  +- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  `* Re: Sieve of Erastosthenes optimized to the maxScott Lurndal
|          |       | |   `- Re: Sieve of Erastosthenes optimized to the maxDavid Brown
|          |       | +* Re: Sieve of Erastosthenes optimized to the maxScott Lurndal
|          |       | |+* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | ||`- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | |`* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | | `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | |  +* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |+- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | |  |`* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  | `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |  +* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  |  |`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |  | `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  |  |  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |  |   `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  |  |    `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |  |     `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  |  |      `- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |  `* Re: Sieve of Erastosthenes optimized to the maxScott Lurndal
|          |       | |  |   `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |    `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |  |     `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       | |  |      `- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | |  `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       | |   `- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       | `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       |  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |   `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |    +* Re: Sieve of Erastosthenes optimized to the maxred floyd
|          |       |    |`- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |    `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     +* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |`* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     | `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |  `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |   `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |    `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |     `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |      `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |       `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |        `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |         `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |          `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |           `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       |     |            `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |             `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |              +* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |              |`- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |              `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |               `* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |                `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |                 +* Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |                 |`* Re: Sieve of Erastosthenes optimized to the maxred floyd
|          |       |     |                 | +- Re: Sieve of Erastosthenes optimized to the maxBonita Montero
|          |       |     |                 | `- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       |     |                 `* Re: Sieve of Erastosthenes optimized to the maxKaz Kylheku
|          |       |     `- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          |       `- Re: Sieve of Erastosthenes optimized to the maxChris M. Thomasson
|          `* Re: Sieve of Erastosthenes optimized to the maxBonita Montero
`* Re: Sieve of Erastosthenes optimized to the maxwij

Pages:123456
Re: Sieve of Erastosthenes optimized to the max

<unhlaq$1lj9s$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3040&group=comp.lang.c%2B%2B#3040

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Mon, 8 Jan 2024 12:18:34 -0800
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <unhlaq$1lj9s$2@dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<20231229092738.13@kylheku.com>
<umo79t$165i5$2@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 8 Jan 2024 20:18:35 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="125f82ba8d31f55934c12cbd9b2d140a";
logging-data="1756476"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19A9MDDKjdVMHfo+f9OgL5VGx7a4g7dGh0="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:poK7iPta9+DEwdSiX8cVRLT/XCE=
Content-Language: en-US
In-Reply-To: <ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
 by: Chris M. Thomasson - Mon, 8 Jan 2024 20:18 UTC

On 1/7/2024 9:48 PM, Bonita Montero wrote:
> Am 07.01.2024 um 21:46 schrieb Chris M. Thomasson:
>
>> I know that they had a problem and the provided workaround from Intel
>> really did help out. ...
>
> Absolutely not, not with four way associativity.
>

Whatever you say; Sigh. I am done with this.

Re: Sieve of Erastosthenes optimized to the max

<uni6mg$1ns04$1@redfloyd.dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3041&group=comp.lang.c%2B%2B#3041

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!redfloyd.dont-email.me!.POSTED!not-for-mail
From: no.spam....@its.invalid (red floyd)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Mon, 8 Jan 2024 17:14:55 -0800
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <uni6mg$1ns04$1@redfloyd.dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umo79t$165i5$2@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<unhlaq$1lj9s$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 Jan 2024 01:14:56 -0000 (UTC)
Injection-Info: redfloyd.dont-email.me; posting-host="cda13e1985e4cf100d1b5261272bc67c";
logging-data="1830916"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18r609uxzBmqaDcuCDC7TZds7fs9vD/6HM="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:yJ4uyudRfSbzceRu1z1xU11Swgk=
Content-Language: en-US
In-Reply-To: <unhlaq$1lj9s$2@dont-email.me>
 by: red floyd - Tue, 9 Jan 2024 01:14 UTC

On 1/8/2024 12:18 PM, Chris M. Thomasson wrote:
> On 1/7/2024 9:48 PM, Bonita Montero wrote:
>> Am 07.01.2024 um 21:46 schrieb Chris M. Thomasson:
>>
>>> I know that they had a problem and the provided workaround from Intel
>>> really did help out. ...
>>
>> Absolutely not, not with four way associativity.
>>
>
> Whatever you say; Sigh. I am done with this.

Intel just needs to call Bonita whenever they have an issue.

Re: Sieve of Erastosthenes optimized to the max

<20240108175039.572@kylheku.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3042&group=comp.lang.c%2B%2B#3042

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: 433-929-...@kylheku.com (Kaz Kylheku)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Tue, 9 Jan 2024 02:02:13 -0000 (UTC)
Organization: A noiseless patient Spider
Lines: 40
Message-ID: <20240108175039.572@kylheku.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umo79t$165i5$2@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
Injection-Date: Tue, 9 Jan 2024 02:02:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="b95bb188c8d5daa6c75d93fb3ca754eb";
logging-data="1842559"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/gCnC63BYXd9XzjrEf5ZMwV94u3+eeZ2E="
User-Agent: slrn/pre1.0.4-9 (Linux)
Cancel-Lock: sha1:YRWtVMJfNhQbchDphyKQvfG3/4M=
 by: Kaz Kylheku - Tue, 9 Jan 2024 02:02 UTC

On 2024-01-08, Bonita Montero <Bonita.Montero@gmail.com> wrote:
> Am 07.01.2024 um 21:46 schrieb Chris M. Thomasson:
>
>> I know that they had a problem and the provided workaround from Intel
>> really did help out. ...
>
> Absolutely not, not with four way associativity.

You are referring to that as if it were some rescuing magic.

Four way associativity is quite poor. It's only a step above two-way,
which is a step above the bottom of the barrel: direct mapping.

The cache entries are tiny on the P4: 32 bytes. An entire set is just
128 bytes. Code that works intensely with a 128 byte block occupies
the entire set of four cache blocks. If anything else touches memory
that maps to the same set, an evacuation has to take place, and
then when that code is resumed, it will take a hit.

If two hyperthreads run the same function which works intensively
with a 128 byte area of the stack, and the distance between the
stacks is a multiple of 8K, they will interfere through the same
cache set. The cache set is 128 bytes; each thread wants to keep
its own 128 bytes in it.

The situation seems far from improbable to me.

We don't need more than four hyper-threads in order to blow the
four-way set associative cache. We just need more than one
in the above scenario.

Needing more that four would be the case for threads that are hammering
away on a 32 byte block. (And so since there are only two hyperthreads
on the P4, that wouldn't be a problem.)

--
TXR Programming Language: http://nongnu.org/txr
Cygnal: Cygwin Native Application Library: http://kylheku.com/cygnal
Mastodon: @Kazinator@mstdn.ca
NOTE: If you use Google Groups, I don't see you, unless you're whitelisted.

Re: Sieve of Erastosthenes optimized to the max

<unioh9$1tmb9$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3043&group=comp.lang.c%2B%2B#3043

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Tue, 9 Jan 2024 07:19:22 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <unioh9$1tmb9$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<unhlaq$1lj9s$2@dont-email.me> <uni6mg$1ns04$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 Jan 2024 06:19:21 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="794523f82a83ed73bb238ef348acdde0";
logging-data="2021737"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+gPHPJ9zkjgNmRi4Zzmj4TUN4sHbA2okc="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:AGdT5n7HvQ0pEb15OlzZszHy9Nk=
Content-Language: de-DE
In-Reply-To: <uni6mg$1ns04$1@redfloyd.dont-email.me>
 by: Bonita Montero - Tue, 9 Jan 2024 06:19 UTC

Am 09.01.2024 um 02:14 schrieb red floyd:
> On 1/8/2024 12:18 PM, Chris M. Thomasson wrote:
>> On 1/7/2024 9:48 PM, Bonita Montero wrote:
>>> Am 07.01.2024 um 21:46 schrieb Chris M. Thomasson:
>>>
>>>> I know that they had a problem and the provided workaround from
>>>> Intel really did help out. ...
>>>
>>> Absolutely not, not with four way associativity.
>>>
>>
>> Whatever you say; Sigh. I am done with this.
>
> Intel just needs to call Bonita whenever they have an issue.

Intel made a lot of mistakes with Pentium 4 and Itanium.
This is rather a minor "mistake".

Re: Sieve of Erastosthenes optimized to the max

<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3044&group=comp.lang.c%2B%2B#3044

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Tue, 9 Jan 2024 15:12:05 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umo79t$165i5$2@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 9 Jan 2024 14:12:04 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="794523f82a83ed73bb238ef348acdde0";
logging-data="2145208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19SduBYWemNKV0/CXP0uwCpXG/I9mOONmU="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:X71nkuCmCOs37XPz4jW55Thu5hM=
In-Reply-To: <20240108175039.572@kylheku.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 9 Jan 2024 14:12 UTC

Am 09.01.2024 um 03:02 schrieb Kaz Kylheku:

> Four way associativity is quite poor. It's only a step above two-way,
> which is a step above the bottom of the barrel: direct mapping.

That's your opinion. In 2000 this was o.k.

> The cache entries are tiny on the P4: 32 bytes.

No, the L1 line size is 64 bytes.

> An entire set is just 128 bytes.

No, four lines each 64 bytes.

Re: Sieve of Erastosthenes optimized to the max

<unlh8d$2dhg7$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3045&group=comp.lang.c%2B%2B#3045

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Tue, 9 Jan 2024 23:33:32 -0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <unlh8d$2dhg7$1@dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<unhlaq$1lj9s$2@dont-email.me> <uni6mg$1ns04$1@redfloyd.dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 10 Jan 2024 07:33:33 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="895382d1d7b553b27dcc9759fae19b1a";
logging-data="2541063"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+r8m2QJnu57LjVmYOGr8sAMuJXsFNkvII="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:aB13BE1hSzd/YM6BWx8Zf/M6Hxo=
In-Reply-To: <uni6mg$1ns04$1@redfloyd.dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Wed, 10 Jan 2024 07:33 UTC

On 1/8/2024 5:14 PM, red floyd wrote:
> On 1/8/2024 12:18 PM, Chris M. Thomasson wrote:
>> On 1/7/2024 9:48 PM, Bonita Montero wrote:
>>> Am 07.01.2024 um 21:46 schrieb Chris M. Thomasson:
>>>
>>>> I know that they had a problem and the provided workaround from
>>>> Intel really did help out. ...
>>>
>>> Absolutely not, not with four way associativity.
>>>
>>
>> Whatever you say; Sigh. I am done with this.
>
> Intel just needs to call Bonita whenever they have an issue.
>

Okay. You just made me laugh so hard I started to cough a bit! Wow.
Cleaned out the pipes, so to speak. Thanks. ROFL! Cough...

:^D

Re: Sieve of Erastosthenes optimized to the max

<865xzwmqf5.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3046&group=comp.lang.c%2B%2B#3046

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Sat, 13 Jan 2024 21:31:42 -0800
Organization: A noiseless patient Spider
Lines: 53
Message-ID: <865xzwmqf5.fsf@linuxsc.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <ul5bn0$2qsht$2@dont-email.me> <ul5ut3$31a17$1@raubtier-asyl.eternal-september.org> <ul7ft1$3853g$1@dont-email.me> <ul7gal$3885r$1@raubtier-asyl.eternal-september.org> <ulchs1$t3ph$1@dont-email.me> <ulfa02$1er97$1@redfloyd.dont-email.me> <86edfcvkjm.fsf@linuxsc.com> <um7iva$27ikh$1@dont-email.me> <86a5q0uhd1.fsf@linuxsc.com> <umn1ma$svun$7@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="8638bc13aeaeb22b15b54cee031022ba";
logging-data="363857"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/iMI9akCeg+W8+QUAOF36EUkx9P9Mci60="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:t2RIV+H8H3cZEHFzhMxP++4/bi0=
sha1:TEUw05wEOftD8OUK2WrtAV9w/S0=
 by: Tim Rentsch - Sun, 14 Jan 2024 05:31 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> On 24/12/2023 08:36, Tim Rentsch wrote:
>
>> Depending on how the code is written, no modulo operations need
>> to be done, because they will be optimized away and done at
>> compile time. If we look at multiplying two numbers represented
>> by bits in bytes i and j, the two numbers are
>>
>> i*30 + a
>> j*30 + b
>>
>> for some a and b in { 1, 7, 11, 13 17, 19, 23, 29 }.
>>
>> The values we're interested in are the index of the product and
>> the residue of the product, namely
>>
>> (i*30+a) * (j*30+b) / 30 (for the index)
>> (i*30+a) * (j*30+b) % 30 (for the residue)
>>
>> Any term with a *30 in the numerator doesn't contribute to
>> the residue, and also can be combined with the by-30 divide
>> for computing the index. Thus these expressions can be
>> rewritten as
>>
>> i*30*j + i*b + j*a + (a*b/30) (for the index)
>> a*b%30 (for the residue)
>>
>> When a and b have values that are known at compile time,
>> neither the divide nor the remainder result in run-time
>> operations being done; all of that heavy lifting is
>> optimized away and done at compile time. Of course there
>> are some multiplies, but they are cheaper than divides, and
>> also can be done in parallel. (The multiplication a*b also
>> can be done at compile time.)
>>
>> The residue needs to be turned into a bit mask to do the
>> logical operation on the byte of bits, but here again that
>> computation can be optimized away and done at compile time.
>>
>> Does that all make sense?
>
> Right now, no. But that's me. I'll flag it to read again when I've
> had a better night's sleep.

I'm posting to nudge you into looking at this again, if
you haven't already.

I have now had a chance to get your source and run some
comparisons. A program along the lines I outlined can run much
faster than the code you posted (as well as needing less memory).
A good target is to find all primes less than 1e11, which needs
less than 4gB of ram.

OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<up95f1$kibc$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3094&group=comp.lang.c%2B%2B#3094

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!usenet.network!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: vir.camp...@invalid.invalid (Vir Campestris)
Newsgroups: comp.lang.c++
Subject: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the
max)
Date: Mon, 29 Jan 2024 21:31:12 +0000
Organization: A noiseless patient Spider
Lines: 97
Message-ID: <up95f1$kibc$1@dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umpspm$1cphn$1@dont-email.me>
<umqvhh$1kvj6$1@raubtier-asyl.eternal-september.org>
<umsfrt$1qvlo$1@dont-email.me>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Mon, 29 Jan 2024 21:31:13 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="53bbc510e8b7410575590e14d0f9fa70";
logging-data="674156"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX184KGZVG1rlcYTFUQGdvQeXJUgJU6HbD+I="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:dJNXb4ZBn2xakVyY0gObMCDMfl8=
In-Reply-To: <unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
Content-Language: en-GB
 by: Vir Campestris - Mon, 29 Jan 2024 21:31 UTC

I retired last year, and I haven't really written any code since. This
has turned out to be quite a fun little thing of a type I haven't had
time for for YEARS. And oddly I still don't seem to have enough time for
it... It's the garden, and the kid's gardens, and my mum's garden, and
all those holidays :)

But some optimisations. You'll remember in Bonita's first version the
bitmap was initialised to 0xaaaa, because it's a waste of time doing the
sieve for 2.

I pointed out that we don't need to even store the even numbers.

But there's more.

If you look at the bitmap when you've sieved for 2 you see

12 34 56 78
11 10 10 10...
which is a repeat of 2 after an initialisation word. That's the aaaa.

You can do the same with 3

123 456 789
111 110 110 110

except this time the repeat is 3. And annoyingly that doesn't map well
down onto a byte-based architecture. You end up with an initial word,
then a 3-word repeat. (If your word was 24 or 36 bytes it would only be
1 word, but I haven't seen that since the 1970s)

In hex, with lowest byte first, that is
fd b6 6d db b6 6d db

(That BTW is the same if you only store the odd numbers - a 3-word repeat.)

So rather than start off with your bitmap all set to 1s you can set it
to this repeating pattern. That replaces all the ANDs for all the values
of three with a memory fill with far fewer accesses.

You can do the same with 5:

12345 6789a bcdef
11111 11110 11110 11110

You can then AND your pattern for 3 with the one for 5, and get one with
a repeat length of 15, and set that into your bitmap. You've now
replaced about a fifth of all your AND operations with a flood fill.

This can carry on - for a while. Only a short while. You _can_ make a
sequence for lots of primes. But it gets quite long, quite quickly. For
up to 23, and not storing the evens, it's over 1E8 words long!

I was implementing a version of that when something else occurred to me.
You can sacrifice speed for store size if you're prepared to do an
integer divide for every prime lookup.

Group our numbers into 6s like this

012345
6789ab
cdefgh (YKWIM)
ijklmn

Mask out the ones divisible by 2 or 3 and you see

0123-5
-7---b
-d---h
-i---n

Except for the first "page" the pattern is identical. Your algorithm can be:
Divide your candidate by 6.
If the result is zero look up in the page zero table 0123-5
If it is non-zero index into a translation table like this
010002
If the translation is zero the number is not prime.
If it is not zero it is the index of the bit for this page which tells
me if the number is prime. And there need only be 2 bits for 6 numbers.

(6 is the product of the first primes 2 and 3)

It's still worth masking out the even numbers - they don't need the
divide, a simple AND detects them - and I suspect it's worth using a
much larger number than 6. 3*5*11*13 is 15,015, which seems as though it
might be a convenient size. And only about a third of the number aren't
known to be primes (5760 to be exact)

I might play with that idea some time.

But a note for the group of course - optimising this to the max has
nothing to do whatever with C++. The only C++ optimising I've found
myself doing is using raw pointers, not vector's operator[]. (certainly
not the at function). And also I found myself using emplace_back a lot.
It's a PITA because you can only emplace back a single item, and it is slow.

Andy

Re: Sieve of Erastosthenes optimized to the max

<166fa939a9a7a5efc03bf538eb04016de4d932fc.camel@gmail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3148&group=comp.lang.c%2B%2B#3148

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wynii...@gmail.com (wij)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Wed, 14 Feb 2024 00:15:37 +0800
Organization: A noiseless patient Spider
Lines: 430
Message-ID: <166fa939a9a7a5efc03bf538eb04016de4d932fc.camel@gmail.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="baa3c76df66cc705adf409e5dce5b124";
logging-data="2259553"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+kWc5DN27objxSJDJxchHt"
User-Agent: Evolution 3.50.2 (3.50.2-1.fc39)
Cancel-Lock: sha1:Bib/9lUnW8xRPTCNvW6siZt6Hu4=
In-Reply-To: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
 by: wij - Tue, 13 Feb 2024 16:15 UTC

On Sun, 2023-12-10 at 10:46 +0100, Bonita Montero wrote:
> I've parallelized my sieve of Erastosthenes to all cores. The
> parallel
> threads do al the punching of the non-prime multiplex beyond sqrt(
> max
> ). I found that the algorithm is limited by the memory bandwith since
> the bit-range between sqrt( max ) and max is to large to fit inside
> the cache. So I partitioned the each thread to a number of bit-ranges
> that fits inside the L2-cache. With that I got a speedup of factor 28
> when calculating about the first 210 million primes, i.e. all primes
> <= 2 ^ 32.
> On my Zen4 16 core PC under Windows with clang-cl 16.0.5 producing
> the
> primes without any file output is only 0.28s. On my Linux-PC, a Zen2
> 64
> core CPU producing the same number of primes is about 0.09s.
> The file output is done with my own buffering. With that writing the
> mentioned prime number range results in a 2.2GB file which is written
> in about two seconds with a PCIe 4.0 SSD.
> The first parameter is the highest prime candidate to be generated,
> it can be prefixed with 0x for hex values. The second number is the
> name of the output file; it can be "" to suppress file output. The
> third parameter is the number of punching threads; if it is left the
> number of threads defaults to the number of threads reported by the
> runtime.
>
> #include <iostream>
> #include <cstdlib>
> #include <charconv>
> #include <cstring>
> #include <vector>
> #include <algorithm>
> #include <cmath>
> #include <bit>
> #include <fstream>
> #include <string_view>
> #include <thread>
> #include <mutex>
> #include <condition_variable>
> #include <utility>
> #include <semaphore>
> #include <atomic>
> #include <new>
> #include <span>
> #if defined(_MSC_VER)
> #include <intrin.h>
> #elif defined(__GNUC__) || defined(__clang__)
> #include <cpuid.h>
> #endif
>
> #if defined(_MSC_VER)
> #pragma warning(disable: 26495)
> #endif
>
> using namespace std;
>
> #if defined(__cpp_lib_hardware_interference_size)
> constexpr ptrdiff_t CL_SIZE = hardware_destructive_interference_size;
> #else
> constexpr ptrdiff_t CL_SIZE = 64;
> #endif
>
> size_t getL2Size();
>
> int main( int argc, char **argv )
> {
> if( argc < 2 )
> return EXIT_FAILURE;
> auto parse = []( char const *str, bool hex, auto &value )
> {
> from_chars_result fcr = from_chars( str, str +
> strlen( str ), value,
> !hex ? 10 : 16 );
> return fcr.ec == errc() && !*fcr.ptr;
> };
> char const *sizeStr = argv[1];
> bool hex = sizeStr[0] == '0' && (sizeStr[1] == 'x' ||
> sizeStr[1] == 'X');
> sizeStr += 2 * hex;
> size_t end;
> if( !parse( sizeStr, hex, end ) )
> return EXIT_FAILURE;
> if( (ptrdiff_t)end++ < 0 )
> throw bad_alloc();
> unsigned hc;
> if( argc < 4 || !parse( argv[3], false, hc ) )
> hc = jthread::hardware_concurrency();
> if( !hc )
> return EXIT_FAILURE;
> using word_t = size_t;
> constexpr size_t
> BITS = sizeof(word_t) * 8,
> CL_BITS = CL_SIZE * 8;
> union alignas(CL_SIZE) ndi_words_cl { word_t words[CL_SIZE /
> sizeof(word_t)]; ndi_words_cl() {} };
> size_t nCls = (end + CL_BITS - 1) / CL_BITS;
> vector<ndi_words_cl> sieveCachelines( (end + CL_BITS - 1) /
> CL_BITS );
> size_t nWords = (end + BITS - 1) / BITS;
> span<word_t> sieve( &sieveCachelines[0].words[0], nWords );
> auto fill = sieve.begin();
> *fill++ = (word_t)0xAAAAAAAAAAAAAAACu;
> if( fill != sieve.end() )
> for_each( fill, sieve.end(), []( word_t &w  ) { w =
> (word_t)0xAAAAAAAAAAAAAAAAu; } );
> size_t sqrt = (ptrdiff_t)ceil( ::sqrt( (ptrdiff_t)end ) );
> auto punch = [&]( auto, size_t start, size_t end, size_t
> prime )
> {
> if( start >= end )
> return;
> size_t multiple = start;
> if( prime >= BITS ) [[likely]]
> do
> sieve[multiple / BITS] &= rotl(
> (word_t)-2, multiple % BITS );
> while( (multiple += prime) < end );
> else
> {
> auto pSieve = sieve.begin() + multiple /
> BITS;
> do
> {
> word_t
> word = *pSieve,
> mask = rotl( (word_t)-2,
> multiple % BITS ),
> oldMask;
> do
> word &= mask,
> oldMask = mask,
> mask = rotl( mask, prime %
> BITS ),
> multiple += prime;
> while( mask < oldMask );
> *pSieve++ = word;
> } while( multiple < end );
> }
> };
> for( size_t prime = 3; prime < sqrt; ++prime )
> {
> for( auto pSieve = sieve.begin() + prime / BITS; ; )
> {
> if( word_t w = *pSieve >> prime % BITS; w )
> [[likely]]
> {
> prime += countr_zero( w );
> break;
> }
> prime = prime + BITS & -(ptrdiff_t)BITS;
> if( prime >= sqrt )
> break;
> }
> if( prime >= sqrt ) [[unlikely]]
> break;
> punch( false_type(), prime * prime, sqrt, prime );
> }
> auto scan = [&]( size_t start, size_t end, auto fn )
> {
> for( size_t prime = start; prime < end; )
> {
> word_t word = sieve[prime / BITS] >> prime %
> BITS;
> bool hasBits = word;
> for( unsigned gap; word; word >>= gap, word
> >>= 1 )
> {
> gap = countr_zero( word );
> if( (prime += gap) >= end )
> [[unlikely]]
> return;
> fn( prime );
> if( ++prime >= end ) [[unlikely]]
> return;
> }
> prime = (prime + BITS - hasBits) & -
> (ptrdiff_t)BITS;
> }
> };
> size_t bitsPerPartition = (end - sqrt) / hc;
> using range_t = pair<size_t, size_t>;
> vector<pair<size_t, size_t>> ranges;
> ranges.reserve( hc );
> for( size_t t = hc, rEnd = end, rStart; t--; rEnd = rStart )
> {
> rStart = sqrt + t * bitsPerPartition;
> size_t rClStart = rStart & -(CL_SIZE * 8);
> rStart = rClStart >= sqrt ? rClStart : sqrt;
> if( rStart >= rEnd )
> continue;
> ranges.emplace_back( rStart, rEnd );
> }
> vector<jthread> threads;
> threads.reserve( ranges.size() - 1 );
> static auto dbl = []( ptrdiff_t x ) { return (double)x; };
> double maxPartitionBits = dbl( getL2Size() ) * 8 / 3;
> for( range_t const &range : ranges )
> {
> auto rangePuncher = [&]( size_t rStart, size_t rEnd
> )
> {
> double nBits = dbl( rEnd - rStart );
> ptrdiff_t nPartitions = (ptrdiff_t)ceil(
> nBits / maxPartitionBits );
> double bitsPerPartition = nBits / dbl(
> nPartitions );
> for( ptrdiff_t p = nPartitions, pEnd = rEnd,
> pStart; p--; pEnd = pStart )
> {
> pStart = rStart +
> (ptrdiff_t)((double)p * bitsPerPartition);
> pStart &= -(CL_SIZE * 8);
> scan( 3, sqrt,
> [&]( size_t prime )
> {
> punch( true_type(),
> (pStart + prime - 1) / prime * prime, pEnd,
> prime );
> } );
> }
> };
> if( &range != &ranges.back() )
> threads.emplace_back( rangePuncher,
> range.first, range.second );
> else
> rangePuncher( range.first, range.second );
> }
> threads.resize( 0 );
> if( argc >= 3 && !*argv[2] )
> return EXIT_SUCCESS;
> ofstream ofs;
> ofs.exceptions( ofstream::failbit | ofstream::badbit );
> ofs.open( argc >= 3 ? argv[2] : "primes.txt",
> ofstream::binary |
> ofstream::trunc );
> constexpr size_t
> BUF_SIZE = 0x100000,
> AHEAD = 32;
> union ndi_char { char c; ndi_char() {} };
> vector<ndi_char> printBuf( BUF_SIZE + AHEAD - 1 );
> auto
> bufBegin = printBuf.begin(),
> bufEnd = bufBegin,
> bufFlush = bufBegin + BUF_SIZE;
> auto print = [&]() { ofs << string_view( &bufBegin->c,
> &to_address(
> bufEnd )->c ); };
> scan( 2, end,
> [&]( size_t prime )
> {
> auto [ptr, ec] = to_chars( &bufEnd->c,
> &bufEnd[AHEAD - 1].c, prime );
> if( ec != errc() ) [[unlikely]]
> throw system_error( (int)ec,
> generic_category(), "converson failed" );
> bufEnd = ptr - &bufBegin->c + bufBegin; //
> pointer to iterator - NOP
> bufEnd++->c = '\n';
> if( bufEnd >= bufFlush ) [[unlikely]]
> print(), bufEnd = bufBegin;
> } );
> print();
> }
>
> size_t getL2Size()
> {
> int regs[4];
> auto cpuId = [&]( unsigned code )
> {
> #if defined(_MSC_VER)
> __cpuid( regs, code );
> #elif defined(__GNUC__) || defined(__clang__)
> __cpuid(code, regs[0], regs[1], regs[2], regs[3]);
> #endif
> return regs[0];
> };
> if( (unsigned)cpuId( 0x80000000u ) < 0x80000006u )
> return 512ull * 1024;
> cpuId( 0x80000006u );
> return ((unsigned)regs[2] >> 16) * 1024;
> }


Click here to read the complete article
Re: Sieve of Erastosthenes optimized to the max

<uqgb64$26mhd$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3149&group=comp.lang.c%2B%2B#3149

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Tue, 13 Feb 2024 19:08:05 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <uqgb64$26mhd$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<166fa939a9a7a5efc03bf538eb04016de4d932fc.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 13 Feb 2024 18:08:04 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="7b36bd74df4b35909f14ed1882a726d1";
logging-data="2316845"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1976V6rEHb4WA8bfdmG72yxz/9m2v9myv8="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:gkY5cKjkFRnNPqKeKqHJtBgvFPU=
In-Reply-To: <166fa939a9a7a5efc03bf538eb04016de4d932fc.camel@gmail.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 13 Feb 2024 18:08 UTC

Am 13.02.2024 um 17:15 schrieb wij:

> I just wrote a class PrimeTab to test prime numbers. It took 73s to
> complete.
> 0.1s is too unbelievable. Something must be wrong.

There's nothing wrong with that. I'm storing the bits as a bitmap and
I'm using a segmented sieve and I partition the part beyond the square
root in chunks which are according to the logical number of CPUs and
these are further divided into chunks which fit into the L2-cache.
And the sequential lookup inside the bitmap below the square root
is done with countl_zero, which maps to a single CPU-instruction
on most computers.
The naive single-threeaded approach without cache-partititioning is
for sure magnitudes slower.

Re: Sieve of Erastosthenes optimized to the max

<uqikcr$2mghj$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3150&group=comp.lang.c%2B%2B#3150

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Wed, 14 Feb 2024 15:57:33 +0100
Organization: A noiseless patient Spider
Lines: 287
Message-ID: <uqikcr$2mghj$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<166fa939a9a7a5efc03bf538eb04016de4d932fc.camel@gmail.com>
<uqgb64$26mhd$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 14 Feb 2024 14:57:31 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="7fea53ed42e32413bd06b66d69b8ffb1";
logging-data="2834995"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+FGt9bU+VSObAqkjMK75F9vf/8uxoJTSY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:l6ydpCiSmF3JJS43bqUNUmUGePc=
In-Reply-To: <uqgb64$26mhd$1@raubtier-asyl.eternal-september.org>
Content-Language: de-DE
 by: Bonita Montero - Wed, 14 Feb 2024 14:57 UTC

Am 13.02.2024 um 19:08 schrieb Bonita Montero:

> There's nothing wrong with that. ...
Test this version which is the latest where I stopped further development:

#include <iostream>
#include <cstdlib>
#include <charconv>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>
#include <bit>
#include <fstream>
#include <string_view>
#include <thread>
#include <utility>
#include <new>
#include <span>
#include <array>
#include <cassert>
#include <sstream>
#if defined(_MSC_VER)
#include <intrin.h>
#elif defined(__GNUC__) || defined(__clang__)
#include <cpuid.h>
#endif

#if defined(_MSC_VER)
#pragma warning(disable: 26495) // uninitialized member
#endif

using namespace std;

#if defined(__cpp_lib_hardware_interference_size)
constexpr ptrdiff_t CL_SIZE = hardware_destructive_interference_size;
#else
constexpr ptrdiff_t CL_SIZE = 64;
#endif

size_t getL2Size();
bool smt();

int main( int argc, char **argv )
{ try
{
if( argc < 2 )
return EXIT_FAILURE;
auto parse = []( char const *str, auto &value )
{
bool hex = str[0] == '0' && tolower( str[1] ) == 'x';
str += 2 * hex;
auto [ptr, ec] = from_chars( str, str + strlen( str ), value, !hex ?
10 : 16 );
return ec == errc() && !*ptr;
};
size_t end;
if( !parse( argv[1], end ) )
return EXIT_FAILURE;
if( end < 2 )
return EXIT_FAILURE;
if( (ptrdiff_t)end++ < 0 )
throw bad_alloc();
unsigned
hc = jthread::hardware_concurrency(),
nThreads;
if( argc < 4 || !parse( argv[3], nThreads ) )
nThreads = hc;
if( !nThreads )
return EXIT_FAILURE;
using word_t = size_t;
constexpr size_t
BITS_PER_CL = CL_SIZE * 8,
BITS = sizeof(word_t) * 8;
size_t nBits = end / 2;
union alignas(CL_SIZE) ndi_words_cl { word_t words[CL_SIZE /
sizeof(word_t)]; ndi_words_cl() {} };
vector<ndi_words_cl> sieveCachelines( (nBits + BITS_PER_CL - 1) /
BITS_PER_CL );
span<word_t> sieve( &sieveCachelines[0].words[0], (nBits + BITS - 1) /
BITS );
assert(to_address( sieve.end() ) <= &to_address( sieveCachelines.end()
)->words[0]);
fill( sieve.begin(), sieve.end(), -1 );
auto punch = [&]( size_t start, size_t end, size_t prime, auto )
{
size_t
bit = start / 2,
bitEnd = end / 2;
if( bit >= bitEnd )
return;
if( prime >= BITS ) [[likely]]
do [[likely]]
sieve[bit / BITS] &= rotl( (word_t)-2, bit % BITS );
while( (bit += prime) < bitEnd );
else
{
auto pSieve = sieve.begin() + bit / BITS;
do [[likely]]
{
word_t
word = *pSieve,
mask = rotl( (word_t)-2, bit % BITS ),
oldMask;
do
word &= mask,
oldMask = mask,
mask = rotl( mask, prime % BITS ),
bit += prime;
while( mask < oldMask );
*pSieve++ = word;
} while( bit < bitEnd );
}
};
size_t sqrt = (ptrdiff_t)ceil( ::sqrt( (ptrdiff_t)end ) );
for( size_t bSqrt = sqrt / 2, bit = 1; bit < bSqrt; ++bit ) [[likely]]
{
auto pSieve = sieve.begin() + bit / BITS;
do [[likely]]
{
if( word_t w = *pSieve >> bit % BITS; w ) [[likely]]
{
bit += countr_zero( w );
break;
}
++pSieve;
bit = bit + BITS & -(ptrdiff_t)BITS;
} while( bit < bSqrt );
if( bit >= bSqrt ) [[unlikely]]
break;
size_t prime = 2 * bit + 1;
punch( prime * prime, sqrt, prime, false_type() );
}
auto scan = [&]( size_t start, size_t end, auto fn )
{
size_t
bit = start / 2,
bitEnd = end / 2;
if( bit >= bitEnd )
return;
auto pSieve = sieve.begin() + bit / BITS;
word_t word = *pSieve++ >> bit % BITS;
for( ; ; )
{
size_t nextWordBit = bit + BITS & -(ptrdiff_t)BITS;
for( unsigned gap; word; word >>= gap, word >>= 1 )
{
gap = countr_zero( word );
bit += gap;
if( bit >= bitEnd ) [[unlikely]]
return;
fn( bit++ * 2 + 1, true_type() );
}
bit = nextWordBit;
if( bit >= bitEnd ) [[unlikely]]
return;
word = *pSieve++;
}
};
static auto dbl = []( ptrdiff_t x ) { return (double)x; };
using range_t = pair<size_t, size_t>;
vector<range_t> ranges;
ranges.reserve( nThreads );
vector<jthread> threads;
threads.reserve( nThreads );
auto initiate = [&]( size_t start, auto fn )
{
ranges.resize( 0 );
double threadRange = dbl( end - start ) / nThreads;
for( size_t t = nThreads, trEnd = end, trStart; t--; trEnd = trStart
) [[likely]]
{
trStart = start + (ptrdiff_t)((ptrdiff_t)t * threadRange + 0.5);
size_t trClStart = trStart & -(2 * CL_SIZE * 8);
trStart = trClStart >= start ? trClStart : start;
if( trStart < trEnd )
ranges.emplace_back( trStart, trEnd );
}
for( range_t const &range : ranges )
if( &range != &ranges.back() )
threads.emplace_back( fn, range.first, range.second, true_type() );
else
fn( range.first, range.second, false_type() );
threads.resize( 0 );
};
double maxCacheRange = dbl( getL2Size() * 8 * 2 ) / 3 * (smt() &&
nThreads > hc / 2 ? 1 : 2);
initiate( sqrt,
[&]( size_t rStart, size_t rEnd, auto )
{
double thisThreadRange = dbl( rEnd - rStart );
ptrdiff_t nCachePartitions = (ptrdiff_t)ceil( thisThreadRange /
maxCacheRange );
double cacheRange = thisThreadRange / dbl( nCachePartitions );
for( size_t p = nCachePartitions, cacheEnd = rEnd, cacheStart; p--;
cacheEnd = cacheStart ) [[likely]]
{
cacheStart = rStart + (ptrdiff_t)((double)(ptrdiff_t)p * cacheRange
+ 0.5);
cacheStart &= -(2 * CL_SIZE * 8);
cacheStart = cacheStart >= sqrt ? cacheStart : sqrt;
scan( 3, sqrt,
[&]( size_t prime, auto )
{
size_t start = (cacheStart + prime - 1) / prime * prime;
start = start % 2 ? start : start + prime;
punch( start, cacheEnd, prime, true_type() );
} );
}
} );
if( bool count = false; argc >= 3 && (!*argv[2] || (count = strcmp(
argv[2], "*" ) == 0)) )
{
if( !count )
return EXIT_SUCCESS;
atomic<size_t> aNPrimes( 1 );
initiate( 3,
[&]( size_t rStart, size_t rEnd, auto )
{
size_t nPrimes = 0;
scan( rStart, rEnd, [&]( ... ) { ++nPrimes; } );
aNPrimes.fetch_add( nPrimes, memory_order::relaxed );
} );
cout << aNPrimes.load( memory_order::relaxed ) << " primes" << endl;
return EXIT_SUCCESS;
}
ofstream ofs;
ofs.exceptions( ofstream::failbit | ofstream::badbit );
ofs.open( argc >= 3 ? argv[2] : "primes.txt", ofstream::binary |
ofstream::trunc );
constexpr size_t
BUF_SIZE = 0x100000,
AHEAD = 32;
union ndi_char { char c; ndi_char() {} };
vector<ndi_char> rawPrintBuf( BUF_SIZE + AHEAD - 1 );
span printBuf( &to_address( rawPrintBuf.begin() )->c, &to_address(
rawPrintBuf.end() )->c );
auto
bufBegin = printBuf.begin(),
bufEnd = bufBegin,
bufFlush = bufBegin + BUF_SIZE;
auto print = [&]() { ofs << string_view( bufBegin, bufEnd ); };
auto printPrime = [&]( size_t prime, auto )
{
auto [ptr, ec] = to_chars( &*bufEnd, &bufEnd[AHEAD - 1], prime );
if( (bool)ec ) [[unlikely]]
throw system_error( (int)ec, generic_category(), "converson failed" );
bufEnd = ptr - &*bufBegin + bufBegin; // pointer to iterator - NOP
*bufEnd++ = '\n';
if( bufEnd >= bufFlush ) [[unlikely]]
print(), bufEnd = bufBegin;
};
printPrime( 2, false_type() );
scan( 3, end, printPrime );
print();
}
catch( exception const &exc )
{
cout << exc.what() << endl;
}
}

array<unsigned, 4> cpuId( unsigned code )
{ array<unsigned, 4> regs;
#if defined(_MSC_VER)
__cpuid( (int *)&regs[0], code );
#elif defined(__GNUC__) || defined(__clang__)
__cpuid(code, regs[0], regs[1], regs[2], regs[3]);
#endif
return regs;
}

bool smt()
{ if( cpuId( 0 )[0] < 1 )
return false;
return cpuId( 1 )[3] >> 28 & 1;
}

size_t getL2Size()
{ if( cpuId( 0x80000000u )[0] < 0x80000006u )
return 512ull * 1024;
return (cpuId( 0x80000006u )[2] >> 16) * 1024;
}

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<86frxsz94r.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3155&group=comp.lang.c%2B%2B#3155

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!news.furie.org.uk!usenet.goja.nl.eu.org!weretis.net!feeder8.news.weretis.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)
Date: Fri, 16 Feb 2024 08:06:28 -0800
Organization: A noiseless patient Spider
Lines: 87
Message-ID: <86frxsz94r.fsf@linuxsc.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <umtm2j$2308v$1@raubtier-asyl.eternal-september.org> <umtnhl$234ro$1@dont-email.me> <umudmb$27da9$2@raubtier-asyl.eternal-september.org> <umvi6u$2c9ue$1@dont-email.me> <un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org> <un1l6g$2q1iv$1@dont-email.me> <un2sel$33tna$1@raubtier-asyl.eternal-september.org> <un4jos$3ba8u$1@dont-email.me> <un594t$3hn5o$1@raubtier-asyl.eternal-september.org> <unagvf$ft9g$1@dont-email.me> <unaus6$h9l0$1@raubtier-asyl.eternal-september.org> <20240106000249.177@kylheku.com> <unb6jc$i4of$1@raubtier-asyl.eternal-september.org> <uncfue$ojf6$1@dont-email.me> <undpp4$117ni$1@raubtier-asyl.eternal-september.org> <unf2ip$16tqc$1@dont-email.me> <ung2bt$1eihc$1@raubtier-asyl.eternal-september.org> <20240108175039.572@kylheku.com> <unjk7k$21eto$1@raubtier-asyl.eternal-september.org> <up95f1$kibc$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="acda77ef139adc7a575507d0f435d89d";
logging-data="4126570"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195KD7A70ZLCRT8hieyt1KwdEkeVz6oQrU="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:hurIGa7nVGBwQfMR4ciEHeXBlAs=
sha1:LthGPqVUWc/w8+/XGVtb4BRCbJs=
 by: Tim Rentsch - Fri, 16 Feb 2024 16:06 UTC

Vir Campestris <vir.campestris@invalid.invalid> writes:

> I retired last year, and I haven't really written any code since. This
> has turned out to be quite a fun little thing of a type I haven't had
> time for for YEARS. And oddly I still don't seem to have enough time
> for it... It's the garden, and the kid's gardens, and my mum's garden,
> and all those holidays :)
>
> But some optimisations. You'll remember in Bonita's first version the
> bitmap was initialised to 0xaaaa, because it's a waste of time doing
> the sieve for 2.
>
> I pointed out that we don't need to even store the even numbers.
>
> But there's more.
>
> If you look at the bitmap when you've sieved for 2 you see
>
> 12 34 56 78
> 11 10 10 10...
> which is a repeat of 2 after an initialisation word. That's the aaaa.
>
> You can do the same with 3
>
> 123 456 789
> 111 110 110 110
>
> except this time the repeat is 3. And annoyingly that doesn't map well
> down onto a byte-based architecture. You end up with an initial word,
> then a 3-word repeat. (If your word was 24 or 36 bytes it would only
> be 1 word, but I haven't seen that since the 1970s)
>
> In hex, with lowest byte first, that is
> fd b6 6d db b6 6d db
>
> (That BTW is the same if you only store the odd numbers - a 3-word repeat.)
>
> So rather than start off with your bitmap all set to 1s you can set it
> to this repeating pattern. That replaces all the ANDs for all the
> values of three with a memory fill with far fewer accesses.
>
> You can do the same with 5:
>
> 12345 6789a bcdef
> 11111 11110 11110 11110
>
> You can then AND your pattern for 3 with the one for 5, and get one
> with a repeat length of 15, and set that into your bitmap. You've now
> replaced about a fifth of all your AND operations with a flood fill.
>
> This can carry on - for a while. Only a short while. You _can_ make a
> sequence for lots of primes. But it gets quite long, quite
> quickly. For up to 23, and not storing the evens, it's over 1E8 words
> long!
>
> I was implementing a version of that when something else occurred to
> me. You can sacrifice speed for store size if you're prepared to do an
> integer divide for every prime lookup.

I explained before how numbers can be considered mod 30, of which
only the residues { 1, 7, 11, 13, 17, 19, 23, 29 } are candidates,
because all other residues are divisible by 2, 3, or 5. And very
conveniently, there are exactly 8 of these residues, so one byte
can be used to represent each block of 30 numbers (only 8 of which
might be prime). That cuts down on the space needed.

I also explained how the divides and remainders can be avoided,
by taking advantage of the structure of how the numbers being
considered are represented, and arranging that the difficult parts
be done at compile time.

I have an implementation (written in C) based on this approach that
determines all primes less than roughly 51.75 billion, taking just
under 56 seconds to complete. (No threading is used - code is all
single threaded.)

> [...]
>
> But a note for the group of course - optimising this to the max has
> nothing to do whatever with C++. The only C++ optimising I've found
> myself doing is using raw pointers, not vector's
> operator[]. (certainly not the at function). And also I found myself
> using emplace_back a lot. It's a PITA because you can only emplace
> back a single item, and it is slow.

My program is written in C and uses ordinary C arrays. I expect it
could be converted to C++ without too much difficulty.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3156&group=comp.lang.c%2B%2B#3156

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Fri, 16 Feb 2024 18:30:58 +0100
Organization: A noiseless patient Spider
Lines: 18
Message-ID: <uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umtm2j$2308v$1@raubtier-asyl.eternal-september.org>
<umtnhl$234ro$1@dont-email.me>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 16 Feb 2024 17:30:58 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="0bbe64c2c8ccd886cc1a78e450030725";
logging-data="4158067"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18loZOwHnAOq8l8uonJ+fxcbO/vk6WFoOw="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:JEu80Jrv/5PiO+e9W1ti/v9Eu+s=
Content-Language: de-DE
In-Reply-To: <86frxsz94r.fsf@linuxsc.com>
 by: Bonita Montero - Fri, 16 Feb 2024 17:30 UTC

Am 16.02.2024 um 17:06 schrieb Tim Rentsch:

> I have an implementation (written in C) based on this approach that
> determines all primes less than roughly 51.75 billion, taking just
> under 56 seconds to complete. (No threading is used - code is all
> single threaded.)

On my 16 core PC this takes 1.73 seconds and 43 seconds
overall CPU time without printing the numbers to a file.

C:\Users\Boni\Documents\Source\bitmapSieve>timep
"x64\Release-clang++\bitmapSieve.exe" 51750000000 ""
real 1.729s
user 43.094s
sys 0.094s
cylces 194.738.953.589

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<86il2fwapd.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3163&group=comp.lang.c%2B%2B#3163

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)
Date: Fri, 23 Feb 2024 05:51:10 -0800
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <86il2fwapd.fsf@linuxsc.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <umudmb$27da9$2@raubtier-asyl.eternal-september.org> <umvi6u$2c9ue$1@dont-email.me> <un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org> <un1l6g$2q1iv$1@dont-email.me> <un2sel$33tna$1@raubtier-asyl.eternal-september.org> <un4jos$3ba8u$1@dont-email.me> <un594t$3hn5o$1@raubtier-asyl.eternal-september.org> <unagvf$ft9g$1@dont-email.me> <unaus6$h9l0$1@raubtier-asyl.eternal-september.org> <20240106000249.177@kylheku.com> <unb6jc$i4of$1@raubtier-asyl.eternal-september.org> <uncfue$ojf6$1@dont-email.me> <undpp4$117ni$1@raubtier-asyl.eternal-september.org> <unf2ip$16tqc$1@dont-email.me> <ung2bt$1eihc$1@raubtier-asyl.eternal-september.org> <20240108175039.572@kylheku.com> <unjk7k$21eto$1@raubtier-asyl.eternal-september.org> <up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com> <uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="e6a7fad1a1f29d7a51dca3c2f76e6aaf";
logging-data="607287"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19BA9Xdz/8KoVcxK3y85ALPIl0OKPmWkHY="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:ioDX7uAgTChJYuaerRbQ9RXOI5I=
sha1:pyjO7uZjL/rJ584DTS3/fZ8S8OI=
 by: Tim Rentsch - Fri, 23 Feb 2024 13:51 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 16.02.2024 um 17:06 schrieb Tim Rentsch:
>
>> I have an implementation (written in C) based on this approach that
>> determines all primes less than roughly 51.75 billion, taking just
>> under 56 seconds to complete. (No threading is used - code is all
>> single threaded.)
>
> On my 16 core PC this takes 1.73 seconds and 43 seconds
> overall CPU time without printing the numbers to a file.
>
> C:\Users\Boni\Documents\Source\bitmapSieve>timep
> "x64\Release-clang++\bitmapSieve.exe" 51750000000 ""
> real 1.729s
> user 43.094s
> sys 0.094s
> cylces 194.738.953.589

If you run the program as a single thread, what is the
elapsed time?

Also how long does the program take to determine all
primes up to 3 trillion? Here again I am interested
in the single-thread version.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<urcds6$14fvi$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3164&group=comp.lang.c%2B%2B#3164

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Sat, 24 Feb 2024 10:45:46 +0100
Organization: A noiseless patient Spider
Lines: 41
Message-ID: <urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<umudmb$27da9$2@raubtier-asyl.eternal-september.org>
<umvi6u$2c9ue$1@dont-email.me>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
<86il2fwapd.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 24 Feb 2024 09:45:42 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d8a4effec8bd4f3fb72ca903e5b4b343";
logging-data="1196018"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18YeTB6BZ+r6rlID7MU6CMbpif+AbtH8uk="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:DLjAd8Y2WMsGLRjC/ZLG7kzw8qM=
Content-Language: de-DE
In-Reply-To: <86il2fwapd.fsf@linuxsc.com>
 by: Bonita Montero - Sat, 24 Feb 2024 09:45 UTC

Am 23.02.2024 um 14:51 schrieb Tim Rentsch:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 16.02.2024 um 17:06 schrieb Tim Rentsch:
>>
>>> I have an implementation (written in C) based on this approach that
>>> determines all primes less than roughly 51.75 billion, taking just
>>> under 56 seconds to complete. (No threading is used - code is all
>>> single threaded.)
>>
>> On my 16 core PC this takes 1.73 seconds and 43 seconds
>> overall CPU time without printing the numbers to a file.
>>
>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>> "x64\Release-clang++\bitmapSieve.exe" 51750000000 ""
>> real 1.729s
>> user 43.094s
>> sys 0.094s
>> cylces 194.738.953.589
>
> If you run the program as a single thread, what is the
> elapsed time?

C:\Users\Boni\Documents\Source\bitmapSieve>timep
"x64\Release-clang++\bitmapSieve.exe" 51750000000 "" 1
real 22.945s
user 22.672s
sys 0.234s
cylces 102.917.207.295

> Also how long does the program take to determine all
> primes up to 3 trillion? Here again I am interested
> in the single-thread version.

C:\Users\Boni\Documents\Source\bitmapSieve>timep
"x64\Release-clang++\bitmapSieve.exe" 3000000000 "" 1
real 1.234s
user 1.203s
sys 0.031s
cylces 5.523.677.002

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<86wmqtszd0.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3165&group=comp.lang.c%2B%2B#3165

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)
Date: Sun, 25 Feb 2024 00:48:59 -0800
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <86wmqtszd0.fsf@linuxsc.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org> <un1l6g$2q1iv$1@dont-email.me> <un2sel$33tna$1@raubtier-asyl.eternal-september.org> <un4jos$3ba8u$1@dont-email.me> <un594t$3hn5o$1@raubtier-asyl.eternal-september.org> <unagvf$ft9g$1@dont-email.me> <unaus6$h9l0$1@raubtier-asyl.eternal-september.org> <20240106000249.177@kylheku.com> <unb6jc$i4of$1@raubtier-asyl.eternal-september.org> <uncfue$ojf6$1@dont-email.me> <undpp4$117ni$1@raubtier-asyl.eternal-september.org> <unf2ip$16tqc$1@dont-email.me> <ung2bt$1eihc$1@raubtier-asyl.eternal-september.org> <20240108175039.572@kylheku.com> <unjk7k$21eto$1@raubtier-asyl.eternal-september.org> <up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com> <uqo64i$3usjj$1@raubtier-asyl.eternal-september.org> <86il2fwapd.fsf@linuxsc.com> <urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="d0a541e28d41d50395e069f34372e044";
logging-data="1854706"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+zVA+06vkMkCGyp0UTe6U0RTP2gD36a14="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:JF43wPwblnsZSCe4MtRfq7yU900=
sha1:IZtl1l8gNwM0aNP6I5rL51Q1t2o=
 by: Tim Rentsch - Sun, 25 Feb 2024 08:48 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 23.02.2024 um 14:51 schrieb Tim Rentsch:
>
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 16.02.2024 um 17:06 schrieb Tim Rentsch:
>>>
>>>> I have an implementation (written in C) based on this approach that
>>>> determines all primes less than roughly 51.75 billion, taking just
>>>> under 56 seconds to complete. (No threading is used - code is all
>>>> single threaded.)
>>>
>>> On my 16 core PC this takes 1.73 seconds and 43 seconds
>>> overall CPU time without printing the numbers to a file.
>>>
>>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>>> "x64\Release-clang++\bitmapSieve.exe" 51750000000 ""
>>> real 1.729s
>>> user 43.094s
>>> sys 0.094s
>>> cylces 194.738.953.589
>>
>> If you run the program as a single thread, what is the
>> elapsed time?
>
> C:\Users\Boni\Documents\Source\bitmapSieve>timep
> "x64\Release-clang++\bitmapSieve.exe" 51750000000 "" 1
> real 22.945s
> user 22.672s
> sys 0.234s
> cylces 102.917.207.295

Hmmm. Interesting that the multi-threaded version uses almost
most twice as much CPU as the single-threaded version. I might
have guessed more, but not twice as much.

>> Also how long does the program take to determine all
>> primes up to 3 trillion? Here again I am interested
>> in the single-thread version.
>
> C:\Users\Boni\Documents\Source\bitmapSieve>timep
> "x64\Release-clang++\bitmapSieve.exe" 3000000000 "" 1
> real 1.234s
> user 1.203s
> sys 0.031s
> cylces 5.523.677.002

What I asked for was 3 trillion with a T, not 3 billion with
a B. Not 3000000000 but 3000000000000.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3166&group=comp.lang.c%2B%2B#3166

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Sun, 25 Feb 2024 15:51:11 +0100
Organization: A noiseless patient Spider
Lines: 75
Message-ID: <urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<un0q3n$2ks6a$1@raubtier-asyl.eternal-september.org>
<un1l6g$2q1iv$1@dont-email.me>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
<86il2fwapd.fsf@linuxsc.com>
<urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
<86wmqtszd0.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 25 Feb 2024 14:51:10 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="d9543f2c139e5cadf1e86847a2f9e01c";
logging-data="2009954"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19iSF+1U2B5Iatn8Lo3YHfnzIo5a6Ug8ow="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:9MpVrEnwRcQgludtDgEw8Q5jUIU=
Content-Language: de-DE
In-Reply-To: <86wmqtszd0.fsf@linuxsc.com>
 by: Bonita Montero - Sun, 25 Feb 2024 14:51 UTC

Am 25.02.2024 um 09:48 schrieb Tim Rentsch:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>
>> Am 23.02.2024 um 14:51 schrieb Tim Rentsch:
>>
>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>
>>>> Am 16.02.2024 um 17:06 schrieb Tim Rentsch:
>>>>
>>>>> I have an implementation (written in C) based on this approach that
>>>>> determines all primes less than roughly 51.75 billion, taking just
>>>>> under 56 seconds to complete. (No threading is used - code is all
>>>>> single threaded.)
>>>>
>>>> On my 16 core PC this takes 1.73 seconds and 43 seconds
>>>> overall CPU time without printing the numbers to a file.
>>>>
>>>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>>>> "x64\Release-clang++\bitmapSieve.exe" 51750000000 ""
>>>> real 1.729s
>>>> user 43.094s
>>>> sys 0.094s
>>>> cylces 194.738.953.589
>>>
>>> If you run the program as a single thread, what is the
>>> elapsed time?
>>
>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>> "x64\Release-clang++\bitmapSieve.exe" 51750000000 "" 1
>> real 22.945s
>> user 22.672s
>> sys 0.234s
>> cylces 102.917.207.295
>
> Hmmm. Interesting that the multi-threaded version uses almost
> most twice as much CPU as the single-threaded version. I might
> have guessed more, but not twice as much.

It's because the threads are competing on the L2-cache.
Look at the difference betwen 16 cores without SMT and
16 cores with SMT:

C:\Users\Boni\Documents\Source\bitmapSieve>timep
"x64\Release-clang++\bitmapSieve.exe" 51750000000 "" 16
real 1.916s
user 24.063s
sys 0.109s
cylces 110.113.013.925

C:\Users\Boni\Documents\Source\bitmapSieve>timep
"x64\Release-clang++\bitmapSieve.exe" 51750000000 "" 32
real 1.796s
user 44.703s
sys 0.063s
cylces 203.299.498.170

>
>>> Also how long does the program take to determine all
>>> primes up to 3 trillion? Here again I am interested
>>> in the single-thread version.
>>
>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>> "x64\Release-clang++\bitmapSieve.exe" 3000000000 "" 1
>> real 1.234s
>> user 1.203s
>> sys 0.031s
>> cylces 5.523.677.002
>
> What I asked for was 3 trillion with a T, not 3 billion with
> a B. Not 3000000000 but 3000000000000.

That would in a bitmap of 375GiB, which won't fit into my memory.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<86r0ggr8xb.fsf@linuxsc.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3338&group=comp.lang.c%2B%2B#3338

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: tr.17...@z991.linuxsc.com (Tim Rentsch)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)
Date: Mon, 11 Mar 2024 10:10:40 -0700
Organization: A noiseless patient Spider
Lines: 45
Message-ID: <86r0ggr8xb.fsf@linuxsc.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org> <un2sel$33tna$1@raubtier-asyl.eternal-september.org> <un4jos$3ba8u$1@dont-email.me> <un594t$3hn5o$1@raubtier-asyl.eternal-september.org> <unagvf$ft9g$1@dont-email.me> <unaus6$h9l0$1@raubtier-asyl.eternal-september.org> <20240106000249.177@kylheku.com> <unb6jc$i4of$1@raubtier-asyl.eternal-september.org> <uncfue$ojf6$1@dont-email.me> <undpp4$117ni$1@raubtier-asyl.eternal-september.org> <unf2ip$16tqc$1@dont-email.me> <ung2bt$1eihc$1@raubtier-asyl.eternal-september.org> <20240108175039.572@kylheku.com> <unjk7k$21eto$1@raubtier-asyl.eternal-september.org> <up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com> <uqo64i$3usjj$1@raubtier-asyl.eternal-september.org> <86il2fwapd.fsf@linuxsc.com> <urcds6$14fvi$1@raubtier-asyl.eternal-september.org> <86wmqtszd0.fsf@linuxsc.com> <urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Injection-Info: dont-email.me; posting-host="9d23253f7ade536449cb5f50b3111ee8";
logging-data="3925578"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dbpiO2h4i111huVnbiZXWl3GOW4FYKTo="
User-Agent: Gnus/5.11 (Gnus v5.11) Emacs/22.4 (gnu/linux)
Cancel-Lock: sha1:Csw10RQqjSa0E8LWKWhLfYCiAEY=
sha1:DOODmWQQo+6HRTyi05uWcHMxUXM=
 by: Tim Rentsch - Mon, 11 Mar 2024 17:10 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:

> Am 25.02.2024 um 09:48 schrieb Tim Rentsch:
>
>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>
>>> Am 23.02.2024 um 14:51 schrieb Tim Rentsch:
>>>
>>>> Bonita Montero <Bonita.Montero@gmail.com> writes:
>>>>
>>>>> Am 16.02.2024 um 17:06 schrieb Tim Rentsch:

[...]

>>>> Also how long does the program take to determine all
>>>> primes up to 3 trillion? Here again I am interested
>>>> in the single-thread version.
>>>
>>> C:\Users\Boni\Documents\Source\bitmapSieve>timep
>>> "x64\Release-clang++\bitmapSieve.exe" 3000000000 "" 1
>>> real 1.234s
>>> user 1.203s
>>> sys 0.031s
>>> cylces 5.523.677.002
>>
>> What I asked for was 3 trillion with a T, not 3 billion with
>> a B. Not 3000000000 but 3000000000000.
>
> That would in a bitmap of 375GiB, which won't fit into my memory.

Sounds like you're using 1 bit per number, most of which are
wasted. If you use a different encoding the memory requirements
can be much smaller. How much memory do you have on the box?
If you have 64G you should be able to determine all primes
less than 1.5 trillion, using a simple encoding.

I've mentioned this encoding before but let me give it again.
If numbers are considered mod 30, there are only 8 residues
that are not divisible by 2, 3, or 5. The 8 residues are
1, 7, 11, 13, 17, 19, 23, and 29. So a single byte can
hold all the information needed for 30 numbers, which means

1500000000000 / 30 = 50000000000

which is to say 50 gigabytes should suffice.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<usp6fv$72id$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3343&group=comp.lang.c%2B%2B#3343

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Tue, 12 Mar 2024 10:15:43 +0100
Organization: A noiseless patient Spider
Lines: 23
Message-ID: <usp6fv$72id$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
<86il2fwapd.fsf@linuxsc.com>
<urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
<86wmqtszd0.fsf@linuxsc.com>
<urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>
<86r0ggr8xb.fsf@linuxsc.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 12 Mar 2024 09:15:43 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="6eb6fbb670213a1fa7926230b9364012";
logging-data="232013"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/a+ODjWcSwXw/whzsgdFXIH0tB5hOuHTQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vlpOKHt8WT+LM9fx2jdENqHXSZ8=
In-Reply-To: <86r0ggr8xb.fsf@linuxsc.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 12 Mar 2024 09:15 UTC

Am 11.03.2024 um 18:10 schrieb Tim Rentsch:

> Sounds like you're using 1 bit per number, most of which are
> wasted. If you use a different encoding the memory requirements
> can be much smaller. How much memory do you have on the box?
> If you have 64G you should be able to determine all primes
> less than 1.5 trillion, using a simple encoding.

I'm omitting even numbers and I handle the number two as a
special case; that's the fastest solution.

> I've mentioned this encoding before but let me give it again.
> If numbers are considered mod 30, there are only 8 residues
> that are not divisible by 2, 3, or 5. The 8 residues are
> 1, 7, 11, 13, 17, 19, 23, and 29. So a single byte can
> hold all the information needed for 30 numbers, which means
>
> 1500000000000 / 30 = 50000000000
>
> which is to say 50 gigabytes should suffice.

Show me the code.

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<b0fef8ad619485b9ce7a821826e84c8de58f15bf.camel@gmail.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3347&group=comp.lang.c%2B%2B#3347

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: wynii...@gmail.com (wij)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Thu, 14 Mar 2024 12:44:01 +0800
Organization: A noiseless patient Spider
Lines: 134
Message-ID: <b0fef8ad619485b9ce7a821826e84c8de58f15bf.camel@gmail.com>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<un2sel$33tna$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
<86il2fwapd.fsf@linuxsc.com>
<urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
<86wmqtszd0.fsf@linuxsc.com>
<urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>
<86r0ggr8xb.fsf@linuxsc.com>
<usp6fv$72id$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Injection-Info: dont-email.me; posting-host="8f1e41ccdbe11d20b755fcc99a005d7d";
logging-data="1504192"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+lPhh9yuHpd5yrvbg7Zws0"
User-Agent: Evolution 3.50.2 (3.50.2-1.fc39)
Cancel-Lock: sha1:tcVoaoFIb57Vi7jP76bli6XiGzU=
In-Reply-To: <usp6fv$72id$1@raubtier-asyl.eternal-september.org>
 by: wij - Thu, 14 Mar 2024 04:44 UTC

On Tue, 2024-03-12 at 10:15 +0100, Bonita Montero wrote:
> Am 11.03.2024 um 18:10 schrieb Tim Rentsch:
>
> > Sounds like you're using 1 bit per number, most of which are
> > wasted.  If you use a different encoding the memory requirements
> > can be much smaller.  How much memory do you have on the box?
> > If you have 64G you should be able to determine all primes
> > less than 1.5 trillion, using a simple encoding.
>
> I'm omitting even numbers and I handle the number two as a
> special case; that's the fastest solution.
>
> > I've mentioned this encoding before but let me give it again.
> > If numbers are considered mod 30, there are only 8 residues
> > that are not divisible by 2, 3, or 5.  The 8 residues are
> > 1, 7, 11, 13, 17, 19, 23, and 29.  So a single byte can
> > hold all the information needed for 30 numbers, which means
> >
> >     1500000000000 / 30 = 50000000000
> >
> > which is to say 50 gigabytes should suffice.
>
> Show me the code.
>

Every 30 natural numbers (or more) can be coded in one byte(8 bits):

//----------------------------------------
#include <Wy.stdlib.h>
#include <CSCall/VLInt.h>

// [Syn] PrimeTab is a table for prime numbers
//
class PrimeTab {
public:
typedef uint64_t NumType;

private:
WY_ENSURE(sizeof(NumType)<=sizeof(size_t));
Wy::VLInt m_ptab;
NumType m_maxn;

// [Syn] Get the bit position storing info. for n
// 0= pos for n (n is composite) is not available
//
static size_t bpos(NumType n) {
constexpr NumType Lcm=2*3*5;
const NumType grp= 8*(n/Lcm);
switch(n%30) {
case 1: return grp;
case 7: return grp+1;
case 11: return grp+2;
case 13: return grp+3;
case 17: return grp+4;
case 19: return grp+5;
case 23: return grp+6;
case 29: return grp+7;
default: return 0;
}
};

public:
WY_DECL_REPLY;
PrimeTab() : m_ptab(), m_maxn(0) {};
PrimeTab(const PrimeTab& s) : m_ptab(s.m_ptab), m_maxn(s.m_maxn) {};
PrimeTab(PrimeTab& s, Wy::ByMove_t) : m_ptab(s.m_ptab,Wy::ByMove),
m_maxn(s.m_maxn) {};
explicit PrimeTab(NumType maxn) : m_ptab(), m_maxn(maxn) {
for(NumType n=2; n<=m_maxn; ++n) {
size_t p= bpos(n);
if(p==0) {
continue; // composite number
}
if(m_ptab.bit(p)) {
continue; // composite number
}

for(NumType m=n+n; m<=m_maxn; m+=n) {
Wy::Errno r=m_ptab.set_bit(bpos(m),true);
if(r!=Wy::Ok) {
WY_THROW( Reply(r) );
}
}
};
};
NumType max_num() const { return m_maxn; };
bool is_prime(NumType n) const {
if(n>m_maxn) {
WY_THROW( Reply(EINVAL) );
}
if(n<=6) {
switch(n) {
case 1: // FALLTHROUGH
case 2: // FALLTHROUGH
case 3: // FALLTHROUGH
case 5: return true;
default: return false;
}
}
size_t p= bpos(n);
if(p==0) {
return false;
}
return !m_ptab.bit(p);
};
void swap(PrimeTab& ano) {
m_ptab.swap(ano.m_ptab);
Wy::swap(m_maxn, ano.m_maxn);
};
void reset() {
m_ptab.reset();
};

Wy::Errno reset(NumType maxn) try {
PrimeTab tmp(maxn);
this->swap(tmp);
return Wy::Ok;
}
catch(const Wy::Errno& e) {
WY_RETURN(e);
};
Wy::Errno reset(const PrimeTab& rhs) {
WY_RETURN(m_ptab.reset(rhs.m_ptab));
};
PrimeTab& operator=(const PrimeTab& rhs) {
Wy::Errno r=m_ptab.reset(rhs.m_ptab);
if(r!=Wy::Ok) {
WY_THROW( Reply(r) );
}
return *this;
};
};

Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

<usu57t$1f3a5$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3348&group=comp.lang.c%2B%2B#3348

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to
the max)
Date: Thu, 14 Mar 2024 07:25:04 +0100
Organization: A noiseless patient Spider
Lines: 138
Message-ID: <usu57t$1f3a5$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<un4jos$3ba8u$1@dont-email.me>
<un594t$3hn5o$1@raubtier-asyl.eternal-september.org>
<unagvf$ft9g$1@dont-email.me>
<unaus6$h9l0$1@raubtier-asyl.eternal-september.org>
<20240106000249.177@kylheku.com>
<unb6jc$i4of$1@raubtier-asyl.eternal-september.org>
<uncfue$ojf6$1@dont-email.me>
<undpp4$117ni$1@raubtier-asyl.eternal-september.org>
<unf2ip$16tqc$1@dont-email.me>
<ung2bt$1eihc$1@raubtier-asyl.eternal-september.org>
<20240108175039.572@kylheku.com>
<unjk7k$21eto$1@raubtier-asyl.eternal-september.org>
<up95f1$kibc$1@dont-email.me> <86frxsz94r.fsf@linuxsc.com>
<uqo64i$3usjj$1@raubtier-asyl.eternal-september.org>
<86il2fwapd.fsf@linuxsc.com>
<urcds6$14fvi$1@raubtier-asyl.eternal-september.org>
<86wmqtszd0.fsf@linuxsc.com>
<urfk4u$1tar2$1@raubtier-asyl.eternal-september.org>
<86r0ggr8xb.fsf@linuxsc.com>
<usp6fv$72id$1@raubtier-asyl.eternal-september.org>
<b0fef8ad619485b9ce7a821826e84c8de58f15bf.camel@gmail.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 14 Mar 2024 06:25:01 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="27f7576937a0afad48a0f10b40aebce7";
logging-data="1543493"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+jeUAGUDbs2kd2eNCZkX5BFKuIXPFmBY4="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:SihGfLQ+zyA8pDJ5tzvba1E1RRQ=
Content-Language: de-DE
In-Reply-To: <b0fef8ad619485b9ce7a821826e84c8de58f15bf.camel@gmail.com>
 by: Bonita Montero - Thu, 14 Mar 2024 06:25 UTC

Am 14.03.2024 um 05:44 schrieb wij:
> On Tue, 2024-03-12 at 10:15 +0100, Bonita Montero wrote:
>> Am 11.03.2024 um 18:10 schrieb Tim Rentsch:
>>
>>> Sounds like you're using 1 bit per number, most of which are
>>> wasted.  If you use a different encoding the memory requirements
>>> can be much smaller.  How much memory do you have on the box?
>>> If you have 64G you should be able to determine all primes
>>> less than 1.5 trillion, using a simple encoding.
>>
>> I'm omitting even numbers and I handle the number two as a
>> special case; that's the fastest solution.
>>
>>> I've mentioned this encoding before but let me give it again.
>>> If numbers are considered mod 30, there are only 8 residues
>>> that are not divisible by 2, 3, or 5.  The 8 residues are
>>> 1, 7, 11, 13, 17, 19, 23, and 29.  So a single byte can
>>> hold all the information needed for 30 numbers, which means
>>>
>>>     1500000000000 / 30 = 50000000000
>>>
>>> which is to say 50 gigabytes should suffice.
>>
>> Show me the code.
>>
>
> Every 30 natural numbers (or more) can be coded in one byte(8 bits):

Show me a working sieve with that that beats my code.

> //----------------------------------------
> #include <Wy.stdlib.h>
> #include <CSCall/VLInt.h>
>
> // [Syn] PrimeTab is a table for prime numbers
> //
> class PrimeTab {
> public:
> typedef uint64_t NumType;
>
> private:
> WY_ENSURE(sizeof(NumType)<=sizeof(size_t));
> Wy::VLInt m_ptab;
> NumType m_maxn;
>
> // [Syn] Get the bit position storing info. for n
> // 0= pos for n (n is composite) is not available
> //
> static size_t bpos(NumType n) {
> constexpr NumType Lcm=2*3*5;
> const NumType grp= 8*(n/Lcm);
> switch(n%30) {
> case 1: return grp;
> case 7: return grp+1;
> case 11: return grp+2;
> case 13: return grp+3;
> case 17: return grp+4;
> case 19: return grp+5;
> case 23: return grp+6;
> case 29: return grp+7;
> default: return 0;
> }
> };
>
> public:
> WY_DECL_REPLY;
> PrimeTab() : m_ptab(), m_maxn(0) {};
> PrimeTab(const PrimeTab& s) : m_ptab(s.m_ptab), m_maxn(s.m_maxn) {};
> PrimeTab(PrimeTab& s, Wy::ByMove_t) : m_ptab(s.m_ptab,Wy::ByMove),
> m_maxn(s.m_maxn) {};
> explicit PrimeTab(NumType maxn) : m_ptab(), m_maxn(maxn) {
> for(NumType n=2; n<=m_maxn; ++n) {
> size_t p= bpos(n);
> if(p==0) {
> continue; // composite number
> }
> if(m_ptab.bit(p)) {
> continue; // composite number
> }
>
> for(NumType m=n+n; m<=m_maxn; m+=n) {
> Wy::Errno r=m_ptab.set_bit(bpos(m),true);
> if(r!=Wy::Ok) {
> WY_THROW( Reply(r) );
> }
> }
> };
> };
> NumType max_num() const { return m_maxn; };
> bool is_prime(NumType n) const {
> if(n>m_maxn) {
> WY_THROW( Reply(EINVAL) );
> }
> if(n<=6) {
> switch(n) {
> case 1: // FALLTHROUGH
> case 2: // FALLTHROUGH
> case 3: // FALLTHROUGH
> case 5: return true;
> default: return false;
> }
> }
> size_t p= bpos(n);
> if(p==0) {
> return false;
> }
> return !m_ptab.bit(p);
> };
> void swap(PrimeTab& ano) {
> m_ptab.swap(ano.m_ptab);
> Wy::swap(m_maxn, ano.m_maxn);
> };
> void reset() {
> m_ptab.reset();
> };
>
> Wy::Errno reset(NumType maxn) try {
> PrimeTab tmp(maxn);
> this->swap(tmp);
> return Wy::Ok;
> }
> catch(const Wy::Errno& e) {
> WY_RETURN(e);
> };
> Wy::Errno reset(const PrimeTab& rhs) {
> WY_RETURN(m_ptab.reset(rhs.m_ptab));
> };
> PrimeTab& operator=(const PrimeTab& rhs) {
> Wy::Errno r=m_ptab.reset(rhs.m_ptab);
> if(r!=Wy::Ok) {
> WY_THROW( Reply(r) );
> }
> return *this;
> };
> };
>
>

Re: Sieve of Erastosthenes optimized to the max

<utlf3h$393l6$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3364&group=comp.lang.c%2B%2B#3364

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Fri, 22 Mar 2024 19:34:25 -0700
Organization: A noiseless patient Spider
Lines: 9
Message-ID: <utlf3h$393l6$1@dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<um2dsb$17vgg$2@dont-email.me>
<um2vpr$1e7pn$1@raubtier-asyl.eternal-september.org>
<um31o0$1edq3$1@dont-email.me>
<um4f1l$1l1c2$1@raubtier-asyl.eternal-september.org>
<um7haa$274oh$3@dont-email.me>
<um8vlp$2h8oc$1@raubtier-asyl.eternal-september.org>
<uma7i4$2nagg$1@dont-email.me>
<umdmkf$3clht$1@raubtier-asyl.eternal-september.org>
<umdovb$3cmi3$2@dont-email.me>
<ume6ap$3ecjk$1@raubtier-asyl.eternal-september.org>
<umfcqi$3jktj$2@dont-email.me>
<umgbci$3qpao$1@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Mar 2024 02:34:25 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="136108bc033d63220533a114254bf648";
logging-data="3444390"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y1lKqIOLNZfziWtrfC4YynECQkkFrOLY="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:PmLZ1wpWpD4ii2kO0fWn/i7kSsg=
In-Reply-To: <umgbci$3qpao$1@raubtier-asyl.eternal-september.org>
Content-Language: en-US
 by: Chris M. Thomasson - Sat, 23 Mar 2024 02:34 UTC

On 12/26/2023 9:06 PM, Bonita Montero wrote:
> Am 26.12.2023 um 21:24 schrieb Chris M. Thomasson:
>
>> So, are you familiar with Intel's early hyper threading problem?
>> There was false sharing between the ...
>
> False sharing can only happen between different cores.

Sigh.

Re: Sieve of Erastosthenes optimized to the max

<utn1fp$3oeks$2@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3366&group=comp.lang.c%2B%2B#3366

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Sat, 23 Mar 2024 17:54:20 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <utn1fp$3oeks$2@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<um2dsb$17vgg$2@dont-email.me>
<um2vpr$1e7pn$1@raubtier-asyl.eternal-september.org>
<um31o0$1edq3$1@dont-email.me>
<um4f1l$1l1c2$1@raubtier-asyl.eternal-september.org>
<um7haa$274oh$3@dont-email.me>
<um8vlp$2h8oc$1@raubtier-asyl.eternal-september.org>
<uma7i4$2nagg$1@dont-email.me>
<umdmkf$3clht$1@raubtier-asyl.eternal-september.org>
<umdovb$3cmi3$2@dont-email.me>
<ume6ap$3ecjk$1@raubtier-asyl.eternal-september.org>
<umfcqi$3jktj$2@dont-email.me>
<umgbci$3qpao$1@raubtier-asyl.eternal-september.org>
<utlf3h$393l6$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Mar 2024 16:54:17 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="2059e4cb17b0cfa4536c7b2f5d738773";
logging-data="3947164"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19xzRzNFzUgUC7Tpo3l9l2MnzkzpRfPg9s="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:hELtr7zgIsQh+V1XNBdWINB7iEU=
In-Reply-To: <utlf3h$393l6$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 23 Mar 2024 16:54 UTC

Am 23.03.2024 um 03:34 schrieb Chris M. Thomasson:
> On 12/26/2023 9:06 PM, Bonita Montero wrote:
>> Am 26.12.2023 um 21:24 schrieb Chris M. Thomasson:
>>
>>> So, are you familiar with Intel's early hyper threading problem?
>>> There was false sharing between the ...
>>
>> False sharing can only happen between different cores.
>
> Sigh.

Why ? Do you think false sharing can happen between the threads
of a single core ?

Re: Sieve of Erastosthenes optimized to the max

<utng4n$3rn1f$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3369&group=comp.lang.c%2B%2B#3369

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Sat, 23 Mar 2024 14:04:23 -0700
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <utng4n$3rn1f$2@dont-email.me>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<um2dsb$17vgg$2@dont-email.me>
<um2vpr$1e7pn$1@raubtier-asyl.eternal-september.org>
<um31o0$1edq3$1@dont-email.me>
<um4f1l$1l1c2$1@raubtier-asyl.eternal-september.org>
<um7haa$274oh$3@dont-email.me>
<um8vlp$2h8oc$1@raubtier-asyl.eternal-september.org>
<uma7i4$2nagg$1@dont-email.me>
<umdmkf$3clht$1@raubtier-asyl.eternal-september.org>
<umdovb$3cmi3$2@dont-email.me>
<ume6ap$3ecjk$1@raubtier-asyl.eternal-september.org>
<umfcqi$3jktj$2@dont-email.me>
<umgbci$3qpao$1@raubtier-asyl.eternal-september.org>
<utlf3h$393l6$1@dont-email.me>
<utn1fp$3oeks$2@raubtier-asyl.eternal-september.org>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 23 Mar 2024 21:04:23 -0000 (UTC)
Injection-Info: dont-email.me; posting-host="136108bc033d63220533a114254bf648";
logging-data="4054063"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+F7G2zx6O1Pw8PMcFIMo++pasc3Aijc1g="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:4B4NDdDmcyCGtB1rS0bYuBX1yPM=
Content-Language: en-US
In-Reply-To: <utn1fp$3oeks$2@raubtier-asyl.eternal-september.org>
 by: Chris M. Thomasson - Sat, 23 Mar 2024 21:04 UTC

On 3/23/2024 9:54 AM, Bonita Montero wrote:
> Am 23.03.2024 um 03:34 schrieb Chris M. Thomasson:
>> On 12/26/2023 9:06 PM, Bonita Montero wrote:
>>> Am 26.12.2023 um 21:24 schrieb Chris M. Thomasson:
>>>
>>>> So, are you familiar with Intel's early hyper threading problem?
>>>> There was false sharing between the ...
>>>
>>> False sharing can only happen between different cores.
>>
>> Sigh.
>
> Why ? Do you think false sharing can happen between the threads
> of a single core ?
>

Sigh again...

Re: Sieve of Erastosthenes optimized to the max

<utoh9d$6lrr$1@raubtier-asyl.eternal-september.org>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=3370&group=comp.lang.c%2B%2B#3370

  copy link   Newsgroups: comp.lang.c++
Path: i2pn2.org!i2pn.org!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c++
Subject: Re: Sieve of Erastosthenes optimized to the max
Date: Sun, 24 Mar 2024 07:30:07 +0100
Organization: A noiseless patient Spider
Lines: 21
Message-ID: <utoh9d$6lrr$1@raubtier-asyl.eternal-september.org>
References: <ul41d4$2koct$1@raubtier-asyl.eternal-september.org>
<um2dsb$17vgg$2@dont-email.me>
<um2vpr$1e7pn$1@raubtier-asyl.eternal-september.org>
<um31o0$1edq3$1@dont-email.me>
<um4f1l$1l1c2$1@raubtier-asyl.eternal-september.org>
<um7haa$274oh$3@dont-email.me>
<um8vlp$2h8oc$1@raubtier-asyl.eternal-september.org>
<uma7i4$2nagg$1@dont-email.me>
<umdmkf$3clht$1@raubtier-asyl.eternal-september.org>
<umdovb$3cmi3$2@dont-email.me>
<ume6ap$3ecjk$1@raubtier-asyl.eternal-september.org>
<umfcqi$3jktj$2@dont-email.me>
<umgbci$3qpao$1@raubtier-asyl.eternal-september.org>
<utlf3h$393l6$1@dont-email.me>
<utn1fp$3oeks$2@raubtier-asyl.eternal-september.org>
<utng4n$3rn1f$2@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sun, 24 Mar 2024 06:30:05 -0000 (UTC)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="661bbc650b0e553e73b14b7d466277cb";
logging-data="219003"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18yCD2SE+nskQuDa8V0RjFEAmm2QK2EbCQ="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:vl12Vj6/w4Iuq2QaeveNeRDyneg=
Content-Language: de-DE
In-Reply-To: <utng4n$3rn1f$2@dont-email.me>
 by: Bonita Montero - Sun, 24 Mar 2024 06:30 UTC

Am 23.03.2024 um 22:04 schrieb Chris M. Thomasson:
> On 3/23/2024 9:54 AM, Bonita Montero wrote:
>> Am 23.03.2024 um 03:34 schrieb Chris M. Thomasson:
>>> On 12/26/2023 9:06 PM, Bonita Montero wrote:
>>>> Am 26.12.2023 um 21:24 schrieb Chris M. Thomasson:
>>>>
>>>>> So, are you familiar with Intel's early hyper threading problem?
>>>>> There was false sharing between the ...
>>>>
>>>> False sharing can only happen between different cores.
>>>
>>> Sigh.
>>
>> Why ? Do you think false sharing can happen between the threads
>> of a single core ?
>>
>
> Sigh again...

On a single core CPU with two thread's there's never false sharing.


devel / comp.lang.c++ / Re: OT: A better sieve (was Re: Sieve of Erastosthenes optimized to the max)

Pages:123456
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor