group/
group.rs

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    // Group accessors and Communicator accessors agree
14    assert_eq!(world.size(), g.size());
15    assert_eq!(world.rank(), g.rank().unwrap());
16
17    // g == g
18    assert_eq!(GroupRelation::Identical, g.compare(&g));
19
20    let h = world.group();
21    // h == g
22    assert_eq!(GroupRelation::Identical, g.compare(&h));
23
24    let i = g.union(&h);
25    // g union h == g union g == g
26    assert_eq!(GroupRelation::Identical, g.compare(&i));
27
28    let empty = g.difference(&h);
29    // g difference h == g difference g = empty Group
30    assert_eq!(
31        GroupRelation::Identical,
32        SystemGroup::empty().compare(&empty)
33    );
34    assert_eq!(0, empty.size());
35
36    // g intersection empty == empty Group
37    assert_eq!(0, g.intersection(&empty).size());
38
39    let first_half: Vec<Rank> = (0..g.size() / 2).collect();
40
41    // f and s are first and second half of g
42    let f = g.include(&first_half[..]);
43    let s = g.exclude(&first_half[..]);
44    // f != s
45    assert_eq!(GroupRelation::Unequal, f.compare(&s));
46
47    // g intersection f == f
48    let f_ = g.intersection(&f);
49    assert_eq!(GroupRelation::Identical, f.compare(&f_));
50    // g intersection s == s
51    let s_ = g.intersection(&s);
52    assert_eq!(GroupRelation::Identical, s.compare(&s_));
53
54    // g difference s == f
55    let f__ = g.difference(&s);
56    assert_eq!(GroupRelation::Identical, f.compare(&f__));
57    // g difference f == s
58    let s__ = g.difference(&f);
59    assert_eq!(GroupRelation::Identical, s.compare(&s__));
60
61    // f union s == g
62    let fs = f.union(&s);
63    assert_eq!(GroupRelation::Identical, g.compare(&fs));
64
65    // f intersection s == empty Group
66    let fs = f.intersection(&s);
67    assert_eq!(GroupRelation::Identical, empty.compare(&fs));
68
69    // rank is either in f or in s
70    assert!(
71        (f.rank().is_some() && s.rank().is_none()) ^ (f.rank().is_none() && s.rank().is_some())
72    );
73
74    // inverting rank mappings
75    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}