pub fn gather_to_root<T: Equivalence, C: CommunicatorCollectives>(
    arr: &[T],
    comm: &C,
) -> Option<Vec<T>>Expand description
Array to root Gather distributed array to the root rank.
The result is a Vec<T> on root and None on all other ranks.
Examples found in repository?
examples/mpi_global_bounding_box.rs (line 34)
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
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());
    }
}More examples
examples/mpi_cumsum.rs (line 37)
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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62
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(comm.rank() as u64);
    // Create `npoints` per rank.
    let nelems = 10;
    // Generate random numbers
    let mut elems = Vec::<usize>::with_capacity(nelems);
    for _ in 0..nelems {
        elems.push(rng.gen_range(0..100));
    }
    // Compute the cumulative sum.
    let global_cum_sum = global_inclusive_cumsum(&elems, &comm);
    // Copy array to root and compare with inclusive scan there.
    if let (Some(cum_sum_root), Some(original_array)) = (
        gather_to_root(&global_cum_sum, &comm),
        gather_to_root(&elems, &comm),
    ) {
        // Scan on root
        let expected_cum_sum = original_array
            .iter()
            .scan(0, |state, x| {
                *state += *x;
                Some(*state)
            })
            .collect_vec();
        // Check that the first element is not modified (inclusive cumsum)
        assert_eq!(
            original_array.first().unwrap(),
            cum_sum_root.first().unwrap()
        );
        for (actual, expected) in izip!(cum_sum_root.iter(), expected_cum_sum.iter()) {
            assert_eq!(*actual, *expected);
        }
        println!("Cumulative sum computed.");
    }
}