1#![deny(warnings)]
2#![allow(clippy::many_single_char_names)]
3extern crate mpi_fork_fnsp as mpi;
4
5use mpi::topology::{GroupRelation, Rank, SystemGroup};
6use mpi::traits::*;
7
8fn main() {
9 let universe = mpi::initialize().unwrap();
10 let world = universe.world();
11
12 let g = world.group();
13 assert_eq!(world.size(), g.size());
15 assert_eq!(world.rank(), g.rank().unwrap());
16
17 assert_eq!(GroupRelation::Identical, g.compare(&g));
19
20 let h = world.group();
21 assert_eq!(GroupRelation::Identical, g.compare(&h));
23
24 let i = g.union(&h);
25 assert_eq!(GroupRelation::Identical, g.compare(&i));
27
28 let empty = g.difference(&h);
29 assert_eq!(
31 GroupRelation::Identical,
32 SystemGroup::empty().compare(&empty)
33 );
34 assert_eq!(0, empty.size());
35
36 assert_eq!(0, g.intersection(&empty).size());
38
39 let first_half: Vec<Rank> = (0..g.size() / 2).collect();
40
41 let f = g.include(&first_half[..]);
43 let s = g.exclude(&first_half[..]);
44 assert_eq!(GroupRelation::Unequal, f.compare(&s));
46
47 let f_ = g.intersection(&f);
49 assert_eq!(GroupRelation::Identical, f.compare(&f_));
50 let s_ = g.intersection(&s);
52 assert_eq!(GroupRelation::Identical, s.compare(&s_));
53
54 let f__ = g.difference(&s);
56 assert_eq!(GroupRelation::Identical, f.compare(&f__));
57 let s__ = g.difference(&f);
59 assert_eq!(GroupRelation::Identical, s.compare(&s__));
60
61 let fs = f.union(&s);
63 assert_eq!(GroupRelation::Identical, g.compare(&fs));
64
65 let fs = f.intersection(&s);
67 assert_eq!(GroupRelation::Identical, empty.compare(&fs));
68
69 assert!(
71 (f.rank().is_some() && s.rank().is_none()) ^ (f.rank().is_none() && s.rank().is_some())
72 );
73
74 let rev: Vec<Rank> = (0..g.size()).rev().collect();
76 let r = g.include(&rev[..]);
77 assert_eq!(
78 Some(rev[g.rank().unwrap() as usize]),
79 r.translate_rank(g.rank().unwrap(), &g)
80 );
81}