Function send_receive

Source
pub fn send_receive<R, M, D, S>(
    msg: &M,
    destination: &D,
    source: &S,
) -> (R, Status)
Expand description

Sends msg to destination and simultaneously receives an instance of R from source.

§Examples

See examples/send_receive.rs

§Standard section(s)

3.10

Examples found in repository?
examples/send_receive.rs (line 19)
8fn main() {
9    let universe = mpi::initialize().unwrap();
10    let world = universe.world();
11    let size = world.size();
12    let rank = world.rank();
13
14    let next_rank = if rank + 1 < size { rank + 1 } else { 0 };
15    let next_process = world.process_at_rank(next_rank);
16    let previous_rank = if rank > 0 { rank - 1 } else { size - 1 };
17    let previous_process = world.process_at_rank(previous_rank);
18
19    let (msg, status): (Rank, _) = p2p::send_receive(&rank, &previous_process, &next_process);
20    println!(
21        "Process {} got message {}.\nStatus is: {:?}",
22        rank, msg, status
23    );
24    world.barrier();
25    assert_eq!(msg, next_rank);
26
27    if rank > 0 {
28        let msg = vec![rank, rank + 1, rank - 1];
29        world.process_at_rank(0).send(&msg[..]);
30    } else {
31        for _ in 1..size {
32            let (msg, status) = world.any_process().receive_vec::<Rank>();
33            println!(
34                "Process {} got long message {:?}.\nStatus is: {:?}",
35                rank, msg, status
36            );
37
38            let x = status.source_rank();
39            let v = vec![x, x + 1, x - 1];
40            assert_eq!(v, msg);
41        }
42    }
43    world.barrier();
44
45    let mut x = rank;
46    p2p::send_receive_replace_into(&mut x, &next_process, &previous_process);
47    assert_eq!(x, previous_rank);
48}