-
-
Notifications
You must be signed in to change notification settings - Fork 503
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Trac #25009: update and promote spkg primecount
The `prime_pi` function is currently a symbolic function that can hold its argument as in {{{ sage: n = SR.var('n') sage: prime_pi(n) prime_pi(n) }}} that also contains the Cython code for evaluating it {{{ sage: prime_pi(13543) 1603 }}} Unfortunately, it is buggy, see #24960 (fixed in #32894, using this ticket). We will promote the spkg `primecount` to standard and use it instead. This ticket does this part, and reverts deprecations from #32412. It also removes obsolete deprecation warning, and the corresponding no longer available parameter. Upstream patch: kimwalisch/primesieve#107 (rejected) ------------- Below is the original part, no longer too relevant. ------------- We move the evaluation part as a standalone function in `arith/` and provide alternative implementations - using `PARI/GP` (only efficient in the range of tabulated primes) - using the different algorithms in the library primecount that is packaged in #24966 URL: https://trac.sagemath.org/25009 Reported by: vdelecroix Ticket author(s): Dima Pasechnik Reviewer(s): Matthias Koeppe
- Loading branch information
Showing
31 changed files
with
195 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
tarball=primecount-VERSION.tar.gz | ||
sha1=d7a2c660eb64d14c951feeaee1d94d220c68c23e | ||
md5=ab925094a104499cfc21db2532e65517 | ||
cksum=2340721037 | ||
sha1=845b863f2007dc90d83c199db0af8fc20fd5092e | ||
md5=b855038556de3f0ec8210b54e4057a65 | ||
cksum=2388953073 | ||
upstream_url=https://github.com/kimwalisch/primecount/archive/refs/tags/vVERSION.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
cmake | ||
primesieve | cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
primecount | ||
primecount-devel |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
5.1 | ||
7.1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
diff --git a/CMakeLists.txt b/CMakeLists.txt | ||
index d1fb69a..d9d6d43 100644 | ||
--- a/CMakeLists.txt | ||
+++ b/CMakeLists.txt | ||
@@ -267,7 +267,7 @@ if(BUILD_LIBPRIMESIEVE) | ||
set(BUILD_MANPAGE "${COPY_BUILD_MANPAGE}" CACHE BOOL "Regenerate man page using a2x" FORCE) | ||
set(BUILD_TESTS "${COPY_BUILD_TESTS}" CACHE BOOL "Build test programs" FORCE) | ||
else() | ||
- find_package(primesieve REQUIRED) | ||
+ find_package(primesieve 7.6 REQUIRED) | ||
endif() | ||
|
||
# Testing ############################################################ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,2 @@ | ||
############################################################################### | ||
# | ||
# primecount Sage check script | ||
# | ||
############################################################################### | ||
|
||
cd src | ||
$MAKE test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
SAGE_SPKG_CONFIGURE([primecount], [ | ||
m4_pushdef([SAGE_PRIMECOUNT_MINVER],[7.1]) | ||
m4_pushdef([SAGE_PRIMECOUNT_MAJOR],[7]) | ||
m4_pushdef([SAGE_PRIMECOUNT_MINOR],[1]) | ||
SAGE_SPKG_DEPCHECK([primesieve], [ | ||
dnl Checking for primecount with pkg-config | ||
PKG_CHECK_MODULES([PRIMECOUNT], [primecount >= SAGE_PRIMECOUNT_MINVER], [ ], [ | ||
AC_CHECK_HEADER([primecount.h], [ | ||
AC_SEARCH_LIBS([primecount_pi], [primecount], [ | ||
AC_MSG_CHECKING([checking primecount version directly]) | ||
AC_RUN_IFELSE([AC_LANG_PROGRAM([ | ||
[#include <primecount.h> | ||
]],[[ | ||
if (PRIMECOUNT_VERSION_MAJOR > ]] SAGE_PRIMECOUNT_MAJOR [[ ) return 0; | ||
if (PRIMECOUNT_VERSION_MAJOR == ]] SAGE_PRIMECOUNT_MAJOR [[ && | ||
PRIMECOUNT_VERSION_MINOR >= ]] SAGE_PRIMECOUNT_MINOR [[ ) return 0; | ||
else return 1; | ||
]])], | ||
[AC_MSG_RESULT([Good.])], | ||
[AC_MSG_RESULT([Too old.]) | ||
sage_spkg_install_primecount=yes], | ||
[]) dnl cross-compilation - noop | ||
], | ||
[sage_spkg_install_primecount=yes]) | ||
], [sage_spkg_install_primecount=yes]) | ||
]) | ||
]) | ||
m4_popdef([SAGE_PRIMECOUNT_MINVER]) | ||
m4_popdef([SAGE_PRIMECOUNT_MAJOR]) | ||
m4_popdef([SAGE_PRIMECOUNT_MINOR]) | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,23 @@ | ||
############################################################################### | ||
# | ||
# primecount Sage install script | ||
# | ||
############################################################################### | ||
|
||
cd src | ||
|
||
if [ "$SAGE_FAT_BINARY" = yes ]; then | ||
EXTRA_OPTS="-DWITH_POPCNT=OFF" | ||
fi | ||
|
||
echo "Configuring primecount." | ||
primc_config(){ | ||
echo "Configuring primecount: building primesieve $1" | ||
sdh_cmake -DCMAKE_VERBOSE_MAKEFILE=ON \ | ||
-DBUILD_STATIC_LIBS=OFF \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DBUILD_TESTS=ON \ | ||
${EXTRA_OPTS} | ||
-DBUILD_LIBPRIMESIEVE=$1 \ | ||
-DCMAKE_FIND_ROOT_PATH=$SAGE_LOCAL/lib/cmake \ | ||
-DCMAKE_FIND_ROOT_PATH_MODE_LIBRARY=BOTH \ | ||
-DCMAKE_INSTALL_PREFIX=$SAGE_LOCAL \ | ||
${EXTRA_OPTS} && sdh_make_install | ||
} | ||
|
||
sdh_make | ||
# we try to use the external primesieve first, and if | ||
# cmake cannot find it, we build a vendored copy | ||
|
||
sdh_make_install | ||
(primc_config OFF) || primc_config ON |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
optional | ||
standard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
primesieve: CLI program and C/C++ library for generating primes | ||
=============================================================== | ||
|
||
Description | ||
----------- | ||
|
||
A CLI program and C/C++ library for quickly generating prime numbers. | ||
https://github.com/kimwalisch/primesieve | ||
|
||
A dependency of the standard spkg primecount. | ||
|
||
License | ||
------- | ||
|
||
BSD-2-clause | ||
|
||
Upstream Contact | ||
---------------- | ||
|
||
- https://github.com/kimwalisch/primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
tarball=primesieve-VERSION.tar.gz | ||
sha1=b78579e0c78fedb75dc9a58b4be3b092eefbcfcb | ||
md5=65eb8972819e47f552f563dc7699be8a | ||
cksum=51195771 | ||
upstream_url=https://github.com/kimwalisch/primesieve/archive/refs/tags/vVERSION.tar.gz |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
| cmake |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
primesieve-dev | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
libprimesieve-dev |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
primesieve-devel | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
primesieve |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
7.6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
From 1f8d0470b4e9d50393032b86d21a7a2fcc512355 Mon Sep 17 00:00:00 2001 | ||
From: Matthias Koeppe <mkoeppe@math.ucdavis.edu> | ||
Date: Sat, 27 Nov 2021 10:50:09 -0800 | ||
Subject: [PATCH] src/MemoryPool.cpp: Work around missing std::align on GCC 4.x | ||
|
||
--- | ||
src/MemoryPool.cpp | 27 ++++++++++++++++++++++++++- | ||
1 file changed, 26 insertions(+), 1 deletion(-) | ||
|
||
diff --git a/src/MemoryPool.cpp b/src/MemoryPool.cpp | ||
index 7a4a4006..60f62101 100644 | ||
--- a/src/MemoryPool.cpp | ||
+++ b/src/MemoryPool.cpp | ||
@@ -26,6 +26,31 @@ | ||
|
||
using std::size_t; | ||
|
||
+#if defined(__GNUC__) && __GNUC__ == 4 | ||
+ | ||
+// gcc 4.9 does not implement std::align. | ||
+// Use the implementation from | ||
+// https://gcc.gnu.org/bugzilla/show_bug.cgi?id=57350#c11 | ||
+ | ||
+using std::uintptr_t; | ||
+ | ||
+static inline void *align(size_t alignment, size_t size, | ||
+ void *&ptr, size_t &space) | ||
+{ | ||
+ uintptr_t pn = reinterpret_cast<uintptr_t>(ptr); | ||
+ uintptr_t aligned = (pn + alignment - 1) & -alignment; | ||
+ size_t padding = aligned - pn; | ||
+ if (space < size + padding) return nullptr; | ||
+ space -= padding; | ||
+ return ptr = reinterpret_cast<void *>(aligned); | ||
+} | ||
+ | ||
+#else | ||
+ | ||
+using std::align; | ||
+ | ||
+#endif | ||
+ | ||
namespace primesieve { | ||
|
||
void MemoryPool::addBucket(SievingPrime*& sievingPrime) | ||
@@ -70,7 +95,7 @@ void MemoryPool::allocateBuckets() | ||
void* ptr = memory; | ||
|
||
// Align pointer address to sizeof(Bucket) | ||
- if (!std::align(sizeof(Bucket), sizeof(Bucket), ptr, bytes)) | ||
+ if (!align(sizeof(Bucket), sizeof(Bucket), ptr, bytes)) | ||
throw primesieve_error("MemoryPool: failed to align memory!"); | ||
|
||
initBuckets(ptr, bytes); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
cd src | ||
$MAKE test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
SAGE_SPKG_CONFIGURE([primesieve], [ | ||
m4_pushdef([SAGE_PRIMESIEVE_MINVER],[7.6]) | ||
dnl Checking for primesieve with pkg-config | ||
PKG_CHECK_MODULES([PRIMESIEVE], [primesieve >= SAGE_PRIMESIEVE_MINVER], [ ], [ | ||
sage_spkg_install_primesieve=yes]) | ||
m4_popdef([SAGE_PRIMESIEVE_MINVER]) | ||
]) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
cd src | ||
|
||
if [ "$SAGE_FAT_BINARY" = yes ]; then | ||
EXTRA_OPTS="-DWITH_POPCNT=OFF" | ||
fi | ||
|
||
echo "Configuring primesieve." | ||
sdh_cmake -DCMAKE_VERBOSE_MAKEFILE=ON \ | ||
-DBUILD_STATIC_LIBS=OFF \ | ||
-DBUILD_SHARED_LIBS=ON \ | ||
-DBUILD_TESTS=ON \ | ||
${EXTRA_OPTS} | ||
|
||
sdh_make_install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
standard |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters