Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Removed the multithreading helper of is_small_prime_small_test. #161

Merged
merged 3 commits into from
May 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 8 additions & 17 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,18 +262,15 @@ mod tests {
reader.lines().map(|line| line.unwrap())
}

/// Convenience to count the number of prime numbers in a given range using
/// multiple threads.
///
/// * `lower` - First number of the range (inclusive).
/// * `upper` - Last number of the range (exclusive).
/// * `pieces` - Number of threads to use.
///
/// -> Number of primes numbers in the range.
fn primes(lower: i64, upper: i64, pieces: i64) -> usize {
#[cfg(target_pointer_width = "64")]
#[test]
fn is_prime_small_test() {
// Break the range into equal sub-ranges, and count the number of
// primes in each sub-range in a separate thread.
let (lower, upper, pieces) = (0, 3i64.pow(20), 3);
let search_space = upper - lower;
let search_space = search_space / pieces + if search_space % pieces == 0 { 0 } else { 1 };
(lower..upper)
let num_of_primes = (lower..upper)
.step_by(search_space as usize)
.map(|lower| {
let upper = std::cmp::min(lower + search_space, upper);
Expand All @@ -282,13 +279,7 @@ mod tests {
.collect::<Vec<_>>()
.into_iter()
.map(|worker| worker.join().unwrap())
.sum()
}

#[cfg(target_pointer_width = "64")]
#[test]
fn is_prime_small_test() {
let num_of_primes = primes(0, 3i64.pow(20), 3);
.sum::<usize>();
assert_eq!(num_of_primes, 166677978);
}

Expand Down