Fixed minor issues in reduction, added pseudo matmul test

This commit is contained in:
Alex 2021-04-22 12:26:16 -04:00
parent 7e4b3fc25e
commit ab10c5fef3
2 changed files with 20 additions and 15 deletions

View File

@ -18,7 +18,6 @@ impl Student {
} }
} }
} }
fn main() { fn main() {
let numbers: Vec<Student> = vec![]; let numbers: Vec<Student> = vec![];
@ -41,18 +40,21 @@ fn main() {
println!("{:?}", num); println!("{:?}", num);
} }
let a:Vec<Vec<i32>> = vec![vec![1,2,3],vec![4,5,6],vec![7,8,9]];
let n = a.len();
let mut c = vec![vec![0;n];n];
let mut x = 0; let mut x = 0;
// let mut y = 1;
par_for! { par_for! {
for i in 0..10, reduction x#+, { // I feel like we shouldn't need to capture a here
// let mut lock = x.write(); for k in 0..n, capturing a, reduction x#+, {
// *lock += 7; critical! {
// y *= 6; read a;
x += 2; x += a[1][k]*a[k][0];
}
} }
} }
println!("{:?}", x); c[1][0] = x;
println!("{:?}", c[1][0]);
// let mut local = 0; // let mut local = 0;
// par_for! { // par_for! {
// for i in 1..32, blocksize 1, capturing numbers, private local, { // for i in 1..32, blocksize 1, capturing numbers, private local, {

View File

@ -111,7 +111,10 @@ macro_rules! __internal_par_for {
let __rmp_tpm_mtx = rustmp::ThreadPoolManager::get_instance_guard(); let __rmp_tpm_mtx = rustmp::ThreadPoolManager::get_instance_guard();
let __rmp_tpm = __rmp_tpm_mtx.lock().unwrap(); let __rmp_tpm = __rmp_tpm_mtx.lock().unwrap();
let __rmp_iters = __rmp_tpm.split_iterators($iter, $size); let __rmp_iters = __rmp_tpm.split_iterators($iter, $size);
let __rmp_red_vals = rustmp::Capture::new(Vec::with_capacity(__rmp_iters.len())); let mut __rmp_red_vals = Vec::new();
// let mut __rmp_count = 0;
$(__rmp_red_vals.push(Vec::new()); $red_name = $red_name;)*
let __rmp_red_vals = rustmp::Capture::new(__rmp_red_vals);
for iter in __rmp_iters { for iter in __rmp_iters {
$(let $captured = $captured.clone();)* $(let $captured = $captured.clone();)*
let __rmp_red_vals = __rmp_red_vals.clone(); let __rmp_red_vals = __rmp_red_vals.clone();
@ -121,14 +124,14 @@ macro_rules! __internal_par_for {
for &$name in &iter for &$name in &iter
$blk $blk
let mut __rmp_temp = __rmp_red_vals.write(); let mut __rmp_temp = __rmp_red_vals.write();
$(__rmp_temp.push($red_name);)* let mut __rmp_counter = 0;
$(__rmp_temp[__rmp_counter].push($red_name); __rmp_counter += 1;)*
})); }));
} }
__rmp_tpm.exec(__rmp_tasks); __rmp_tpm.exec(__rmp_tasks);
let mut __rmp_temp = __rmp_red_vals.read(); let mut __rmp_temp = __rmp_red_vals.read();
for i in 0..__rmp_temp.len() { let mut __rmp_counter = 0;
$($red_name = $red_name $red_op __rmp_temp[i];)* $($red_name = __rmp_temp[__rmp_counter].iter().fold($red_name, |x, &y| {x $red_op y}); __rmp_counter += 1;)*;
}
} }
$(let $captured = $captured.unwrap();)* $(let $captured = $captured.unwrap();)*
}; };
@ -193,7 +196,7 @@ macro_rules! __internal_par_for {
captured($($captured:ident)*), captured($($captured:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
reduction $($new_name:ident#$new_op:tt)*, reduction $($new_name:ident#$new_op:tt);*,
$($rem:tt)+) => { $($rem:tt)+) => {
rustmp::__internal_par_for!( rustmp::__internal_par_for!(
var_name($name), var_name($name),