diff --git a/cpp/demo/checkpointing/main.cpp b/cpp/demo/checkpointing/main.cpp index 0e1d082cb86..91f1b60d289 100644 --- a/cpp/demo/checkpointing/main.cpp +++ b/cpp/demo/checkpointing/main.cpp @@ -30,54 +30,56 @@ int main(int argc, char* argv[]) MPI_COMM_WORLD, {{{0.0, 0.0}, {1.0, 1.0}}}, {4, 4}, mesh::CellType::quadrilateral, part)); - try - { - // Set up ADIOS2 IO and Engine - adios2::ADIOS adios(mesh->comm()); + try + { + // Set up ADIOS2 IO and Engine + adios2::ADIOS adios(mesh->comm()); - adios2::IO io = adios.DeclareIO("mesh-write"); - io.SetEngine("BP5"); - adios2::Engine engine = io.Open("mesh.bp", adios2::Mode::Write); + adios2::IO io = adios.DeclareIO("mesh-write"); + io.SetEngine("BP5"); + adios2::Engine engine = io.Open("mesh.bp", adios2::Mode::Write); - io::native::write_mesh(io, engine, *mesh); + io::native::write_mesh(io, engine, *mesh); - engine.Close(); - } - catch (std::exception &e) - { - std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; - MPI_Abort(MPI_COMM_WORLD, -1); - } + engine.Close(); + } + catch (std::exception& e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; + MPI_Abort(MPI_COMM_WORLD, -1); + } - try - { - // Set up ADIOS2 IO and Engine - adios2::ADIOS adios_read(MPI_COMM_WORLD); - adios2::IO io_read = adios_read.DeclareIO("mesh-read"); - io_read.SetEngine("BP5"); - adios2::Engine engine_read = io_read.Open("mesh.bp", adios2::Mode::Read); + try + { + // Set up ADIOS2 IO and Engine + adios2::ADIOS adios_read(MPI_COMM_WORLD); + adios2::IO io_read = adios_read.DeclareIO("mesh-read"); + io_read.SetEngine("BP5"); + adios2::Engine engine_read = io_read.Open("mesh.bp", adios2::Mode::Read); - engine_read.BeginStep(); - auto mesh_read = io::native::read_mesh(io_read, engine_read, MPI_COMM_WORLD); - if (engine_read.BetweenStepPairs()) - { - engine_read.EndStep(); - } + engine_read.BeginStep(); + auto mesh_read + = io::native::read_mesh(io_read, engine_read, MPI_COMM_WORLD); + if (engine_read.BetweenStepPairs()) + { + engine_read.EndStep(); + } - engine_read.Close(); + engine_read.Close(); - adios2::IO io_write = adios_read.DeclareIO("mesh-write"); - io_write.SetEngine("BP5"); - adios2::Engine engine_write = io_write.Open("mesh2.bp", adios2::Mode::Write); + adios2::IO io_write = adios_read.DeclareIO("mesh-write"); + io_write.SetEngine("BP5"); + adios2::Engine engine_write + = io_write.Open("mesh2.bp", adios2::Mode::Write); - io::native::write_mesh(io_write, engine_write, mesh_read); - engine_write.Close(); - } - catch (std::exception &e) - { - std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; - MPI_Abort(MPI_COMM_WORLD, -1); - } + io::native::write_mesh(io_write, engine_write, mesh_read); + engine_write.Close(); + } + catch (std::exception& e) + { + std::cout << "ERROR: ADIOS2 exception: " << e.what() << "\n"; + MPI_Abort(MPI_COMM_WORLD, -1); + } MPI_Finalize(); return 0; diff --git a/cpp/doc/source/demo.rst b/cpp/doc/source/demo.rst index 7ce9d8d80db..96b21104885 100644 --- a/cpp/doc/source/demo.rst +++ b/cpp/doc/source/demo.rst @@ -42,3 +42,4 @@ Experimental :maxdepth: 1 demos/demo_mixed_topology.md + demos/demo_checkpointing.md diff --git a/cpp/dolfinx/io/checkpointing.cpp b/cpp/dolfinx/io/checkpointing.cpp index 66565288757..37f73a5d5ce 100644 --- a/cpp/dolfinx/io/checkpointing.cpp +++ b/cpp/dolfinx/io/checkpointing.cpp @@ -164,7 +164,8 @@ template void write_mesh(adios2::IO& io, adios2::Engine& engine, //----------------------------------------------------------------------------- template dolfinx::mesh::Mesh read_mesh(adios2::IO& io, adios2::Engine& engine, - MPI_Comm comm) + MPI_Comm comm, + dolfinx::mesh::GhostMode ghost_mode) { int rank, size; @@ -234,7 +235,7 @@ dolfinx::mesh::Mesh read_mesh(adios2::IO& io, adios2::Engine& engine, fem::CoordinateElement element = fem::CoordinateElement(cell_type, degree, lagrange_variant); - auto part = mesh::create_cell_partitioner(mesh::GhostMode::shared_facet); + auto part = mesh::create_cell_partitioner(ghost_mode); mesh::Mesh mesh = mesh::create_mesh(comm, comm, array, element, comm, x_reduced, x_shape, part); @@ -247,10 +248,12 @@ dolfinx::mesh::Mesh read_mesh(adios2::IO& io, adios2::Engine& engine, //----------------------------------------------------------------------------- /// @cond template dolfinx::mesh::Mesh -read_mesh(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm); +read_mesh(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm, + dolfinx::mesh::GhostMode ghost_mode); template dolfinx::mesh::Mesh -read_mesh(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm); +read_mesh(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm, + dolfinx::mesh::GhostMode ghost_mode); /// @endcond @@ -354,7 +357,8 @@ std::vector read_topology_data(adios2::IO& io, adios2::Engine& engine, //----------------------------------------------------------------------------- std::variant, dolfinx::mesh::Mesh> -read_mesh_variant(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm) +read_mesh_variant(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm, + dolfinx::mesh::GhostMode ghost_mode) { engine.BeginStep(); std::string floating_point = io.VariableType("x"); @@ -362,7 +366,7 @@ read_mesh_variant(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm) if (floating_point == "float") { dolfinx::mesh::Mesh mesh - = dolfinx::io::native::read_mesh(io, engine, comm); + = dolfinx::io::native::read_mesh(io, engine, comm, ghost_mode); if (engine.BetweenStepPairs()) { engine.EndStep(); @@ -372,7 +376,7 @@ read_mesh_variant(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm) else if (floating_point == "double") { dolfinx::mesh::Mesh mesh - = dolfinx::io::native::read_mesh(io, engine, comm); + = dolfinx::io::native::read_mesh(io, engine, comm, ghost_mode); if (engine.BetweenStepPairs()) { engine.EndStep(); diff --git a/cpp/dolfinx/io/checkpointing.h b/cpp/dolfinx/io/checkpointing.h index 3337f6b37b2..c6104a935f7 100644 --- a/cpp/dolfinx/io/checkpointing.h +++ b/cpp/dolfinx/io/checkpointing.h @@ -12,6 +12,7 @@ #include #include #include +#include #include /// @file checkpointing.h @@ -37,7 +38,9 @@ void write_mesh(adios2::IO& io, adios2::Engine& engine, /// @return mesh reconstructed from the data template dolfinx::mesh::Mesh read_mesh(adios2::IO& io, adios2::Engine& engine, - MPI_Comm comm = MPI_COMM_WORLD); + MPI_Comm comm = MPI_COMM_WORLD, + dolfinx::mesh::GhostMode ghost_mode + = dolfinx::mesh::GhostMode::none); } // namespace dolfinx::io::native @@ -87,7 +90,9 @@ std::vector read_topology_data(adios2::IO& io, adios2::Engine& engine, /// @return mesh reconstructed from the data std::variant, dolfinx::mesh::Mesh> read_mesh_variant(adios2::IO& io, adios2::Engine& engine, - MPI_Comm comm = MPI_COMM_WORLD); + MPI_Comm comm = MPI_COMM_WORLD, + dolfinx::mesh::GhostMode ghost_mode + = dolfinx::mesh::GhostMode::none); } // namespace dolfinx::io::impl_native