more stuff
This commit is contained in:
@ -9,7 +9,7 @@ fn main() {
|
||||
let size = world.size();
|
||||
let rank = world.rank();
|
||||
|
||||
let support_points = 20;
|
||||
let support_points = 100;
|
||||
let a = 0.0;
|
||||
let b = 1.0;
|
||||
let N = (b - a) / size as f64;
|
||||
@ -17,6 +17,7 @@ fn main() {
|
||||
let f = |x: f64| 1.0 / (1.0 + x.powi(2)) as f64; // function
|
||||
let n = (support_points / size) as u32; // fewer ranks should also use an appropriate amount of support points; the support points are distributed among the ranks
|
||||
let partial_integral = trapezoidal_rule(f, a + rank as f64 * N, a + (rank + 1) as f64 * N, n);
|
||||
println!("Rank {}: Partial integral is {} on [{},{}]", rank, partial_integral, (a + rank as f64 * N), (a + (rank + 1) as f64 * N));
|
||||
|
||||
world.barrier();
|
||||
|
||||
@ -26,7 +27,7 @@ fn main() {
|
||||
|
||||
if rank == 0 {
|
||||
println!("The approximated integral is {}", integral);
|
||||
println!("The error is {}", (integral - (PI / 4.0)).abs());
|
||||
println!("The error is |{:.7} - {:.7}| = {}", (PI / 4.0), integral, (integral - (PI / 4.0)).abs());
|
||||
}
|
||||
}
|
||||
|
||||
@ -72,4 +73,4 @@ mod tests {
|
||||
|
||||
assert!((expected - actual).abs() < tolerance, "Integral is {} but should be {}", actual, expected);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user