2
0
mirror of https://github.com/boostorg/math.git synced 2026-01-24 06:02:08 +00:00

Implemented interval sieve [CI SKIP]

This commit is contained in:
Matt Borland
2020-08-23 18:50:07 -05:00
parent 6759ede1b3
commit 1b40403801
2 changed files with 12 additions and 9 deletions

View File

@@ -15,18 +15,20 @@
#include <memory>
#include <array>
#include <cstdint>
#include <bitset>
namespace boost::math::detail
{
template<class Integer, class PrimeContainer, class Container>
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 Integer, class PrimeContainer, class Container>
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

View File

@@ -9,6 +9,7 @@
#define BOOST_MATH_SPECIAL_FUNCTIONS_PRIME_SIEVE_HPP
#include <boost/math/special_functions/prime.hpp>
#include <boost/math/special_functions/interval_sieve.hpp>
#include <boost/assert.hpp>
#include <vector>
#include <iterator>
@@ -138,8 +139,8 @@ constexpr void prime_table(Integer upper_bound, Container &resultant_primes)
template<class Integer, class PrimesContainer, class Container>
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, [&current_lower_bound, &current_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, [&current_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)