'\" t .\" Title: primesieve .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 02/17/2024 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" .TH "PRIMESIEVE" "1" "02/17/2024" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * Define some portability stuff .\" ----------------------------------------------------------------- .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .\" http://bugs.debian.org/507673 .\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html .\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" ----------------------------------------------------------------- .\" * set default formatting .\" ----------------------------------------------------------------- .\" disable hyphenation .nh .\" disable justification (adjust text to left margin only) .ad l .\" ----------------------------------------------------------------- .\" * MAIN CONTENT STARTS HERE * .\" ----------------------------------------------------------------- .SH "NAME" primesieve \- generate prime numbers .SH "SYNOPSIS" .sp \fBprimesieve\fR [\fISTART\fR] \fISTOP\fR [\fIOPTION\fR]\&... .SH "DESCRIPTION" .sp Generate the prime numbers and/or prime k\-tuplets inside [\fISTART\fR, \fISTOP\fR] (< 2^64) using the segmented sieve of Eratosthenes\&. primesieve includes a number of extensions to the sieve of Eratosthenes which significantly improve performance: multiples of small primes are pre\-sieved, it uses wheel factorization to skip multiples with small prime factors and it uses the bucket sieve algorithm which improves cache efficiency when sieving > 2^32\&. primesieve is also multi\-threaded, it uses all available CPU cores by default for counting primes and for finding the nth prime\&. .sp The segmented sieve of Eratosthenes has a runtime complexity of O(n log log n) operations and it uses O(n^(1/2)) bits of memory\&. More specifically primesieve uses 8 bytes per sieving prime, hence its memory usage can be approximated by PrimePi(n^(1/2)) * 8 bytes (per thread)\&. .SH "OPTIONS" .PP \fB\-c\fR[\fINUM+\fR], \fB\-\-count\fR[=\fINUM+\fR] .RS 4 Count primes and/or prime k\-tuplets, 1 <= \fINUM\fR <= 6\&. Count primes: \fB\-c\fR or \fB\-\-count\fR, count twin primes: \fB\-c2\fR or \fB\-\-count=2\fR, count prime triplets: \fB\-c3\fR or \fB\-\-count=3\fR, \&... You can also count primes and prime k\-tuplets at the same time, e\&.g\&. \fB\-c123\fR counts primes, twin primes and prime triplets\&. .RE .PP \fB\-\-cpu\-info\fR .RS 4 Print CPU information: CPU name, frequency, number of cores, cache sizes, \&... .RE .PP \fB\-d, \-\-dist\fR=\fIDIST\fR .RS 4 Sieve the interval [\fISTART\fR, \fISTART\fR + \fIDIST\fR]\&. .RE .PP \fB\-h, \-\-help\fR .RS 4 Print this help menu\&. .RE .PP \fB\-n, \-\-nth\-prime\fR .RS 4 Find the nth prime, e\&.g\&. 100 \fB\-n\fR finds the 100th prime\&. If 2 numbers \fIN\fR \fISTART\fR are provided finds the nth prime > \fISTART\fR, e\&.g\&. 2 100 \fB\-n\fR finds the 2nd prime > 100\&. .RE .PP \fB\-\-no\-status\fR .RS 4 Turn off the progressing status\&. .RE .PP \fB\-p\fR[\fINUM\fR], \fB\-\-print\fR[=\fINUM\fR] .RS 4 Print primes or prime k\-tuplets, 1 <= \fINUM\fR <= 6\&. Print primes: \fB\-p\fR, print twin primes: \fB\-p2\fR, print prime triplets: \fB\-p3\fR, \&... .RE .PP \fB\-q, \-\-quiet\fR .RS 4 Quiet mode, prints less output\&. .RE .PP \fB\-R, \-\-RiemannR\fR .RS 4 Approximate PrimePi(x) using the Riemann R function: R(x)\&. .RE .PP \fB\-\-RiemannR\-inverse\fR .RS 4 Approximate the nth prime using the inverse Riemann R function: R^\-1(x)\&. .RE .PP \fB\-s, \-\-size\fR=\fISIZE\fR .RS 4 Set the size of the sieve array in KiB, 16 <= \fISIZE\fR <= 8192\&. By default primesieve uses a sieve size that matches your CPU\(cqs L1 cache size (per core) or is slightly smaller than your CPU\(cqs L2 cache size\&. This setting is crucial for performance, on exotic CPUs primesieve sometimes fails to determine the CPU\(cqs cache sizes which usually causes a big slowdown\&. In this case you can get a significant speedup by manually setting the sieve size to your CPU\(cqs L1 or L2 cache size (per core)\&. .RE .PP \fB\-S, \-\-stress\-test\fR[=\fIMODE\fR] .RS 4 Run a stress test\&. The \fIMODE\fR can be either CPU (default) or RAM\&. The CPU \fIMODE\fR uses little memory (< 5 MiB per thread) and puts the highest load on the CPU\&. The RAM \fIMODE\fR on the other hand uses much more memory than the CPU \fIMODE\fR (each thread uses about 1\&.16 GiB), but the CPU usually won\(cqt get as hot as in the CPU \fIMODE\fR\&. Stress testing keeps on running until either a miscalculation occurs (due to a hardware issue) or the timeout expires\&. The default timeout is 24 hours, the timeout can be changed using the \fB\-\-timeout=SECS\fR option\&. By default the stress test uses a number of threads that matches the number of CPU cores, the number of threads can be changed using the \fB\-\-threads=NUM\fR option\&. .RE .PP \fB\-\-test\fR .RS 4 Run various correctness tests (< 1 minute)\&. .RE .PP \fB\-t, \-\-threads\fR=\fINUM\fR .RS 4 Set the number of threads, 1 <= \fINUM\fR <= CPU cores\&. By default primesieve uses all available CPU cores for counting primes and for finding the nth prime\&. .RE .PP \fB\-\-time\fR .RS 4 Print the time elapsed in seconds\&. .RE .PP \fB\-\-timeout\fR=\fISECS\fR .RS 4 Set the stress test timeout in seconds\&. Units of time for seconds, minutes, hours, days and years are also supported with the suffix s, m, h, d or y\&. E\&.g\&. \fB\-\-timeout 10m\fR sets a timeout of 10 minutes\&. The default stress test timeout is 24 hours\&. .RE .PP \fB\-v, \-\-version\fR .RS 4 Print version and license information\&. .RE .SH "EXAMPLES" .PP \fBprimesieve 1000\fR .RS 4 Count the primes <= 1000\&. .RE .PP \fBprimesieve 1e6 \-\-print\fR .RS 4 Print the primes <= 10^6\&. .RE .PP \fBprimesieve 1e6 \-\-print > primes\&.txt\fR .RS 4 Store the primes <= 10^6 in a text file\&. .RE .PP \fBprimesieve 2^32 \-\-print=2\fR .RS 4 Print the twin primes <= 2^32\&. .RE .PP \fBprimesieve 1e16 \-\-dist=1e10 \-\-threads=1\fR .RS 4 Count the primes inside [10^16, 10^16 + 10^10] using a single thread\&. .RE .SH "HOMEPAGE" .sp https://github\&.com/kimwalisch/primesieve .SH "AUTHOR" .sp Kim Walisch