1#![deny(warnings)]
2extern crate mpi_fork_fnsp as mpi;
3
4use mpi::traits::*;
5
6fn main() {
7 let universe = mpi::initialize().unwrap();
8 let world = universe.world();
9 let root_rank = 0;
10 let root_process = world.process_at_rank(root_rank);
11
12 let mut x;
13 if world.rank() == root_rank {
14 x = 2_u64.pow(10);
15 println!("Root broadcasting value: {}.", x);
16 } else {
17 x = 0_u64;
18 }
19 root_process.broadcast_into(&mut x);
20 println!("Rank {} received value: {}.", world.rank(), x);
21 assert_eq!(x, 1024);
22 println!();
23
24 let mut a;
25 let n = 4;
26 if world.rank() == root_rank {
27 a = (1..).map(|i| 2_u64.pow(i)).take(n).collect::<Vec<_>>();
28 println!("Root broadcasting value: {:?}.", &a[..]);
29 } else {
30 a = std::iter::repeat(0_u64).take(n).collect::<Vec<_>>();
31 }
32 root_process.broadcast_into(&mut a[..]);
33 println!("Rank {} received value: {:?}.", world.rank(), &a[..]);
34 assert_eq!(&a[..], &[2, 4, 8, 16]);
35}