pub struct View<'d, 'b, D, B>{ /* private fields */ }Expand description
A buffer with a user specified count and datatype
§Safety
Views can be used to instruct the underlying MPI library to rummage around at arbitrary
locations in memory. This might be controlled later on using datatype bounds an slice lengths
but for now, all View constructors are marked unsafe.
Implementations§
Source§impl<'d, 'b, D, B> View<'d, 'b, D, B>
impl<'d, 'b, D, B> View<'d, 'b, D, B>
Sourcepub unsafe fn with_count_and_datatype(
buffer: &'b B,
count: Count,
datatype: &'d D,
) -> View<'d, 'b, D, B>
pub unsafe fn with_count_and_datatype( buffer: &'b B, count: Count, datatype: &'d D, ) -> View<'d, 'b, D, B>
Return a view of buffer containing count instances of MPI datatype datatype.
§Examples
See examples/contiguous.rs, examples/vector.rs
§Safety
datatypemust map an element ofbufferwithout exposing any padding bytes or exceeding the bounds of the object.
Examples found in repository?
examples/contiguous.rs (line 28)
9fn main() {
10 let universe = mpi::initialize().unwrap();
11 let world = universe.world();
12 let rank = world.rank();
13 let size = world.size();
14
15 let next_rank = if rank + 1 < size { rank + 1 } else { 0 };
16 let next_process = world.process_at_rank(next_rank);
17 let previous_rank = if rank > 0 { rank - 1 } else { size - 1 };
18 let previous_process = world.process_at_rank(previous_rank);
19
20 let b1 = (1..).map(|x| rank * x).take(3).collect::<Vec<_>>();
21 let mut b2 = std::iter::repeat(-1).take(3).collect::<Vec<_>>();
22 println!("Rank {} sending message: {:?}.", rank, b1);
23 world.barrier();
24
25 let t = UserDatatype::contiguous(3, &Rank::equivalent_datatype());
26 let status;
27 {
28 let v1 = unsafe { View::with_count_and_datatype(&b1[..], 1, &t) };
29 let mut v2 = unsafe { MutView::with_count_and_datatype(&mut b2[..], 1, &t) };
30 status = p2p::send_receive_into(&v1, &next_process, &mut v2, &previous_process);
31 }
32
33 println!(
34 "Rank {} received message: {:?}, status: {:?}.",
35 rank, b2, status
36 );
37 world.barrier();
38
39 let b3 = (1..).map(|x| previous_rank * x).take(3).collect::<Vec<_>>();
40 assert_eq!(b3, b2);
41}More examples
examples/vector.rs (line 28)
9fn main() {
10 let universe = mpi::initialize().unwrap();
11 let world = universe.world();
12 let rank = world.rank();
13 let size = world.size();
14
15 let next_rank = if rank + 1 < size { rank + 1 } else { 0 };
16 let next_process = world.process_at_rank(next_rank);
17 let previous_rank = if rank > 0 { rank - 1 } else { size - 1 };
18 let previous_process = world.process_at_rank(previous_rank);
19
20 let b1 = (1..).map(|x| rank * x).take(6).collect::<Vec<_>>();
21 let mut b2 = std::iter::repeat(-1).take(6).collect::<Vec<_>>();
22 println!("Rank {} sending message: {:?}.", rank, b1);
23 world.barrier();
24
25 let t = UserDatatype::vector(2, 2, 3, &Rank::equivalent_datatype());
26 let status;
27 {
28 let v1 = unsafe { View::with_count_and_datatype(&b1[..], 1, &t) };
29 let mut v2 = unsafe { MutView::with_count_and_datatype(&mut b2[..], 1, &t) };
30 status = p2p::send_receive_into(&v1, &next_process, &mut v2, &previous_process);
31 }
32
33 println!(
34 "Rank {} received message: {:?}, status: {:?}.",
35 rank, b2, status
36 );
37 world.barrier();
38
39 let b3 = (1..)
40 .map(|x| if x % 3 == 0 { -1 } else { previous_rank * x })
41 .take(6)
42 .collect::<Vec<_>>();
43 assert_eq!(b3, b2);
44}examples/all_gather.rs (line 50)
8fn main() {
9 let universe = mpi::initialize().unwrap();
10 let world = universe.world();
11 let root_rank = 0;
12
13 let count = world.size() as usize;
14 let i = 2_u64.pow(world.rank() as u32 + 1);
15 let mut a = vec![0u64; count];
16
17 world.all_gather_into(&i, &mut a[..]);
18
19 if world.rank() == root_rank {
20 println!("Root gathered sequence: {:?}.", a);
21 }
22 assert!(a
23 .iter()
24 .enumerate()
25 .all(|(a, &b)| b == 2u64.pow(a as u32 + 1)));
26
27 let factor = world.rank() as u64 + 1;
28 let a = (1_u64..)
29 .take(count)
30 .map(|x| x * factor)
31 .collect::<Vec<_>>();
32 let mut t = vec![0u64; count * count];
33
34 world.all_gather_into(&a[..], &mut t[..]);
35
36 if world.rank() == root_rank {
37 println!("Root gathered table:");
38 for r in t.chunks(count) {
39 println!("{:?}", r);
40 }
41 }
42 assert!((0_u64..)
43 .zip(t.iter())
44 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
45
46 let d = UserDatatype::contiguous(count as Count, &u64::equivalent_datatype());
47 t = vec![0u64; count * count];
48
49 {
50 let sv = unsafe { View::with_count_and_datatype(&a[..], 1, &d) };
51 let mut rv = unsafe { MutView::with_count_and_datatype(&mut t[..], count as Count, &d) };
52
53 world.all_gather_into(&sv, &mut rv);
54 }
55
56 if world.rank() == root_rank {
57 println!("Root gathered table:");
58 for r in t.chunks(count) {
59 println!("{:?}", r);
60 }
61 }
62 assert!((0_u64..)
63 .zip(t.iter())
64 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
65}examples/immediate_all_gather.rs (line 58)
8fn main() {
9 let universe = mpi::initialize().unwrap();
10 let world = universe.world();
11 let root_rank = 0;
12
13 let count = world.size() as usize;
14 let i = 2_u64.pow(world.rank() as u32 + 1);
15 let mut a = vec![0u64; count];
16
17 mpi::request::scope(|scope| {
18 world
19 .immediate_all_gather_into(scope, &i, &mut a[..])
20 .wait();
21 });
22
23 if world.rank() == root_rank {
24 println!("Root gathered sequence: {:?}.", a);
25 }
26 assert!(a
27 .iter()
28 .enumerate()
29 .all(|(a, &b)| b == 2u64.pow(a as u32 + 1)));
30
31 let factor = world.rank() as u64 + 1;
32 let a = (1_u64..)
33 .take(count)
34 .map(|x| x * factor)
35 .collect::<Vec<_>>();
36 let mut t = vec![0u64; count * count];
37
38 mpi::request::scope(|scope| {
39 world
40 .immediate_all_gather_into(scope, &a[..], &mut t[..])
41 .wait();
42 });
43
44 if world.rank() == root_rank {
45 println!("Root gathered table:");
46 for r in t.chunks(count) {
47 println!("{:?}", r);
48 }
49 }
50 assert!((0_u64..)
51 .zip(t.iter())
52 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
53
54 let d = UserDatatype::contiguous(count as Count, &u64::equivalent_datatype());
55 t = vec![0u64; count * count];
56
57 {
58 let sv = unsafe { View::with_count_and_datatype(&a[..], 1, &d) };
59 let mut rv = unsafe { MutView::with_count_and_datatype(&mut t[..], count as Count, &d) };
60 mpi::request::scope(|scope| {
61 world.immediate_all_gather_into(scope, &sv, &mut rv).wait();
62 });
63 }
64
65 if world.rank() == root_rank {
66 println!("Root gathered table:");
67 for r in t.chunks(count) {
68 println!("{:?}", r);
69 }
70 }
71 assert!((0_u64..)
72 .zip(t.iter())
73 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
74}examples/gather.rs (line 50)
8fn main() {
9 let universe = mpi::initialize().unwrap();
10 let world = universe.world();
11 let root_rank = 0;
12 let root_process = world.process_at_rank(root_rank);
13
14 let count = world.size() as usize;
15 let i = 2_u64.pow(world.rank() as u32 + 1);
16
17 if world.rank() == root_rank {
18 let mut a = vec![0u64; count];
19 root_process.gather_into_root(&i, &mut a[..]);
20 println!("Root gathered sequence: {:?}.", a);
21 assert!(a
22 .iter()
23 .enumerate()
24 .all(|(a, &b)| b == 2u64.pow(a as u32 + 1)));
25 } else {
26 root_process.gather_into(&i);
27 }
28
29 let factor = world.rank() as u64 + 1;
30 let a = (1_u64..)
31 .take(count)
32 .map(|x| x * factor)
33 .collect::<Vec<_>>();
34
35 if world.rank() == root_rank {
36 let mut t = vec![0u64; count * count];
37 root_process.gather_into_root(&a[..], &mut t[..]);
38 println!("Root gathered table:");
39 for r in t.chunks(count) {
40 println!("{:?}", r);
41 }
42 assert!((0_u64..)
43 .zip(t.iter())
44 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
45 } else {
46 root_process.gather_into(&a[..]);
47 }
48
49 let d = UserDatatype::contiguous(count as Count, &u64::equivalent_datatype());
50 let sv = unsafe { View::with_count_and_datatype(&a[..], 1, &d) };
51
52 if world.rank() == root_rank {
53 let mut t = vec![0u64; count * count];
54
55 {
56 let mut rv =
57 unsafe { MutView::with_count_and_datatype(&mut t[..], count as Count, &d) };
58 root_process.gather_into_root(&sv, &mut rv);
59 }
60
61 println!("Root gathered table:");
62 for r in t.chunks(count) {
63 println!("{:?}", r);
64 }
65 assert!((0_u64..)
66 .zip(t.iter())
67 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
68 } else {
69 root_process.gather_into(&sv);
70 }
71}examples/immediate_gather.rs (line 62)
8fn main() {
9 let universe = mpi::initialize().unwrap();
10 let world = universe.world();
11 let root_rank = 0;
12 let root_process = world.process_at_rank(root_rank);
13
14 let count = world.size() as usize;
15 let i = 2_u64.pow(world.rank() as u32 + 1);
16
17 if world.rank() == root_rank {
18 let mut a = vec![0u64; count];
19 mpi::request::scope(|scope| {
20 root_process
21 .immediate_gather_into_root(scope, &i, &mut a[..])
22 .wait();
23 });
24 println!("Root gathered sequence: {:?}.", a);
25 assert!(a
26 .iter()
27 .enumerate()
28 .all(|(a, &b)| b == 2u64.pow(a as u32 + 1)));
29 } else {
30 mpi::request::scope(|scope| {
31 root_process.immediate_gather_into(scope, &i).wait();
32 });
33 }
34
35 let factor = world.rank() as u64 + 1;
36 let a = (1_u64..)
37 .take(count)
38 .map(|x| x * factor)
39 .collect::<Vec<_>>();
40
41 if world.rank() == root_rank {
42 let mut t = vec![0u64; count * count];
43 mpi::request::scope(|scope| {
44 root_process
45 .immediate_gather_into_root(scope, &a[..], &mut t[..])
46 .wait();
47 });
48 println!("Root gathered table:");
49 for r in t.chunks(count) {
50 println!("{:?}", r);
51 }
52 assert!((0_u64..)
53 .zip(t.iter())
54 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
55 } else {
56 mpi::request::scope(|scope| {
57 root_process.immediate_gather_into(scope, &a[..]).wait();
58 });
59 }
60
61 let d = UserDatatype::contiguous(count as Count, &u64::equivalent_datatype());
62 let sv = unsafe { View::with_count_and_datatype(&a[..], 1, &d) };
63
64 if world.rank() == root_rank {
65 let mut t = vec![0u64; count * count];
66
67 {
68 let mut rv =
69 unsafe { MutView::with_count_and_datatype(&mut t[..], count as Count, &d) };
70 mpi::request::scope(|scope| {
71 root_process
72 .immediate_gather_into_root(scope, &sv, &mut rv)
73 .wait();
74 });
75 }
76
77 println!("Root gathered table:");
78 for r in t.chunks(count) {
79 println!("{:?}", r);
80 }
81 assert!((0_u64..)
82 .zip(t.iter())
83 .all(|(a, &b)| b == (a / count as u64 + 1) * (a % count as u64 + 1)));
84 } else {
85 mpi::request::scope(|scope| {
86 root_process.immediate_gather_into(scope, &sv).wait();
87 });
88 }
89}Trait Implementations§
Source§impl<'d, 'b, D, B> AsDatatype for View<'d, 'b, D, B>
impl<'d, 'b, D, B> AsDatatype for View<'d, 'b, D, B>
Source§impl<'d, 'b, D, B> Collection for View<'d, 'b, D, B>
impl<'d, 'b, D, B> Collection for View<'d, 'b, D, B>
impl<'d, 'b, D, B> Buffer for View<'d, 'b, D, B>
Auto Trait Implementations§
impl<'d, 'b, D, B> Freeze for View<'d, 'b, D, B>where
B: ?Sized,
impl<'d, 'b, D, B> RefUnwindSafe for View<'d, 'b, D, B>
impl<'d, 'b, D, B> Send for View<'d, 'b, D, B>
impl<'d, 'b, D, B> Sync for View<'d, 'b, D, B>
impl<'d, 'b, D, B> Unpin for View<'d, 'b, D, B>where
B: ?Sized,
impl<'d, 'b, D, B> UnwindSafe for View<'d, 'b, D, B>
Blanket Implementations§
Source§impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
impl<Src, Scheme> ApproxFrom<Src, Scheme> for Srcwhere
Scheme: ApproxScheme,
Source§fn approx_from(src: Src) -> Result<Src, <Src as ApproxFrom<Src, Scheme>>::Err>
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 Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
impl<Dst, Src, Scheme> ApproxInto<Dst, Scheme> for Srcwhere
Dst: ApproxFrom<Src, Scheme>,
Scheme: ApproxScheme,
Source§type Err = <Dst as ApproxFrom<Src, Scheme>>::Err
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>
fn approx_into(self) -> Result<Dst, <Src as ApproxInto<Dst, Scheme>>::Err>
Convert the subject into an approximately equivalent representation.
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T, Dst> ConvAsUtil<Dst> for T
impl<T, Dst> ConvAsUtil<Dst> for T
Source§impl<T> ConvUtil for T
impl<T> ConvUtil for T
Source§fn approx_as<Dst>(self) -> Result<Dst, Self::Err>where
Self: Sized + ApproxInto<Dst>,
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>
fn approx_as_by<Dst, Scheme>(self) -> Result<Dst, Self::Err>
Approximate the subject to a given type with a specific scheme.