parallel_io/
parallel_io.rs1use itertools::izip;
2use mpi::{collective::CommunicatorCollectives, environment::Universe, traits::Communicator};
3use ndelement::{ciarlet::CiarletElement, map::IdentityMap, types::ReferenceCellType};
4use ndgrid::traits::{
5 DistributableGrid, Entity, Grid, ParallelBuilder, ParallelGrid, RONExportParallel,
6 RONImportParallel, Topology,
7};
8use ndgrid::{
9 ParallelGridImpl, SingleElementGrid, SingleElementGridBuilder, shapes, types::GraphPartitioner,
10};
11
12fn main() {
18 let universe: Universe = mpi::initialize().unwrap();
19 let comm = universe.world();
20 let rank = comm.rank();
21
22 let g = if rank == 0 {
23 let serial_g = shapes::unit_cube_boundary::<f64>(4, 5, 4, ReferenceCellType::Triangle);
25
26 serial_g.distribute(&comm, GraphPartitioner::None)
28 } else {
29 let b = SingleElementGridBuilder::<f64>::new(3, (ReferenceCellType::Triangle, 1));
30 b.create_parallel_grid(&comm, 0)
31 };
32
33 g.export_as_ron("_unit_cube_boundary_parallel.ron");
35
36 comm.barrier();
38
39 let g2 = ParallelGridImpl::<'_, _, SingleElementGrid::<f64, CiarletElement<f64, IdentityMap>>>::import_from_ron(&comm, "_unit_cube_boundary_parallel.ron");
41
42 if rank == 0 {
44 println!("The first 5 cells of the grids");
45 for (cell, cell2) in izip!(
46 g.local_grid().entity_iter(ReferenceCellType::Triangle),
47 g2.local_grid().entity_iter(ReferenceCellType::Triangle)
48 )
49 .take(5)
50 {
51 println!(
52 "{:?} {:?}",
53 cell.topology()
54 .sub_entity_iter(ReferenceCellType::Point)
55 .collect::<Vec<_>>(),
56 cell2
57 .topology()
58 .sub_entity_iter(ReferenceCellType::Point)
59 .collect::<Vec<_>>(),
60 );
61 }
62 }
63}