immediate_scan/
immediate_scan.rs

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    mpi::request::scope(|scope| {
19        world
20            .immediate_scan_into(scope, &rank, &mut x, SystemOperation::sum())
21            .wait();
22    });
23    assert_eq!(x, (rank * (rank + 1)) / 2);
24
25    let y = rank + 1;
26    let mut z = 0;
27    mpi::request::scope(|scope| {
28        world
29            .immediate_exclusive_scan_into(scope, &y, &mut z, SystemOperation::product())
30            .wait();
31    });
32    if rank > 0 {
33        assert_eq!(z, fac(y - 1));
34    }
35}