Finding prime numbers is always fun. This is the sieve of Eratosthenes in Rust. Being a sieve it is of course hugely memory intensive. Running time was never a priority since the amount of RAM would be the limiting factor. Finding all primes less than 125.000.000.000 yielded the following results on a VM with 20 EPYC cores and 160GB RAM:
Found 5100605440 primes.
Last primes in the series:
124999999981 * 124999999997 = 15624999997250000000057
It completed in a little over 20 minutes. The 20 cores were of course a bit of an overkill, since the program is strictly single-threaded, but it was the best VM size in Azure I could get with respect to RAM size without raising a quota request, and who has time for that?
- Rust development machine, preferrably 64-bit
- There's a VS Code dev container config in the repo
- A host to run the sieve on, a big one
- Do a quick
cargo build --release
on the dev machine - Run the
rusty_primes
executable (orrusty_primes.exe
if you're into that) - Wait for the results
- This will take a lot of time if you're aiming high
- Success (or maybe a panic)!
Make sure you aim for a target a bit smaller than your available system memory to allow for filtering. You can overshoot your actual physical memory by a bit, but that would hit the swap and you will have to wait a whole lot longer for your results (unless of course you're 1337 and always turn off swap in which case you will get a segfault on GNU/Linux and a BSOD on Windows).
All code licensed under GPL-3.0-only, license text in COPYING file in the repo root.
Please do.