From 1b404038017074ec4c896edaa732ef2ded034dae Mon Sep 17 00:00:00 2001 From: Matt Borland Date: Sun, 23 Aug 2020 18:50:07 -0500 Subject: [PATCH] Implemented interval sieve [CI SKIP] --- .../boost/math/special_functions/interval_sieve.hpp | 8 +++++--- .../boost/math/special_functions/prime_sieve.hpp | 13 +++++++------ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/include/boost/math/special_functions/interval_sieve.hpp b/include/boost/math/special_functions/interval_sieve.hpp index a65759462..305d3a433 100644 --- a/include/boost/math/special_functions/interval_sieve.hpp +++ b/include/boost/math/special_functions/interval_sieve.hpp @@ -15,18 +15,20 @@ #include #include #include +#include namespace boost::math::detail { +template +class IntervalSieve +{ + #ifdef __SIZEOF_INT128__ // Defined in GCC 4.6+, clang, intel. MSVC does not define. using int_128t = __int128; // One machine word smaller than the boost equivalent #else using int_128t = boost::multiprecision::int128_t; #endif -template -class IntervalSieve -{ private: // Table of pseudo-sqares (https://mathworld.wolfram.com/Pseudosquare.html) // This table is from page 421, table 16.3.1, Hugh Williams' book diff --git a/include/boost/math/special_functions/prime_sieve.hpp b/include/boost/math/special_functions/prime_sieve.hpp index c22fbacd5..ceb8934e5 100644 --- a/include/boost/math/special_functions/prime_sieve.hpp +++ b/include/boost/math/special_functions/prime_sieve.hpp @@ -9,6 +9,7 @@ #define BOOST_MATH_SPECIAL_FUNCTIONS_PRIME_SIEVE_HPP #include +#include #include #include #include @@ -138,8 +139,8 @@ constexpr void prime_table(Integer upper_bound, Container &resultant_primes) template void segmented_sieve(Integer lower_bound, Integer upper_bound, const PrimesContainer &primes, Container &resultant_primes) { - const Integer L1_SIZE {32648}; - const Integer interval {L1_SIZE * 4}; + const Integer L1_SIZE {32768}; + const Integer interval {L1_SIZE * 8}; Integer current_lower_bound{lower_bound}; Integer current_upper_bound{current_lower_bound + interval}; @@ -160,8 +161,8 @@ void segmented_sieve(Integer lower_bound, Integer upper_bound, const PrimesConta { prime_vectors[i].reserve(primes_in_range); - future_manager.emplace_back(std::async(std::launch::async, [current_lower_bound, current_upper_bound, &primes, &prime_vectors, i]{ - boost::math::detail::mask_sieve(current_lower_bound, current_upper_bound, primes, prime_vectors[i]); + future_manager.emplace_back(std::async(std::launch::async, [¤t_lower_bound, ¤t_upper_bound, &primes, &prime_vectors, i]{ + boost::math::detail::IntervalSieve sieve(current_lower_bound, current_upper_bound, primes, prime_vectors[i]); })); current_lower_bound = current_upper_bound + 1; @@ -169,8 +170,8 @@ void segmented_sieve(Integer lower_bound, Integer upper_bound, const PrimesConta } prime_vectors[ranges].reserve(primes_in_range); - future_manager.emplace_back(std::async(std::launch::async, [current_lower_bound, upper_bound, &primes, &prime_vectors]{ - boost::math::detail::mask_sieve(current_lower_bound, upper_bound, primes, prime_vectors.back()); + future_manager.emplace_back(std::async(std::launch::async, [¤t_lower_bound, &upper_bound, &primes, &prime_vectors]{ + boost::math::detail::IntervalSieve sieve(current_lower_bound, upper_bound, primes, prime_vectors.back()); })); for(auto &&future : future_manager)