mirror of https://github.com/xythrez/RustMP.git
Added in potential using keyword and full matrix multiplication example
This commit is contained in:
parent
ab10c5fef3
commit
416b694ef3
|
@ -40,21 +40,22 @@ 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 a = vec![vec![1,2,3],vec![4,5,6],vec![7,8,9]];
|
||||||
|
let b = vec![vec![3,2,1],vec![6,5,4],vec![9,8,7]];
|
||||||
let n = a.len();
|
let n = a.len();
|
||||||
let mut c = vec![vec![0;n];n];
|
let mut c = vec![vec![0;n];n];
|
||||||
|
for i in 0..n {
|
||||||
|
for j in 0..n {
|
||||||
let mut x = 0;
|
let mut x = 0;
|
||||||
par_for! {
|
par_for! {
|
||||||
// I feel like we shouldn't need to capture a here
|
for k in 0..n, using a b, reducing x#+, {
|
||||||
for k in 0..n, capturing a, reduction x#+, {
|
x += a[i][k]*b[k][j];
|
||||||
critical! {
|
|
||||||
read a;
|
|
||||||
x += a[1][k]*a[k][0];
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
c[i][j] = x;
|
||||||
}
|
}
|
||||||
c[1][0] = x;
|
}
|
||||||
println!("{:?}", c[1][0]);
|
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, capturing numbers, private local, {
|
||||||
|
|
63
src/lib.rs
63
src/lib.rs
|
@ -71,13 +71,14 @@ macro_rules! critical {
|
||||||
|
|
||||||
#[macro_export]
|
#[macro_export]
|
||||||
macro_rules! __internal_par_for {
|
macro_rules! __internal_par_for {
|
||||||
// without reduction
|
// without reducing
|
||||||
(var_name($name:ident),
|
(var_name($name:ident),
|
||||||
iterator($iter:expr),
|
iterator($iter:expr),
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction(),
|
reducing(),
|
||||||
|
using($($used_name:ident)*),
|
||||||
$blk:block) => {
|
$blk:block) => {
|
||||||
let mut __rmp_tasks = Vec::new();
|
let mut __rmp_tasks = Vec::new();
|
||||||
$(let $captured = rustmp::Capture::new($captured);)*
|
$(let $captured = rustmp::Capture::new($captured);)*
|
||||||
|
@ -87,6 +88,7 @@ macro_rules! __internal_par_for {
|
||||||
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 $captured = $captured.clone();)*
|
||||||
|
$(let $used_name = $used_name.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();)*
|
||||||
for &$name in &iter
|
for &$name in &iter
|
||||||
|
@ -97,13 +99,14 @@ macro_rules! __internal_par_for {
|
||||||
}
|
}
|
||||||
$(let $captured = $captured.unwrap();)*
|
$(let $captured = $captured.unwrap();)*
|
||||||
};
|
};
|
||||||
// with reduction
|
// with reducing
|
||||||
(var_name($name:ident),
|
(var_name($name:ident),
|
||||||
iterator($iter:expr),
|
iterator($iter:expr),
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction($($red_name:ident, $red_op:tt)+),
|
reducing($($red_name:ident, $red_op:tt)+),
|
||||||
|
using($($used_name:ident)*),
|
||||||
$blk:block) => {
|
$blk:block) => {
|
||||||
let mut __rmp_tasks = Vec::new();
|
let mut __rmp_tasks = Vec::new();
|
||||||
$(let $captured = rustmp::Capture::new($captured);)*
|
$(let $captured = rustmp::Capture::new($captured);)*
|
||||||
|
@ -117,6 +120,7 @@ macro_rules! __internal_par_for {
|
||||||
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 $captured = $captured.clone();)*
|
||||||
|
$(let $used_name = $used_name.clone();)*
|
||||||
let __rmp_red_vals = __rmp_red_vals.clone();
|
let __rmp_red_vals = __rmp_red_vals.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();)*
|
||||||
|
@ -141,7 +145,8 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction($($red_name:ident, $red_op:tt)*),
|
reducing($($red_name:ident, $red_op:tt)*),
|
||||||
|
using($($used_name:ident)*),
|
||||||
blocksize $new_size:expr,
|
blocksize $new_size:expr,
|
||||||
$($rem:tt)+) => {
|
$($rem:tt)+) => {
|
||||||
rustmp::__internal_par_for!(
|
rustmp::__internal_par_for!(
|
||||||
|
@ -150,7 +155,8 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($new_size),
|
blocksize($new_size),
|
||||||
captured($($captured)*),
|
captured($($captured)*),
|
||||||
private($($private)*),
|
private($($private)*),
|
||||||
reduction($($red_name, $red_op)*),
|
reducing($($red_name, $red_op)*),
|
||||||
|
using($($used_name)*),
|
||||||
$($rem)*)
|
$($rem)*)
|
||||||
};
|
};
|
||||||
// Parse capturing
|
// Parse capturing
|
||||||
|
@ -159,7 +165,8 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction($($red_name:ident, $red_op:tt)*),
|
reducing($($red_name:ident, $red_op:tt)*),
|
||||||
|
using($($used_name:ident)*),
|
||||||
capturing $($new_captured:ident)*,
|
capturing $($new_captured:ident)*,
|
||||||
$($rem:tt)+) => {
|
$($rem:tt)+) => {
|
||||||
rustmp::__internal_par_for!(
|
rustmp::__internal_par_for!(
|
||||||
|
@ -168,7 +175,8 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size),
|
blocksize($size),
|
||||||
captured($($new_captured)*),
|
captured($($new_captured)*),
|
||||||
private($($private)*),
|
private($($private)*),
|
||||||
reduction($($red_name, $red_op)*),
|
reducing($($red_name, $red_op)*),
|
||||||
|
using($($used_name)*),
|
||||||
$($rem)*)
|
$($rem)*)
|
||||||
};
|
};
|
||||||
// Parse private
|
// Parse private
|
||||||
|
@ -177,7 +185,8 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction($($red_name:ident, $red_op:tt)*),
|
reducing($($red_name:ident, $red_op:tt)*),
|
||||||
|
using($($used_name:ident)*),
|
||||||
private $($new_private:ident)*,
|
private $($new_private:ident)*,
|
||||||
$($rem:tt)+) => {
|
$($rem:tt)+) => {
|
||||||
rustmp::__internal_par_for!(
|
rustmp::__internal_par_for!(
|
||||||
|
@ -186,17 +195,19 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size),
|
blocksize($size),
|
||||||
captured($($captured)*),
|
captured($($captured)*),
|
||||||
private($($new_private)*),
|
private($($new_private)*),
|
||||||
reduction($($red_name, $red_op)*),
|
reducing($($red_name, $red_op)*),
|
||||||
|
using($($used_name)*),
|
||||||
$($rem)*)
|
$($rem)*)
|
||||||
};
|
};
|
||||||
// Parse reduction
|
// Parse reducing
|
||||||
(var_name($name:ident),
|
(var_name($name:ident),
|
||||||
iterator($iter:expr),
|
iterator($iter:expr),
|
||||||
blocksize($size:expr),
|
blocksize($size:expr),
|
||||||
captured($($captured:ident)*),
|
captured($($captured:ident)*),
|
||||||
private($($private:ident)*),
|
private($($private:ident)*),
|
||||||
reduction($($red_name:ident, $red_op:tt)*),
|
reducing($($red_name:ident, $red_op:tt)*),
|
||||||
reduction $($new_name:ident#$new_op:tt);*,
|
using($($used_name:ident)*),
|
||||||
|
reducing $($new_name:ident#$new_op:tt);*,
|
||||||
$($rem:tt)+) => {
|
$($rem:tt)+) => {
|
||||||
rustmp::__internal_par_for!(
|
rustmp::__internal_par_for!(
|
||||||
var_name($name),
|
var_name($name),
|
||||||
|
@ -204,7 +215,28 @@ macro_rules! __internal_par_for {
|
||||||
blocksize($size),
|
blocksize($size),
|
||||||
captured($($captured)*),
|
captured($($captured)*),
|
||||||
private($($private)*),
|
private($($private)*),
|
||||||
reduction($($new_name, $new_op)*),
|
reducing($($new_name, $new_op)*),
|
||||||
|
using($($used_name)*),
|
||||||
|
$($rem)*)
|
||||||
|
};
|
||||||
|
// Parse using
|
||||||
|
(var_name($name:ident),
|
||||||
|
iterator($iter:expr),
|
||||||
|
blocksize($size:expr),
|
||||||
|
captured($($captured:ident)*),
|
||||||
|
private($($private:ident)*),
|
||||||
|
reducing($($red_name:ident, $red_op:tt)*),
|
||||||
|
using($($used_name:ident)*),
|
||||||
|
using $($new_name:ident)*,
|
||||||
|
$($rem:tt)+) => {
|
||||||
|
rustmp::__internal_par_for!(
|
||||||
|
var_name($name),
|
||||||
|
iterator($iter),
|
||||||
|
blocksize($size),
|
||||||
|
captured($($captured)*),
|
||||||
|
private($($private)*),
|
||||||
|
reducing($($red_name, $red_op)*),
|
||||||
|
using($($new_name)*),
|
||||||
$($rem)*)
|
$($rem)*)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -222,7 +254,8 @@ macro_rules! par_for {
|
||||||
blocksize(1),
|
blocksize(1),
|
||||||
captured(),
|
captured(),
|
||||||
private(),
|
private(),
|
||||||
reduction(),
|
reducing(),
|
||||||
|
using(),
|
||||||
$($rem)*)
|
$($rem)*)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue