Struct Color

Source
pub struct Color(/* private fields */);
Expand description

A color used in a communicator split

Implementations§

Source§

impl Color

Source

pub fn undefined() -> Color

Special color of undefined value

Examples found in repository?
examples/split.rs (line 75)
6fn main() {
7    let universe = mpi::initialize().unwrap();
8    let world = universe.world();
9
10    let odd = (0..world.size()).filter(|x| x % 2 != 0).collect::<Vec<_>>();
11    let odd_group = world.group().include(&odd[..]);
12    let even_group = world.group().difference(&odd_group);
13    assert!(
14        (world.rank() % 2 == 0 && even_group.rank().is_some() && odd_group.rank().is_none())
15            || (even_group.rank().is_none() && odd_group.rank().is_some())
16    );
17    let my_group = if odd_group.rank().is_some() {
18        &odd_group
19    } else {
20        &even_group
21    };
22    let empty_group = SystemGroup::empty();
23
24    let oddness_comm = world.split_by_subgroup_collective(my_group);
25    assert!(oddness_comm.is_some());
26    let oddness_comm = oddness_comm.unwrap();
27    assert_eq!(
28        GroupRelation::Identical,
29        oddness_comm.group().compare(my_group)
30    );
31
32    let odd_comm = if odd_group.rank().is_some() {
33        world.split_by_subgroup_collective(&odd_group)
34    } else {
35        world.split_by_subgroup_collective(&empty_group)
36    };
37    if odd_group.rank().is_some() {
38        assert!(odd_comm.is_some());
39        let odd_comm = odd_comm.unwrap();
40        assert_eq!(
41            GroupRelation::Identical,
42            odd_comm.group().compare(&odd_group)
43        );
44    } else {
45        assert!(odd_comm.is_none());
46    }
47
48    #[cfg(not(msmpi))]
49    {
50        if even_group.rank().is_some() {
51            let even_comm = world.split_by_subgroup(&even_group);
52            assert!(even_comm.is_some());
53            let even_comm = even_comm.unwrap();
54            assert_eq!(
55                GroupRelation::Identical,
56                even_comm.group().compare(&even_group)
57            );
58
59            let no_comm = world.split_by_subgroup(&odd_group);
60            assert!(no_comm.is_none());
61        }
62    }
63
64    let oddness_comm = world.split_by_color(Color::with_value(world.rank() % 2));
65    assert!(oddness_comm.is_some());
66    let oddness_comm = oddness_comm.unwrap();
67    assert_eq!(
68        GroupRelation::Identical,
69        oddness_comm.group().compare(my_group)
70    );
71
72    let odd_comm = world.split_by_color(if world.rank() % 2 != 0 {
73        Color::with_value(0)
74    } else {
75        Color::undefined()
76    });
77    if world.rank() % 2 != 0 {
78        assert!(odd_comm.is_some());
79        let odd_comm = odd_comm.unwrap();
80        assert_eq!(
81            GroupRelation::Identical,
82            odd_comm.group().compare(&odd_group)
83        );
84    } else {
85        assert!(odd_comm.is_none());
86    }
87}
Source

pub fn with_value(value: c_int) -> Color

A color of a certain value

Valid values are non-negative.

