Skip to main content

abort/
abort.rs

1//! Demonstrates that `MPI_Abort` (and panics) tear the whole job down instead
2//! of leaving peers blocked. Rank 1 waits forever in a receive; rank 0 aborts.
3//! Every rank should exit promptly (non-zero), never hang.
4
5use mpi::traits::*;
6
7fn main() {
8    let universe = mpi::initialize().unwrap();
9    let world = universe.world();
10
11    if world.rank() == 1 {
12        // Would block forever — but the abort from rank 0 unblocks us by
13        // terminating the process.
14        let _ = world.process_at_rank(0).receive::<i32>();
15        eprintln!("rank 1 should never reach here");
16    } else if world.rank() == 0 {
17        eprintln!("rank 0 calling abort");
18        world.abort(7);
19    }
20}