{"id":13418666,"url":"https://github.com/kimwalisch/primesieve","last_synced_at":"2025-05-14T13:06:14.129Z","repository":{"id":10800392,"uuid":"13072329","full_name":"kimwalisch/primesieve","owner":"kimwalisch","description":"🚀 Fast prime number generator","archived":false,"fork":false,"pushed_at":"2025-05-09T12:50:17.000Z","size":19959,"stargazers_count":1009,"open_issues_count":3,"forks_count":123,"subscribers_count":47,"default_branch":"master","last_synced_at":"2025-05-09T14:00:30.626Z","etag":null,"topics":["arm-neon","arm-sve","avx512","benchmark","eratosthenes","math","number-theory","prime-numbers","primes","primesieve","sieve","sieve-of-eratosthenes","stress-testing"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"bsd-2-clause","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kimwalisch.png","metadata":{"files":{"readme":"README.md","changelog":"ChangeLog","contributing":null,"funding":".github/FUNDING.yml","license":"COPYING","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null},"funding":{"github":"kimwalisch","custom":"https://paypal.com/donate/?hosted_button_id=N3NHLPNYQFBRA"}},"created_at":"2013-09-24T17:58:41.000Z","updated_at":"2025-05-09T12:50:21.000Z","dependencies_parsed_at":"2023-01-13T16:09:50.419Z","dependency_job_id":"cf8a4d41-442b-4ff5-afe3-632fa819ecfd","html_url":"https://github.com/kimwalisch/primesieve","commit_stats":{"total_commits":4497,"total_committers":11,"mean_commits":408.8181818181818,"dds":"0.024016010673782562","last_synced_commit":"64df593ff2973c9a61b68b3ddda4919398846761"},"previous_names":[],"tags_count":53,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fprimesieve","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fprimesieve/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fprimesieve/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kimwalisch%2Fprimesieve/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kimwalisch","download_url":"https://codeload.github.com/kimwalisch/primesieve/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254149950,"owners_count":22022851,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arm-neon","arm-sve","avx512","benchmark","eratosthenes","math","number-theory","prime-numbers","primes","primesieve","sieve","sieve-of-eratosthenes","stress-testing"],"created_at":"2024-07-30T22:01:05.257Z","updated_at":"2025-05-14T13:06:14.112Z","avatar_url":"https://github.com/kimwalisch.png","language":"C++","funding_links":["https://github.com/sponsors/kimwalisch","https://paypal.com/donate/?hosted_button_id=N3NHLPNYQFBRA","https://github.com/sponsors/kimwalisch)!"],"categories":["TODO scan for Android support in followings","C++"],"sub_categories":[],"readme":"# primesieve\n\n[![Build status](https://github.com/kimwalisch/primesieve/actions/workflows/ci.yml/badge.svg)](https://github.com/kimwalisch/primesieve/actions/workflows/ci.yml) [![Build status](https://github.com/kimwalisch/primesieve/actions/workflows/benchmark.yml/badge.svg)](https://github.com/kimwalisch/primesieve/actions/workflows/benchmark.yml)\n[![Github Releases](https://img.shields.io/github/release/kimwalisch/primesieve.svg)](https://github.com/kimwalisch/primesieve/releases)\n[![C API Documentation](https://img.shields.io/badge/docs-C_API-blue)](doc/C_API.md)\n[![C++ API Documentation](https://img.shields.io/badge/docs-C++_API-blue)](doc/CPP_API.md)\n\nprimesieve is a command-line program and C/C++ library for quickly generating prime numbers.\nIt is very cache efficient, it detects your CPU's L1 \u0026 L2 cache sizes and allocates its main\ndata structures accordingly. It is also multi-threaded by default, it uses all available CPU\ncores whenever possible i.e. if sequential ordering is not required. primesieve\ncan generate primes and [prime k-tuplets](https://en.wikipedia.org/wiki/Prime_k-tuple)\nup to 2\u003csup\u003e64\u003c/sup\u003e.\n\nprimesieve generates primes using the segmented\n[sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) with\n[wheel factorization](https://en.wikipedia.org/wiki/Wheel_factorization).\nThis algorithm has a run time complexity of $O(n\\ \\log\\ \\log\\ n)$ operations and uses\n$O(\\sqrt{n})$ memory. Furthermore primesieve uses the\n[bucket sieve](http://sweet.ua.pt/tos/software/prime_sieve.html)\nalgorithm which improves the cache efficiency when generating primes \u003e 2\u003csup\u003e32\u003c/sup\u003e.\nprimesieve uses 8 bytes per sieving prime, in practice its memory usage is about\n$\\pi(\\sqrt{n})\\times 8$ bytes per thread.\n\n* [More algorithm details](doc/ALGORITHMS.md)\n\n## Installation\n\nThe primesieve command-line program can be installed using your operating system's\npackage manager. For doing development with libprimesieve you may need\nto install ```libprimesieve-dev``` or ```libprimesieve-devel```.\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eWindows:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003ewinget install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003emacOS:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003ebrew install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eArch Linux:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003esudo pacman -S primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eDebian/Ubuntu:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003esudo apt install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eFedora:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003esudo dnf install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eFreeBSD:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003epkg install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eopenSUSE:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ccode\u003esudo zypper install primesieve\u003c/code\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n\u003c/table\u003e\n\n## Usage examples\n\n```sh\n# Count the primes ≤ 1e10 using all CPU cores\nprimesieve 1e10\n\n# Print the primes ≤ 1000000\nprimesieve 1000000 --print\n\n# Store the primes ≤ 1000000 in a text file\nprimesieve 1000000 --print \u003e primes.txt\n\n# Print the twin primes ≤ 1000000\nprimesieve 1000000 --print=2\n\n# Count the prime triplets inside [1e10, 1e10+2^32]\nprimesieve 1e10 --dist=2^32 --count=3\n```\n\n## Stress testing\n\nprimesieve includes support for stress testing both the CPU and memory. This feature\nis useful for checking system stability under maximum load and verifying whether\nyour cooling solution (fans, heatsinks, thermal paste, etc.) is adequate. primesieve's\nstress test supports two modes: **CPU** (highest CPU load, uses little memory) and\n**RAM** (high memory usage, uses about 1.2 GiB per thread).\n\n```\n$ primesieve --stress-test --timeout 5m\nStarted CPU stress testing using 14 threads.\nThe expected memory usage is: 14 threads * 2.85 MiB = 39.90 MiB.\nThe stress test keeps on running until either a miscalculation occurs\n(due to a hardware issue) or the timeout of 5m expires.\nYou may cancel the stress test at any time using Ctrl+C.\n\n[Apr 12 19:09] Thread 14, 25.19 secs, PrimePi(1e13+98e11, 1e13+99e11) = 3265923128   OK\n[Apr 12 19:09] Thread  9, 32.48 secs, PrimePi(1e13+63e11, 1e13+64e11) = 3286757785   OK\n[Apr 12 19:09] Thread 14, 22.32 secs, PrimePi(1e13+ 0e11, 1e13+ 1e11) = 3340141707   OK\n[Apr 12 19:10] Thread  2, 17.10 secs, PrimePi(1e13+16e11, 1e13+17e11) = 3323791292   OK\n[Apr 12 19:10] Thread 14, 18.45 secs, PrimePi(1e13+ 3e11, 1e13+ 4e11) = 3336895789   OK\n[Apr 12 19:11] Thread 13, 16.96 secs, PrimePi(1e13+96e11, 1e13+97e11) = 3267004191   OK\n[Apr 12 19:11] Thread  2, 31.79 secs, PrimePi(1e13+20e11, 1e13+21e11) = 3320071119   OK\n[Apr 12 19:12] Thread 11, 29.96 secs, PrimePi(1e13+84e11, 1e13+85e11) = 3273743021   OK\n[Apr 12 19:13] Thread  4, 32.45 secs, PrimePi(1e13+37e11, 1e13+38e11) = 3305523133   OK\n\nAll tests passed successfully!\n```\n\n## Command-line options\n\n```\nUsage: primesieve [START] STOP [OPTION]...\nGenerate the primes and/or prime k-tuplets inside [START, STOP]\n(\u003c 2^64) using the segmented sieve of Eratosthenes.\n\nOptions:\n  -c, --count[=NUM+]         Count primes and/or prime k-tuplets, NUM \u003c= 6.\n                             Count primes: -c or --count (default option),\n                             count twin primes: -c2 or --count=2,\n                             count prime triplets: -c3 or --count=3, ...\n      --cpu-info             Print CPU information (cache sizes).\n  -d, --dist=DIST            Sieve the interval [START, START + DIST].\n  -n, --nth-prime            Find the nth prime.\n                             primesieve 100 -n: finds the 100th prime,\n                             primesieve 2 100 -n: finds the 2nd prime \u003e 100.\n  -p, --print[=NUM]          Print primes or prime k-tuplets, NUM \u003c= 6.\n                             Print primes: -p or --print,\n                             print twin primes: -p2 or --print=2,\n                             print prime triplets: -p3 or --print=3, ...\n  -q, --quiet                Quiet mode, prints less output.\n  -s, --size=SIZE            Set the sieve size in KiB, SIZE \u003c= 8192.\n                             By default primesieve uses a sieve size that\n                             matches your CPU's L1 cache size (per core) or is\n                             slightly smaller than your CPU's L2 cache size.\n  -S, --stress-test[=MODE]   Run a stress test. The MODE can be either\n                             CPU (default) or RAM. The default timeout is 24h.\n      --test                 Run various correctness tests (\u003c 1 minute).\n  -t, --threads=NUM          Set the number of threads, NUM \u003c= CPU cores.\n                             Default setting: use all available CPU cores.\n      --time                 Print the time elapsed in seconds.\n      --timeout=SEC          Set the stress test timeout in seconds. Supported\n                             units of time suffixes: s, m, h, d or y.\n                             30 minutes timeout: --timeout 30m\n```\n\n## Build instructions\n\nYou need to have installed a C++ compiler which supports C++11 (or later)\nand CMake ≥ 3.4.\n\n```sh\ncmake .\ncmake --build . --parallel\nsudo cmake --install .\nsudo ldconfig\n```\n\n* [Detailed build instructions](doc/BUILD.md)\n\n## C API\n\nInclude the ```\u003cprimesieve.h\u003e``` header to use libprimesieve's C API.\n\n```C\n#include \u003cprimesieve.h\u003e\n#include \u003cinttypes.h\u003e\n#include \u003cstdio.h\u003e\n\nint main()\n{\n  primesieve_iterator it;\n  primesieve_init(\u0026it);\n  uint64_t prime;\n\n  /* Iterate over the primes \u003c 10^6 */\n  while ((prime = primesieve_next_prime(\u0026it)) \u003c 1000000)\n    printf(\"%\" PRIu64 \"\\n\", prime);\n\n  primesieve_free_iterator(\u0026it);\n  return 0;\n}\n```\n\n* [C API documentation](doc/C_API.md)\n\n## C++ API\n\nInclude the ```\u003cprimesieve.hpp\u003e``` header to use libprimesieve's C++ API.\n\n```C++\n#include \u003cprimesieve.hpp\u003e\n#include \u003ciostream\u003e\n\nint main()\n{\n  primesieve::iterator it;\n  uint64_t prime = it.next_prime();\n\n  // Iterate over the primes \u003c 10^6\n  for (; prime \u003c 1000000; prime = it.next_prime())\n    std::cout \u003c\u003c prime \u003c\u003c std::endl;\n\n  return 0;\n}\n```\n\n* [C++ API documentation](doc/CPP_API.md)\n\n## Bindings for other languages\n\nprimesieve natively supports C and C++ and has bindings available for:\n\n\u003ctable\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eCommon Lisp:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/AaronChen0/cl-primesieve\"\u003ecl-primesieve\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eJava:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/buildingnicesoftware/primesieve-java\"\u003eprimesieve-java\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eJanet:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/bunder/janet-primesieve\"\u003ejanet-primesieve\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eJulia:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/jlapeyre/PrimeSieve.jl\"\u003ePrimeSieve.jl\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eLua:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/kennypm/lua-primesieve\"\u003elua-primesieve\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eNim:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/nandub/primesievec-nim\"\u003eprimesievec-nim\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eHaskell:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://hackage.haskell.org/package/primesieve\"\u003eprimesieve-haskell\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003ePascal:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/JulStrat/primesieve-pas\"\u003eprimesieve-pas\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e \n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003ePerl:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://gitlab.com/oesiman/primesieve\"\u003ePrimesieve\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003ePython:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/shlomif/primesieve-python\"\u003eprimesieve-python\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eRaku:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/CurtTilmes/raku-primesieve\"\u003eraku-primesieve\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eRuby:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/robertjlooby/primesieve-ruby\"\u003eprimesieve-ruby\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e\n    \u003ctr\u003e\n        \u003ctd\u003e\u003cb\u003eRust:\u003c/b\u003e\u003c/td\u003e\n        \u003ctd\u003e\u003ca href=\"https://github.com/pthariensflame/primesieve.rs\"\u003eprimesieve.rs\u003c/a\u003e\u003c/td\u003e\n    \u003c/tr\u003e   \n\u003c/table\u003e\n\nMany thanks to the developers of these bindings!\n\n## Sponsors\n\nThanks to all current and past [sponsors of primesieve](https://github.com/sponsors/kimwalisch)! Your donations help me purchase (or rent) the latest CPUs and ensure primesieve runs at maximum performance on them. Your donations also motivate me to continue maintaining primesieve.\n\n\u003ca href=\"https://github.com/AndrewVSutherland\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/11425002?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/wolframresearch\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/11549616?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/AlgoWin\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/44401099?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/sethtroisi\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/10172976?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/entersoftone\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/80900902?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n\u003ca href=\"https://github.com/utmcontent\"\u003e\u003cimg src=\"https://images.weserv.nl/?url=avatars.githubusercontent.com/u/4705133?h=60\u0026w=60\u0026fit=cover\u0026mask=circle\"\u003e\u003c/img\u003e\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimwalisch%2Fprimesieve","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkimwalisch%2Fprimesieve","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkimwalisch%2Fprimesieve/lists"}