Fixed empty iterator, optimized matmul tests to initialize threadpool

first
This commit is contained in:
Yiyao Yu 2021-05-04 15:26:18 -04:00
parent b88145b5ba
commit b6ee94515e
7 changed files with 50 additions and 2 deletions

View File

@ -41,7 +41,8 @@ C comparison benchmarks can be found in `omp/`. These can be compiled using
square matrix dimensions (i.e. `./matmul <nsize>`).
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

View File

@ -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)

View File

@ -16,6 +16,10 @@ fn gen_matrix(nsize: usize) -> Vec<Vec<f64>> {
ret
}
fn warmup() {
let _discard = (0..1).into_par_iter().map(|i| {i}).collect::<Vec<i32>>();
}
fn main() {
let args: Vec<String> = 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()

View File

@ -29,6 +29,13 @@ fn gen_empty(nsize: usize) -> Vec<Vec<f64>> {
ret
}
fn warmup() {
par_for! {
for _ in 0..1, {
}
}
}
fn main() {
let args: Vec<String> = 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, {

View File

@ -29,6 +29,13 @@ fn gen_empty(nsize: usize) -> Vec<Vec<f64>> {
ret
}
fn warmup() {
par_for! {
for _ in 0..1, {
}
}
}
fn main() {
let args: Vec<String> = 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, {

View File

@ -27,6 +27,8 @@ fn gen_empty(nsize: usize) -> Vec<Vec<f64>> {
ret
}
fn warmup() {}
fn main() {
let args: Vec<String> = 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 {

View File

@ -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)*)
}
}