Skip to content
This repository was archived by the owner on Oct 4, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 2 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
43 changes: 33 additions & 10 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ threadpool = "1.7"
lazy_static = "1.1"
rand = "0.5.5"
itertools = "0.7.8"
hashbrown = "0.1"

[dependencies.nix]
version = "0.9"
Expand Down
1 change: 1 addition & 0 deletions LICENSE-THIRD-PARTY.txt
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,7 @@ Library.
** lazy_static
** rand
** itertools
** hashbrown
Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ git clone https://github.com/awslabs/fast-pseudoprimes.git
cd fast-pseudoprimes
cargo +nightly run --features numa,unstable --release
```
The code takes about 24 seconds to run from start to finish.
The code takes about 21.9 seconds to run from start to finish.

## Status of this code
This code is released as-is, and we have no plans to maintain it. We are happy to accept pull requests.
Expand Down
6 changes: 5 additions & 1 deletion src/bloomfilter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,15 @@ use numa_threadpool::ThreadPool;

use std::sync::{Mutex, Arc, mpsc::channel};
use std::sync::atomic::{Ordering, AtomicUsize};
use std::collections::HashMap;
use hashbrown::HashMap;
use std::time::Instant;

mod conc_bloom;
use bloomfilter::conc_bloom::*;

use magic_numbers::*;
use modulus::*;
use time::get_elapsed_time;

const FILTER_SIZE : usize = 1usize << 39;
const FILTER_HASHES : usize = 2;
Expand Down Expand Up @@ -230,6 +231,7 @@ pub fn final_sieve(
t1: &[u64],
t2: &[u64]
) -> Vec<Pseudoprime> {
let total = Instant::now();
let t2map = Arc::new(t2map);
let pool = ThreadPool::new(|_| ());
let t1_product_set = Arc::new(ProductSet::new(t1_forward, MODULUS));
Expand Down Expand Up @@ -264,6 +266,8 @@ pub fn final_sieve(

let t3_misses = t3_misses.load(Ordering::SeqCst);

println!("[final_sieve] Completed in {}", get_elapsed_time(total));

println!("Found {} pseudoprimes, with {} T3 misses, {} T2 false positives",
results.len(), t3_misses, t2map.len() - t3_misses - results.len());

Expand Down
6 changes: 5 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#![allow(dead_code)]
#![cfg_attr(feature = "unstable", feature(duration_as_u128))]
#![cfg_attr(feature = "unstable", feature(asm))]
#![cfg_attr(feature = "unstable", feature(core_intrinsics))]
#![cfg_attr(feature = "unstable", feature(avx512_target_feature))]
Expand All @@ -11,6 +12,8 @@ extern crate lazy_static;
extern crate modinverse;
extern crate rug;
extern crate threadpool;
extern crate hashbrown;

#[cfg(feature="unstable")]
extern crate libc;
extern crate itertools;
Expand All @@ -22,4 +25,5 @@ pub mod gray_prod_iter;
pub mod magic_numbers;
pub mod bitset;
pub mod modulus;
pub mod numa_threadpool;
pub mod numa_threadpool;
pub mod time;
6 changes: 4 additions & 2 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

#![cfg_attr(feature = "unstable", feature(asm))]
#![cfg_attr(feature = "unstable", feature(duration_as_u128))]

extern crate pseudoprimes;
extern crate rug;
Expand All @@ -14,10 +15,11 @@ use magic_numbers::*;
use bloomfilter::*;

use std::time::Instant;
use pseudoprimes::time::get_elapsed_time;


fn main() {
let total = Instant::now();
let start = Instant::now();

// fp p<=0.001, 32GiB, k=2
let filter = bloom_t1(&T1_INVERSE);
Expand All @@ -32,5 +34,5 @@ fn main() {
println!("Found passing prime {}, vector {:?}", result.pseudoprime, result.factors);
}

println!("Total time: {} seconds, primes found: {}", total.elapsed().as_secs(), results.len());
println!("Completed in: {}, primes found: {}", get_elapsed_time(start), results.len());
}
4 changes: 2 additions & 2 deletions src/numa_threadpool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ pub use self::numa::*;
mod numa {
extern crate nix;

use libc::{c_char, c_uint, c_int, c_ulong};
use numa_threadpool::numa::nix::libc::{c_char, c_uint, c_int, c_ulong};
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't quite understand why removing the unstable flag caused the build to fail for missing imports, the compile suggested this and it fixed it.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's because lib.rs has a #[cfg(feature="unstable")] mark on the libc extern crate (and I think cargo conditional-depends on it as well)

Copy link

@bdonlan bdonlan Dec 10, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To fix this:

  1. Remove optional=true from the libc clause in Cargo.toml
  2. Remove "libc" from the feature definitions in Cargo.toml
  3. Add an extern crate libc; to src/lib.rs - or update to Rust 2018 :)

use std::ffi::CString;
use std::sync::{Arc, Mutex, Condvar};
use std::thread::{JoinHandle, self};
Expand Down Expand Up @@ -148,7 +148,7 @@ mod numa {

fn worker<Context: 'static>(node: &NodeInfo<Context>, cpu_id: c_uint, queue: &WorkQueue<Context>) {
use self::nix::unistd::gettid;
use libc::pid_t;
use numa_threadpool::numa::nix::libc::pid_t;

let tid = pid_t::from(gettid());
unsafe {
Expand Down
5 changes: 3 additions & 2 deletions src/progress.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

use std::time::Instant;
use std::sync::atomic::{Ordering, AtomicUsize};
use time::get_elapsed_time;

pub struct ProgressReporter {
desc: String,
Expand All @@ -27,8 +28,8 @@ impl<'a> Drop for ProgressHandle<'a> {

impl<'a> Drop for ProgressReporter {
fn drop(&mut self) {
println!("[{}] Completed {} in {}s", self.desc, self.counter.load(Ordering::SeqCst),
self.start_time.elapsed().as_secs());
println!("[{}] Completed {} in {}", self.desc, self.counter.load(Ordering::SeqCst),
get_elapsed_time(self.start_time));
}
}

Expand Down
14 changes: 14 additions & 0 deletions src/time.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
// time.rs Copyright 2018 Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: Apache-2.0

use std::time::Instant;

#[cfg(feature = "unstable")]
pub fn get_elapsed_time(start: Instant) -> String {
return format!("{} ms", start.elapsed().as_millis());
}

#[cfg(not(feature = "unstable"))]
pub fn get_elapsed_time(start: Instant) -> String {
return format!("{} sec", start.elapsed().as_secs());
}