Skip to main content

mpi_global_bounding_box/
mpi_global_bounding_box.rs

1//! Test the computation of a global bounding box across MPI ranks.
2
3use bempp_octree::{
4    geometry::PhysicalBox,
5    octree::compute_global_bounding_box,
6    tools::{gather_to_root, generate_random_points},
7};
8use rand::prelude::*;
9use rand_chacha::ChaCha8Rng;
10
11pub fn main() {
12    // Initialise MPI
13    let universe = mpi::initialize().unwrap();
14
15    // Get the world communicator
16    let comm = universe.world();
17
18    // Initialise a seeded Rng.
19    let mut rng = ChaCha8Rng::seed_from_u64(2);
20
21    // Create `npoints` per rank.
22    let npoints = 10;
23
24    // Generate random points.
25
26    let points = generate_random_points(npoints, &mut rng, &comm);
27
28    // Compute the distributed bounding box.
29
30    let bounding_box = compute_global_bounding_box(&points, &comm);
31
32    // Copy all points to root and compare local bounding box there.
33
34    if let Some(points_root) = gather_to_root(&points, &comm) {
35        // Compute the bounding box on root.
36
37        let expected = PhysicalBox::from_points(&points_root);
38        assert_eq!(expected.coordinates(), bounding_box.coordinates());
39    }
40}