Merge branch 'alex' into jack

This commit is contained in:
Jack Yu 2021-04-30 19:25:32 -04:00
commit 438622d8f1
2 changed files with 21 additions and 4 deletions

View File

@ -18,6 +18,15 @@ impl Student {
}
}
}
fn min(x: i32, y: &i32) -> i32 {
if x < *y {
x
} else {
*y
}
}
fn main() {
let numbers: Vec<Student> = vec![];
@ -49,7 +58,7 @@ fn main() {
let mut x = 0;
par_for! {
for k in 0..n, read a b, reduction x#+, {
x += a[i][k]*b[k][j];
x += (a[i][k]*b[k][j]);
}
}
c[i][j] = x;

View File

@ -69,6 +69,14 @@ macro_rules! critical {
};
}
#[macro_export]
macro_rules! __reduction_operation {
($f:ident) => {$f};
($op:tt) => {
|x, &y| {x $op y}
}
}
#[macro_export]
macro_rules! __internal_par_for {
// without reduction
@ -90,7 +98,7 @@ macro_rules! __internal_par_for {
for iter in __rmp_iters {
$(let $locked = $locked.clone();)*
$(let $read = $read.clone();)*
$(let $private = $private.clone();)*
// $(let $private = $private.clone();)*
__rmp_tasks.push(rustmp::as_static_job(move || {
$(let mut $private = $private.clone();)*
for &$name in &iter
@ -123,7 +131,7 @@ macro_rules! __internal_par_for {
for iter in __rmp_iters {
$(let $locked = $locked.clone();)*
$(let $read = $read.clone();)*
$(let $private = $private.clone();)*
// $(let $private = $private.clone();)*
let __rmp_red_vals = __rmp_red_vals.clone();
$(let $red_name = $red_name.clone();)*
__rmp_tasks.push(rustmp::as_static_job(move || {
@ -139,7 +147,7 @@ macro_rules! __internal_par_for {
__rmp_tpm.exec(__rmp_tasks);
let mut __rmp_temp = __rmp_red_vals.read();
let mut __rmp_counter = 0;
$($red_name = __rmp_temp[__rmp_counter].iter().fold($red_name, |x, &y| {x $red_op y});
$($red_name = __rmp_temp[__rmp_counter].iter().fold($red_name, rustmp::__reduction_operation!($red_op));
__rmp_counter += 1;)*
}
$(let $locked = $locked.unwrap();)*