diff --git a/README.md b/README.md index 9a9281c..7467224 100644 --- a/README.md +++ b/README.md @@ -41,7 +41,8 @@ C comparison benchmarks can be found in `omp/`. These can be compiled using square matrix dimensions (i.e. `./matmul `). Additional benchmarks are located in `benches`. These require Rust nightly and -can be run with the following command: +can be run with the following command, note that RustMP thread pool lazy startup +cost is factored into these tests: ``` $ cargo +nightly bench diff --git a/omp/src/main.c b/omp/src/main.c index dff9ef1..2134fa5 100644 --- a/omp/src/main.c +++ b/omp/src/main.c @@ -51,8 +51,17 @@ free_all (double **matrix, double **result, size_t nsize) free (result); } +void +warmup() { + size_t i; +#ifdef PAR + #pragma omp parallel for +#endif + for (i = 0; i < 1; i++) {} +} -int main (int argc, char *argv[]) +int +main (int argc, char *argv[]) { struct timespec start, end; size_t i, j, k, nsize; @@ -70,6 +79,7 @@ int main (int argc, char *argv[]) } nsize = raw_size; generate_matrices (&matrix, &result, nsize); + warmup(); clock_gettime (CLOCK_MONOTONIC, &start); #ifdef PAR #pragma omp parallel for default(shared) private(j, k, sum) diff --git a/src/bin/rayon_matmul.rs b/src/bin/rayon_matmul.rs index 49a4c43..88856cd 100644 --- a/src/bin/rayon_matmul.rs +++ b/src/bin/rayon_matmul.rs @@ -16,6 +16,10 @@ fn gen_matrix(nsize: usize) -> Vec> { ret } +fn warmup() { + let _discard = (0..1).into_par_iter().map(|i| {i}).collect::>(); +} + fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { @@ -27,6 +31,7 @@ fn main() { 1, ); let matrix = gen_matrix(nsize); + warmup(); let timer = Instant::now(); let _result = (0..nsize) .into_par_iter() diff --git a/src/bin/rmp_matmul.rs b/src/bin/rmp_matmul.rs index e03c032..701c0a9 100644 --- a/src/bin/rmp_matmul.rs +++ b/src/bin/rmp_matmul.rs @@ -29,6 +29,13 @@ fn gen_empty(nsize: usize) -> Vec> { ret } +fn warmup() { + par_for! { + for _ in 0..1, { + } + } +} + fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { @@ -41,6 +48,7 @@ fn main() { ); let matrix = gen_matrix(nsize); let result = gen_empty(nsize); + warmup(); let timer = Instant::now(); par_for! { for i in 0..nsize, shared_mut result, shared matrix, { diff --git a/src/bin/rmpunsafe_matmul.rs b/src/bin/rmpunsafe_matmul.rs index bcd4c6a..763885d 100644 --- a/src/bin/rmpunsafe_matmul.rs +++ b/src/bin/rmpunsafe_matmul.rs @@ -29,6 +29,13 @@ fn gen_empty(nsize: usize) -> Vec> { ret } +fn warmup() { + par_for! { + for _ in 0..1, { + } + } +} + fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { @@ -41,6 +48,7 @@ fn main() { ); let matrix = gen_matrix(nsize); let mut result = gen_empty(nsize); + warmup(); let timer = Instant::now(); par_for! { for i in 0..nsize, shared_unsafe result, shared matrix, { diff --git a/src/bin/seqrs_matmul.rs b/src/bin/seqrs_matmul.rs index a800933..f47ae88 100644 --- a/src/bin/seqrs_matmul.rs +++ b/src/bin/seqrs_matmul.rs @@ -27,6 +27,8 @@ fn gen_empty(nsize: usize) -> Vec> { ret } +fn warmup() {} + fn main() { let args: Vec = env::args().collect(); if args.len() != 2 { @@ -39,6 +41,7 @@ fn main() { ); let matrix = gen_matrix(nsize); let mut result = gen_empty(nsize); + warmup(); let timer = Instant::now(); for i in 0..nsize { for j in 0..nsize { diff --git a/src/lib.rs b/src/lib.rs index 97968de..b978842 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -357,5 +357,18 @@ macro_rules! par_for { private(), reduction(), $($rem)*) + }; + + (for _ in $iter:expr, $($rem:tt)+) => { + rustmp::__internal_par_for!( + var_name(__rmp_internal_unused), + iterator($iter), + blocksize(1), + shared_mut(), + shared(), + shared_unsafe(), + private(), + reduction(), + $($rem)*) } }