1#![deny(warnings)]
2extern crate mpi_fork_fnsp as mpi;
3
4use mpi::collective::SystemOperation;
5use mpi::topology::Rank;
6use mpi::traits::*;
7
8fn fac(n: Rank) -> Rank {
9 (1..=n).product()
10}
11
12fn main() {
13 let universe = mpi::initialize().unwrap();
14 let world = universe.world();
15 let rank = world.rank();
16
17 let mut x = 0;
18 world.scan_into(&rank, &mut x, &SystemOperation::sum());
19 assert_eq!(x, (rank * (rank + 1)) / 2);
20
21 let y = rank + 1;
22 let mut z = 0;
23 world.exclusive_scan_into(&y, &mut z, &SystemOperation::product());
24 if rank > 0 {
25 assert_eq!(z, fac(y - 1));
26 }
27}