Skip to main content

File

Struct File 

Source
pub struct File { /* private fields */ }
Expand description

A file opened collectively by a communicator (MPI_File).

Implementations§

Source§

impl File

Source

pub fn open<C: Communicator>( comm: &C, path: impl AsRef<Path>, mode: u32, ) -> Result<File>

Collectively open path with the given mode flags (MPI_File_open).

Examples found in repository?
examples/parallel_io.rs (lines 16-20)
7fn main() {
8    let universe = mpi::initialize().unwrap();
9    let world = universe.world();
10    let rank = world.rank();
11    let size = world.size();
12
13    // Path depends on world size so concurrent jobs of different sizes don't
14    // collide; identical across the ranks of a single job.
15    let path = std::env::temp_dir().join(format!("mpi_no_c_io_{size}.bin"));
16    let mut f = File::open(
17        &world,
18        &path,
19        MODE_CREATE | MODE_RDWR | MODE_DELETE_ON_CLOSE,
20    )
21    .expect("File::open failed");
22
23    let block = [rank * 100, rank * 100 + 1, rank * 100 + 2, rank * 100 + 3];
24    f.write_at_all(rank as u64 * 16, &block)
25        .expect("write failed");
26
27    if rank == 0 {
28        for r in 0..size {
29            let mut buf = [0i32; 4];
30            f.read_at(r as u64 * 16, &mut buf).expect("read failed");
31            assert_eq!(
32                buf,
33                [r * 100, r * 100 + 1, r * 100 + 2, r * 100 + 3],
34                "I/O block mismatch"
35            );
36        }
37        println!("IO PASS: parallel write/read verified on {size} ranks.");
38    }
39
40    world.barrier();
41    // File is deleted on close (drop).
42}
Source

pub fn write_at<T: Equivalence>( &mut self, offset: u64, data: &[T], ) -> Result<()>

Write data at byte offset (MPI_File_write_at).

Source

pub fn read_at<T: Equivalence>( &mut self, offset: u64, buf: &mut [T], ) -> Result<()>

Read into buf from byte offset (MPI_File_read_at).

Examples found in repository?
examples/parallel_io.rs (line 30)
7fn main() {
8    let universe = mpi::initialize().unwrap();
9    let world = universe.world();
10    let rank = world.rank();
11    let size = world.size();
12
13    // Path depends on world size so concurrent jobs of different sizes don't
14    // collide; identical across the ranks of a single job.
15    let path = std::env::temp_dir().join(format!("mpi_no_c_io_{size}.bin"));
16    let mut f = File::open(
17        &world,
18        &path,
19        MODE_CREATE | MODE_RDWR | MODE_DELETE_ON_CLOSE,
20    )
21    .expect("File::open failed");
22
23    let block = [rank * 100, rank * 100 + 1, rank * 100 + 2, rank * 100 + 3];
24    f.write_at_all(rank as u64 * 16, &block)
25        .expect("write failed");
26
27    if rank == 0 {
28        for r in 0..size {
29            let mut buf = [0i32; 4];
30            f.read_at(r as u64 * 16, &mut buf).expect("read failed");
31            assert_eq!(
32                buf,
33                [r * 100, r * 100 + 1, r * 100 + 2, r * 100 + 3],
34                "I/O block mismatch"
35            );
36        }
37        println!("IO PASS: parallel write/read verified on {size} ranks.");
38    }
39
40    world.barrier();
41    // File is deleted on close (drop).
42}
Source

pub fn write_at_all<T: Equivalence>( &mut self, offset: u64, data: &[T], ) -> Result<()>

Collective write at an explicit offset (MPI_File_write_at_all).

Examples found in repository?
examples/parallel_io.rs (line 24)
7fn main() {
8    let universe = mpi::initialize().unwrap();
9    let world = universe.world();
10    let rank = world.rank();
11    let size = world.size();
12
13    // Path depends on world size so concurrent jobs of different sizes don't
14    // collide; identical across the ranks of a single job.
15    let path = std::env::temp_dir().join(format!("mpi_no_c_io_{size}.bin"));
16    let mut f = File::open(
17        &world,
18        &path,
19        MODE_CREATE | MODE_RDWR | MODE_DELETE_ON_CLOSE,
20    )
21    .expect("File::open failed");
22
23    let block = [rank * 100, rank * 100 + 1, rank * 100 + 2, rank * 100 + 3];
24    f.write_at_all(rank as u64 * 16, &block)
25        .expect("write failed");
26
27    if rank == 0 {
28        for r in 0..size {
29            let mut buf = [0i32; 4];
30            f.read_at(r as u64 * 16, &mut buf).expect("read failed");
31            assert_eq!(
32                buf,
33                [r * 100, r * 100 + 1, r * 100 + 2, r * 100 + 3],
34                "I/O block mismatch"
35            );
36        }
37        println!("IO PASS: parallel write/read verified on {size} ranks.");
38    }
39
40    world.barrier();
41    // File is deleted on close (drop).
42}
Source

pub fn read_at_all<T: Equivalence>( &mut self, offset: u64, buf: &mut [T], ) -> Result<()>

Collective read at an explicit offset (MPI_File_read_at_all).

Source

pub fn size(&self) -> Result<u64>

The current file size in bytes (MPI_File_get_size).

Source

pub fn set_size(&mut self, size: u64) -> Result<()>

Set the file size in bytes (MPI_File_set_size).

Source

pub fn sync(&mut self) -> Result<()>

Flush buffered data to storage (MPI_File_sync).

Source

pub fn close(self) -> Result<()>

Collectively close the file (MPI_File_close), deleting it if it was opened with MODE_DELETE_ON_CLOSE.

Trait Implementations§

Source§

impl Drop for File

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
Source§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more

Auto Trait Implementations§

§

impl Freeze for File

§

impl RefUnwindSafe for File

§

impl Send for File

§

impl Sync for File

§

impl Unpin for File

§

impl UnsafeUnpin for File

§

impl UnwindSafe for File

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<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> 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, 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<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.