'\" t .\" Title: primesieve .\" Author: [see the "AUTHOR" section] .\" Generator: DocBook XSL Stylesheets vsnapshot .\" Date: 09/05/2021 .\" Manual: \ \& .\" Source: \ \& .\" Language: English .\" .TH "PRIMESIEVE" "1" "09/05/2021" "\ \&" "\ \&" .\" ----------------------------------------------------------------- .\" * 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\-s, \-\-size\fR=\fISIZE\fR .RS 4 Set the size of the sieve array in KiB, 8 <= \fISIZE\fR <= 4096\&. 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\-\-test\fR .RS 4 Run various sieving tests\&. .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\-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 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