pub struct File { /* private fields */ }Expand description
A file opened collectively by a communicator (MPI_File).
Implementations§
Source§impl File
impl File
Sourcepub fn open<C: Communicator>(
comm: &C,
path: impl AsRef<Path>,
mode: u32,
) -> Result<File>
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}Sourcepub fn write_at<T: Equivalence>(
&mut self,
offset: u64,
data: &[T],
) -> Result<()>
pub fn write_at<T: Equivalence>( &mut self, offset: u64, data: &[T], ) -> Result<()>
Write data at byte offset (MPI_File_write_at).
Sourcepub fn read_at<T: Equivalence>(
&mut self,
offset: u64,
buf: &mut [T],
) -> Result<()>
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}Sourcepub fn write_at_all<T: Equivalence>(
&mut self,
offset: u64,
data: &[T],
) -> Result<()>
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}Sourcepub fn read_at_all<T: Equivalence>(
&mut self,
offset: u64,
buf: &mut [T],
) -> Result<()>
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).
Sourcepub fn set_size(&mut self, size: u64) -> Result<()>
pub fn set_size(&mut self, size: u64) -> Result<()>
Set the file size in bytes (MPI_File_set_size).
Sourcepub fn close(self) -> Result<()>
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§
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> 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