mpi_global_bounding_box/
mpi_global_bounding_box.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
//! Test the computation of a global bounding box across MPI ranks.

use bempp_octree::{
    geometry::PhysicalBox,
    octree::compute_global_bounding_box,
    tools::{gather_to_root, generate_random_points},
};
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;

pub fn main() {
    // Initialise MPI
    let universe = mpi::initialize().unwrap();

    // Get the world communicator
    let comm = universe.world();

    // Initialise a seeded Rng.
    let mut rng = ChaCha8Rng::seed_from_u64(2);

    // Create `npoints` per rank.
    let npoints = 10;

    // Generate random points.

    let points = generate_random_points(npoints, &mut rng, &comm);

    // Compute the distributed bounding box.

    let bounding_box = compute_global_bounding_box(&points, &comm);

    // Copy all points to root and compare local bounding box there.

    if let Some(points_root) = gather_to_root(&points, &comm) {
        // Compute the bounding box on root.

        let expected = PhysicalBox::from_points(&points_root);
        assert_eq!(expected.coordinates(), bounding_box.coordinates());
    }
}