Examples found in repository?
examples/split.rs (line 64)
6fn main() {
7    let universe = mpi::initialize().unwrap();
8    let world = universe.world();
9
10    let odd = (0..world.size()).filter(|x| x % 2 != 0).collect::<Vec<_>>();
11    let odd_group = world.group().include(&odd[..]);
12    let even_group = world.group().difference(&odd_group);
13    assert!(
14        (world.rank() % 2 == 0 && even_group.rank().is_some() && odd_group.rank().is_none())
15            || (even_group.rank().is_none() && odd_group.rank().is_some())
16    );
17    let my_group = if odd_group.rank().is_some() {
18        &odd_group
19    } else {
20        &even_group
21    };
22    let empty_group = SystemGroup::empty();
23
24    let oddness_comm = world.split_by_subgroup_collective(my_group);
25    assert!(oddness_comm.is_some());
26    let oddness_comm = oddness_comm.unwrap();
27    assert_eq!(
28        GroupRelation::Identical,
29        oddness_comm.group().compare(my_group)
30    );
31
32    let odd_comm = if odd_group.rank().is_some() {
33        world.split_by_subgroup_collective(&odd_group)
34    } else {
35        world.split_by_subgroup_collective(&empty_group)
36    };
37    if odd_group.rank().is_some() {
38        assert!(odd_comm.is_some());
39        let odd_comm = odd_comm.unwrap();
40        assert_eq!(
41            GroupRelation::Identical,
42            odd_comm.group().compare(&odd_group)
43        );
44    } else {
45        assert!(odd_comm.is_none());
46    }
47
48    #[cfg(not(msmpi))]
49    {
50        if even_group.rank().is_some() {
51            let even_comm = world.split_by_subgroup(&even_group);
52            assert!(even_comm.is_some());
53            let even_comm = even_comm.unwrap();
54            assert_eq!(
55                GroupRelation::Identical,
56                even_comm.group().compare(&even_group)
57            );
58
59            let no_comm = world.split_by_subgroup(&odd_group);
60            assert!(no_comm.is_none());
61        }
62    }
63
64    let oddness_comm = world.split_by_color(Color::with_value(world.rank() % 2));
65    assert!(oddness_comm.is_some());
66    let oddness_comm = oddness_comm.unwrap();
67    assert_eq!(
68        GroupRelation::Identical,
69        oddness_comm.group().compare(my_group)
70    );
71
72    let odd_comm = world.split_by_color(if world.rank() % 2 != 0 {
73        Color::with_value(0)
74    } else {
75        Color::undefined()
76    });
77    if world.rank() % 2 != 0 {
78        assert!(odd_comm.is_some());
79        let odd_comm = odd_comm.unwrap();
80        assert_eq!(
81            GroupRelation::Identical,
82            odd_comm.group().compare(&odd_group)
83        );
84    } else {
85        assert!(odd_comm.is_none());
86    }
87}

Trait Implementations§

Source§

impl Clone for Color

Source§

fn clone(&self) -> Color

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for Color

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Copy for Color

Auto Trait Implementations§

§

impl Freeze for Color

§

impl RefUnwindSafe for Color

§

impl Send for Color

§

impl Sync for Color

§

impl Unpin for Color

§

impl UnwindSafe for Color

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<Src, Scheme> ApproxFrom<Src, Scheme> for Src
where Scheme: ApproxScheme,

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>

Convert the given value into an approximately equivalent representation.
Source§

impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Src
where Dst: ApproxFrom<Src, Scheme>, Scheme: ApproxScheme,

Source§

type Err = <Dst as ApproxFrom<Src, Scheme>>::Err

The error type produced by a failed conversion.
Source§

fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>

Convert the subject into an approximately equivalent representation.
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T, Dst> ConvAsUtil<Dst> for T

Source§

fn approx(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject with the default scheme.
Source§

fn approx_by<Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject with a specific scheme.
Source§

impl<T> ConvUtil for T

Source§

fn approx_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst>,

Approximate the subject to a given type with the default scheme.
Source§

fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
where Self: Sized + ApproxInto<Dst, Scheme>, Scheme: ApproxScheme,

Approximate the subject to a given type with a specific scheme.
Source§

fn into_as<Dst>(self) -> Dst
where Self: Sized + Into<Dst>,

Convert the subject to a given type.
Source§

fn try_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + TryInto<Dst>,

Attempt to convert the subject to a given type.
Source§

fn value_as<Dst>(self) -> Result<Dst, Self::Err>
where Self: Sized + ValueInto<Dst>,

Attempt a value conversion of the subject to a given type.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<Src> TryFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn try_from(src: Src) -> Result<Src, <Src as TryFrom<Src>>::Err>

Convert the given value into the subject type.
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<Src, Dst> TryInto<Dst> for Src
where Dst: TryFrom<Src>,

Source§

type Err = <Dst as TryFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn try_into(self) -> Result<Dst, <Src as TryInto<Dst>>::Err>

Convert the subject into the destination type.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<Src> ValueFrom<Src> for Src

Source§

type Err = NoError

The error type produced by a failed conversion.
Source§

fn value_from(src: Src) -> Result<Src, <Src as ValueFrom<Src>>::Err>

Convert the given value into an exactly equivalent representation.
Source§

impl<Src, Dst> ValueInto<Dst> for Src
where Dst: ValueFrom<Src>,

Source§

type Err = <Dst as ValueFrom<Src>>::Err

The error type produced by a failed conversion.
Source§

fn value_into(self) -> Result<Dst, <Src as ValueInto<Dst>>::Err>

Convert the subject into an exactly equivalent representation.