Keyword change again: shared, shared_mut, shared_unsafe

This commit is contained in:
Jack Yu 2021-04-30 19:35:22 -04:00
parent 438622d8f1
commit 0b22ea2395
3 changed files with 44 additions and 44 deletions

View File

@ -40,7 +40,7 @@ fn main() {
let result = gen_empty(nsize); let result = gen_empty(nsize);
let timer = Instant::now(); let timer = Instant::now();
par_for! { par_for! {
for i in 0..nsize, locked result, read matrix, { for i in 0..nsize, shared_mut result, shared matrix, {
for j in 0..nsize { for j in 0..nsize {
let mut sum = 0.0; let mut sum = 0.0;
for k in 0..nsize { for k in 0..nsize {

View File

@ -31,7 +31,7 @@ fn main() {
let numbers: Vec<Student> = vec![]; let numbers: Vec<Student> = vec![];
par_for! { par_for! {
for i in 1..32, blocksize 4, locked numbers, { for i in 1..32, blocksize 4, shared_mut 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)));
@ -57,7 +57,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, read a b, reduction x#+, { for k in 0..n, shared a b, reduction x#+, {
x += (a[i][k]*b[k][j]); x += (a[i][k]*b[k][j]);
} }
} }
@ -67,7 +67,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, locked numbers, private local, { // for i in 1..32, blocksize 1, shared_mut numbers, private local, {
// local += 1; // local += 1;
// println!("{}", local); // println!("{}", local);
// let mut lock = numbers.write(); // let mut lock = numbers.write();

View File

@ -83,21 +83,21 @@ macro_rules! __internal_par_for {
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction(), reduction(),
$blk:block) => { $blk:block) => {
let mut __rmp_tasks = Vec::new(); let mut __rmp_tasks = Vec::new();
$(let $locked = rustmp::Capture::new($locked);)* $(let $shared_mut = rustmp::Capture::new($shared_mut);)*
$(let $read = std::sync::Arc::new($read.clone());)* $(let $shared = std::sync::Arc::new($shared.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 $locked = $locked.clone();)* $(let $shared_mut = $shared_mut.clone();)*
$(let $read = $read.clone();)* $(let $shared = $shared.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();)*
@ -107,20 +107,20 @@ macro_rules! __internal_par_for {
} }
__rmp_tpm.exec(__rmp_tasks); __rmp_tpm.exec(__rmp_tasks);
} }
$(let $locked = $locked.unwrap();)* $(let $shared_mut = $shared_mut.unwrap();)*
}; };
// with reduction // with reduction
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($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 $locked = rustmp::Capture::new($locked);)* $(let $shared_mut = rustmp::Capture::new($shared_mut);)*
$(let $read = std::sync::Arc::new($read.clone());)* $(let $shared = std::sync::Arc::new($shared.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();
@ -129,8 +129,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 $locked = $locked.clone();)* $(let $shared_mut = $shared_mut.clone();)*
$(let $read = $read.clone();)* $(let $shared = $shared.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();)*
@ -150,14 +150,14 @@ macro_rules! __internal_par_for {
$($red_name = __rmp_temp[__rmp_counter].iter().fold($red_name, rustmp::__reduction_operation!($red_op)); $($red_name = __rmp_temp[__rmp_counter].iter().fold($red_name, rustmp::__reduction_operation!($red_op));
__rmp_counter += 1;)* __rmp_counter += 1;)*
} }
$(let $locked = $locked.unwrap();)* $(let $shared_mut = $shared_mut.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),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
blocksize $new_size:expr, blocksize $new_size:expr,
@ -166,48 +166,48 @@ macro_rules! __internal_par_for {
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($new_size), blocksize($new_size),
locked($($locked)*), shared_mut($($shared_mut)*),
read($($read)*), shared($($shared)*),
private($($private)*), private($($private)*),
reduction($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse locked // Parse shared_mut
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
locked $($new_locked:ident)*, shared_mut $($new_shared_mut: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),
locked($($new_locked)*), shared_mut($($new_shared_mut)*),
read($($read)*), shared($($shared)*),
private($($private)*), private($($private)*),
reduction($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
}; };
// Parse read // Parse shared
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
read $($new_name:ident)*, shared $($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),
locked($($locked)*), shared_mut($($shared_mut)*),
read($($new_name)*), shared($($new_name)*),
private($($private)*), private($($private)*),
reduction($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
@ -216,8 +216,8 @@ macro_rules! __internal_par_for {
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared:ident)*),
private($($private:ident)*), private($($private:ident)*),
reduction($($red_name:ident, $red_op:tt)*), reduction($($red_name:ident, $red_op:tt)*),
private $($new_private:ident)*, private $($new_private:ident)*,
@ -226,8 +226,8 @@ macro_rules! __internal_par_for {
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
locked($($locked)*), shared_mut($($shared_mut)*),
read($($read)*), shared($($shared)*),
private($($new_private)*), private($($new_private)*),
reduction($($red_name, $red_op)*), reduction($($red_name, $red_op)*),
$($rem)*) $($rem)*)
@ -236,8 +236,8 @@ macro_rules! __internal_par_for {
(var_name($name:ident), (var_name($name:ident),
iterator($iter:expr), iterator($iter:expr),
blocksize($size:expr), blocksize($size:expr),
locked($($locked:ident)*), shared_mut($($shared_mut:ident)*),
read($($read:ident)*), shared($($shared: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);*,
@ -246,8 +246,8 @@ macro_rules! __internal_par_for {
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize($size), blocksize($size),
locked($($locked)*), shared_mut($($shared_mut)*),
read($($read)*), shared($($shared)*),
private($($private)*), private($($private)*),
reduction($($new_name, $new_op)*), reduction($($new_name, $new_op)*),
$($rem)*) $($rem)*)
@ -265,8 +265,8 @@ macro_rules! par_for {
var_name($name), var_name($name),
iterator($iter), iterator($iter),
blocksize(1), blocksize(1),
locked(), shared_mut(),
read(), shared(),
private(), private(),
reduction(), reduction(),
$($rem)*) $($rem)*)