Refactoring part2: renamed keywords to blocksize, read, locked, private, reduction.

This commit is contained in:
Jack Yu 2021-04-25 23:23:11 -04:00
parent dcd1afbc12
commit 64b830c7e6
2 changed files with 60 additions and 60 deletions

View File

@ -22,7 +22,7 @@ fn main() {
let numbers: Vec<Student> = vec![]; let numbers: Vec<Student> = vec![];
par_for! { par_for! {
for i in 1..32, blocksize 4, capturing numbers, { for i in 1..32, blocksize 4, locked numbers, {
//std::thread::sleep( //std::thread::sleep(
// time::Duration::from_secs( // time::Duration::from_secs(
// rand::thread_rng().gen_range(1..10))); // rand::thread_rng().gen_range(1..10)));
@ -48,7 +48,7 @@ fn main() {
for j in 0..n { for j in 0..n {
let mut x = 0; let mut x = 0;
par_for! { par_for! {
for k in 0..n, using a b, reducing x#+, { for k in 0..n, read a b, reduction x#+, {
x += a[i][k]*b[k][j]; x += a[i][k]*b[k][j];
} }
} }
@ -58,7 +58,7 @@ fn main() {
println!("{:?}", c); println!("{:?}", c);
// 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, locked numbers, private local, {
// local += 1; // local += 1;
// println!("{}", local); // println!("{}", local);
// let mut lock = numbers.write(); // let mut lock = numbers.write();

View File

@ -71,25 +71,25 @@ macro_rules! critical {
#[macro_export] #[macro_export]
macro_rules! __internal_par_for { macro_rules! __internal_par_for {
// without reducing // without reduction
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing(), reduction(),
$blk:block) => { $blk:block) => {
let mut __rmp_tasks = Vec::new(); let mut __rmp_tasks = Vec::new();
$(let $captured = rustmp::Capture::new($captured);)* $(let $locked = rustmp::Capture::new($locked);)*
$(let $used_name = std::sync::Arc::new($used_name.clone());)* $(let $read = std::sync::Arc::new($read.clone());)*
{ {
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);
for iter in __rmp_iters { for iter in __rmp_iters {
$(let $captured = $captured.clone();)* $(let $locked = $locked.clone();)*
$(let $used_name = $used_name.clone();)* $(let $read = $read.clone();)*
$(let $private = $private.clone();)* $(let $private = $private.clone();)*
__rmp_tasks.push(rustmp::as_static_job(move || { __rmp_tasks.push(rustmp::as_static_job(move || {
$(let mut $private = $private.clone();)* $(let mut $private = $private.clone();)*
@ -99,20 +99,20 @@ macro_rules! __internal_par_for {
} }
__rmp_tpm.exec(__rmp_tasks); __rmp_tpm.exec(__rmp_tasks);
} }
$(let $captured = $captured.unwrap();)* $(let $locked = $locked.unwrap();)*
}; };
// with reducing // with reduction
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)+), reduction($($red_name:ident, $red_op:tt)+),
$blk:block) => { $blk:block) => {
let mut __rmp_tasks = Vec::new(); let mut __rmp_tasks = Vec::new();
$(let $captured = rustmp::Capture::new($captured);)* $(let $locked = rustmp::Capture::new($locked);)*
$(let $used_name = std::sync::Arc::new($used_name.clone());)* $(let $read = std::sync::Arc::new($read.clone());)*
{ {
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();
@ -121,8 +121,8 @@ macro_rules! __internal_par_for {
$(__rmp_red_vals.push(Vec::new()); stringify!($red_name);)* $(__rmp_red_vals.push(Vec::new()); stringify!($red_name);)*
let __rmp_red_vals = rustmp::Capture::new(__rmp_red_vals); 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 $locked = $locked.clone();)*
$(let $used_name = $used_name.clone();)* $(let $read = $read.clone();)*
$(let $private = $private.clone();)* $(let $private = $private.clone();)*
let __rmp_red_vals = __rmp_red_vals.clone(); let __rmp_red_vals = __rmp_red_vals.clone();
$(let $red_name = $red_name.clone();)* $(let $red_name = $red_name.clone();)*
@ -142,106 +142,106 @@ macro_rules! __internal_par_for {
$($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, |x, &y| {x $red_op y});
__rmp_counter += 1;)* __rmp_counter += 1;)*
} }
$(let $captured = $captured.unwrap();)* $(let $locked = $locked.unwrap();)*
}; };
// Parse blocksize // Parse blocksize
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
blocksize $new_size:expr, blocksize $new_size:expr,
$($rem:tt)+) => { $($rem:tt)+) => {
rustmp::__internal_par_for!( rustmp::__internal_par_for!(
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($new_size), blocksize($new_size),
captured($($captured)*), locked($($locked)*),
using($($used_name)*), read($($read)*),
private($($private)*), private($($private)*),
reducing($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse capturing // Parse locked
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
capturing $($new_captured:ident)*, locked $($new_locked:ident)*,
$($rem:tt)+) => { $($rem:tt)+) => {
rustmp::__internal_par_for!( rustmp::__internal_par_for!(
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
captured($($new_captured)*), locked($($new_locked)*),
using($($used_name)*), read($($read)*),
private($($private)*), private($($private)*),
reducing($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse using // Parse read
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
using $($new_name:ident)*, read $($new_name:ident)*,
$($rem:tt)+) => { $($rem:tt)+) => {
rustmp::__internal_par_for!( rustmp::__internal_par_for!(
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
captured($($captured)*), locked($($locked)*),
using($($new_name)*), read($($new_name)*),
private($($private)*), private($($private)*),
reducing($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse private // Parse private
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
private $($new_private:ident)*, private $($new_private:ident)*,
$($rem:tt)+) => { $($rem:tt)+) => {
rustmp::__internal_par_for!( rustmp::__internal_par_for!(
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
captured($($captured)*), locked($($locked)*),
using($($used_name)*), read($($read)*),
private($($new_private)*), private($($new_private)*),
reducing($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse reducing // Parse reduction
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
captured($($captured:ident)*), locked($($locked:ident)*),
using($($used_name:ident)*), read($($read:ident)*),
private($($private:ident)*), private($($private:ident)*),
reducing($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
reducing $($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),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
captured($($captured)*), locked($($locked)*),
using($($used_name)*), read($($read)*),
private($($private)*), private($($private)*),
reducing($($new_name, $new_op)*), reduction($($new_name, $new_op)*),
$($rem)*) $($rem)*)
}; };
} }
@ -257,10 +257,10 @@ macro_rules! par_for {
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize(1), blocksize(1),
captured(), locked(),
using(), read(),
private(), private(),
reducing(), reduction(),
$($rem)*) $($rem)*)
} }
} }