broadcast_complex/
broadcast_complex.rs

1extern crate mpi_fork_fnsp as mpi;
2use mpi::traits::*;
3use num_complex::Complex;
4
5fn main() {
6    let universe = mpi::initialize().unwrap();
7    let world = universe.world();
8
9    let root_process = world.process_at_rank(0);
10
11    let mut data = if world.rank() == 0 {
12        [
13            Complex::<f64>::new(1., -2.),
14            Complex::<f64>::new(8., -4.),
15            Complex::<f64>::new(3., -9.),
16            Complex::<f64>::new(7., -5.),
17        ]
18    } else {
19        [Complex::<f64>::new(0., 0.); 4]
20    };
21
22    // root_process.broadcast_into(&mut data);
23    root_process.broadcast_into(&mut data[..]);
24
25    assert_eq!(
26        data,
27        [
28            Complex::<f64>::new(1., -2.),
29            Complex::<f64>::new(8., -4.),
30            Complex::<f64>::new(3., -9.),
31            Complex::<f64>::new(7., -5.),
32        ]
33    );
34}