EDIT: I was being a dummy got it to work, with following code statement:
fn packstep_single(data: &mut point::Particles<'_>, iter: usize){
let p_i = data.pvec[iter];
let (wgx, wgy, wgz) = data
.pvec
.par_iter()
.enumerate()
.map(|(j, p_j)| {
let rij = p_i - *p_j;
let mut rij2 = (rij * rij).sum();
if j != iter {
if rij2 <= AC::H2 {
rij2 = rij2.sqrt();
let rij1 = 1.0 / (rij2);
let q = rij2 * AC::H1;
let q1 = q - 2.0;
let qq3 = q * q1 * q1 * q1;
let wq = AC::AD * AC::FAC * qq3;
return
(wq * (rij.0 * rij1) * AC::H1,wq * (rij.1 * rij1) * AC::H1,wq * (rij.2 * rij1) * AC::H1)
}
}
// if we don't do the calculation, just contribute '0' to the sum
(0.0, 0.0, 0.0)
})
.reduce(|| (0.0, 0.0, 0.0), |a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2));
let u_i = data.uvec[iter];
let dux = (-AC::BETA * wgx * AC::V - AC::ZETA * u_i.0) * AC::DT;
let duy = (-AC::BETA * wgy * AC::V - AC::ZETA * u_i.1) * AC::DT;
let duz = (-AC::BETA * wgz * AC::V - AC::ZETA * u_i.2) * AC::DT;
data.utmp[iter] = u_i + point::Point(dux, duy, duz);
data.ptmp[iter] = p_i + point::Point(dux * AC::DT, duy, duz * AC::DT);
}
Unfortunately the performance is not very good currently since it takes 6000 ms.
--OLD MESSAGE--
Hello @daboross!
Thank you very much for your interest and example code. I have tried to implement it:
let p_i = data.pvec[iter];
let (wgx, wgy, wgz) = data
.pvec
.par_iter()
.enumerate()
.map(|(j, p_j)| {
if j != iter {
let rij = p_i - *p_j;
let mut rij2 = (rij * rij).sum();
if rij2 <= AC::H2 {
rij2 = rij2.sqrt();
let rij1 = 1.0 / (rij2);
let q = rij2 * AC::H1;
let q1 = q - 2.0;
let qq3 = q * q1 * q1 * q1;
let wq = AC::AD * AC::FAC * qq3;
wgx = 2.0;
wgy = 2.0;
wgz = 2.0;
}
return
(wgx,wgy,wgz)
;
}
// if we don't do the calculation, just contribute '0' to the sum
(0.0, 0.0, 0.0)
})
.reduce(|| (0.0, 0.0, 0.0), |a, b| (a.0 + b.0, a.1 + b.1, a.2 + b.2));
But I get the following error:
error[E0425]: cannot find value `wgz` in this scope
--> src/algorithm.rs:55:21
|
55 | wgz += wq * (rij.2 * rij1) * AC::H1;
| ^^^ not found in this scope
error: aborting due to 3 previous errors
For more information about this error, try `rustc --explain E0425`.
error: could not compile `a`.
And the same for all wgx/y/z
. Am a bit new to Rayon so I struggle a bit with what to change to fix it. It is a scoping problem
Kind regards