Change project name

master
Trivernis 4 years ago
parent 606067151f
commit be74b0e517

16
Cargo.lock generated

@ -82,6 +82,14 @@ dependencies = [
"lazy_static 1.4.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "euler-10"
version = "0.1.0"
dependencies = [
"may 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "generator"
version = "0.6.19"
@ -186,14 +194,6 @@ dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "primes"
version = "0.1.0"
dependencies = [
"may 0.3.16 (registry+https://github.com/rust-lang/crates.io-index)",
"num_cpus 1.12.0 (registry+https://github.com/rust-lang/crates.io-index)",
]
[[package]]
name = "redox_syscall"
version = "0.1.56"

@ -1,5 +1,5 @@
[package]
name = "primes"
name = "euler-10"
version = "0.1.0"
authors = ["trivernis <trivernis@gmail.com>"]
edition = "2018"

@ -9,5 +9,5 @@ A simple program that calculates prime numbers with multithreading. The resultin
cargo build --release
# run
./target/release/primes [<start number>]
./target/release/euler-10 [<start number>]
```

@ -1,26 +1,17 @@
use may::go;
use may::sync::mpmc::{channel, Sender};
use num_cpus;
use std::env;
use std::time::{Instant, Duration};
fn main() {
may::config().set_workers(num_cpus::get());
let (tx, rx) = channel::<u64>();
let num_threads: u16 = num_cpus::get() as u16;
let mut start: u64 = 1;
let args: Vec<String> = env::args().collect();
if args.len() > 1 {
start = args[1].parse::<u64>().unwrap();
}
if &start % 2 == 0 {
start += 1;
}
println!("Starting {} threads", num_threads);
for i in 0u16..num_threads {
let tx = tx.clone();
go!(move || {
get_primes(start + (2 * &i) as u64, (&num_threads * 2) as u64, 2_000_000, &tx);
get_primes(1 + (2 * &i) as u64, (&num_threads * 2) as u64, 2_000_000, &tx);
});
println!("Started thread {}", i);
}

Loading…
Cancel
Save