barrier/
barrier.rs

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 receiver_rank = 0;
10
11    if world.rank() == receiver_rank {
12        let n = (world.size() - 1) as usize;
13        let mut buf = vec![0u64; 2 * n];
14        for x in buf[0..n].iter_mut() {
15            world.any_process().receive_into(x);
16        }
17        world.barrier();
18        for x in buf[n..2 * n].iter_mut() {
19            world.any_process().receive_into(x);
20        }
21        println!("{:?}", buf);
22        assert!(buf[0..n].iter().all(|&x| x == 1));
23        assert!(buf[n..2 * n].iter().all(|&x| x == 2));
24    } else {
25        world.process_at_rank(0).send(&1u64);
26        world.barrier();
27        world.process_at_rank(0).send(&2u64);
28    }
29}