Change project name

master
Trivernis 5 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)", "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]] [[package]]
name = "generator" name = "generator"
version = "0.6.19" version = "0.6.19"
@ -186,14 +194,6 @@ dependencies = [
"libc 0.2.66 (registry+https://github.com/rust-lang/crates.io-index)", "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]] [[package]]
name = "redox_syscall" name = "redox_syscall"
version = "0.1.56" version = "0.1.56"

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

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

@ -1,26 +1,17 @@
use may::go; use may::go;
use may::sync::mpmc::{channel, Sender}; use may::sync::mpmc::{channel, Sender};
use num_cpus; use num_cpus;
use std::env;
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
fn main() { fn main() {
may::config().set_workers(num_cpus::get()); may::config().set_workers(num_cpus::get());
let (tx, rx) = channel::<u64>(); let (tx, rx) = channel::<u64>();
let num_threads: u16 = num_cpus::get() as u16; 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); println!("Starting {} threads", num_threads);
for i in 0u16..num_threads { for i in 0u16..num_threads {
let tx = tx.clone(); let tx = tx.clone();
go!(move || { 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); println!("Started thread {}", i);
} }

Loading…
Cancel
Save