Skip to content

Commit

Permalink
Parametrize ghost_mode; add cpp demo to doc
Browse files Browse the repository at this point in the history
  • Loading branch information
ampdes committed Aug 14, 2024
1 parent 636f742 commit 31ac5b0
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 49 deletions.
82 changes: 42 additions & 40 deletions cpp/demo/checkpointing/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<float>(io_read, engine_read, MPI_COMM_WORLD);
if (engine_read.BetweenStepPairs())
{
engine_read.EndStep();
}
engine_read.BeginStep();
auto mesh_read
= io::native::read_mesh<float>(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;
Expand Down
1 change: 1 addition & 0 deletions cpp/doc/source/demo.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,4 @@ Experimental
:maxdepth: 1

demos/demo_mixed_topology.md
demos/demo_checkpointing.md
18 changes: 11 additions & 7 deletions cpp/dolfinx/io/checkpointing.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,8 @@ template void write_mesh<double>(adios2::IO& io, adios2::Engine& engine,
//-----------------------------------------------------------------------------
template <std::floating_point T>
dolfinx::mesh::Mesh<T> read_mesh(adios2::IO& io, adios2::Engine& engine,
MPI_Comm comm)
MPI_Comm comm,
dolfinx::mesh::GhostMode ghost_mode)
{

int rank, size;
Expand Down Expand Up @@ -234,7 +235,7 @@ dolfinx::mesh::Mesh<T> read_mesh(adios2::IO& io, adios2::Engine& engine,
fem::CoordinateElement<T> element
= fem::CoordinateElement<T>(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<T> mesh = mesh::create_mesh(comm, comm, array, element, comm,
x_reduced, x_shape, part);
Expand All @@ -247,10 +248,12 @@ dolfinx::mesh::Mesh<T> read_mesh(adios2::IO& io, adios2::Engine& engine,
//-----------------------------------------------------------------------------
/// @cond
template dolfinx::mesh::Mesh<float>
read_mesh<float>(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm);
read_mesh<float>(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm,
dolfinx::mesh::GhostMode ghost_mode);

template dolfinx::mesh::Mesh<double>
read_mesh<double>(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm);
read_mesh<double>(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm,
dolfinx::mesh::GhostMode ghost_mode);

/// @endcond

Expand Down Expand Up @@ -354,15 +357,16 @@ std::vector<int64_t> read_topology_data(adios2::IO& io, adios2::Engine& engine,

//-----------------------------------------------------------------------------
std::variant<dolfinx::mesh::Mesh<float>, dolfinx::mesh::Mesh<double>>
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");

if (floating_point == "float")
{
dolfinx::mesh::Mesh<float> mesh
= dolfinx::io::native::read_mesh<float>(io, engine, comm);
= dolfinx::io::native::read_mesh<float>(io, engine, comm, ghost_mode);
if (engine.BetweenStepPairs())
{
engine.EndStep();
Expand All @@ -372,7 +376,7 @@ read_mesh_variant(adios2::IO& io, adios2::Engine& engine, MPI_Comm comm)
else if (floating_point == "double")
{
dolfinx::mesh::Mesh<double> mesh
= dolfinx::io::native::read_mesh<double>(io, engine, comm);
= dolfinx::io::native::read_mesh<double>(io, engine, comm, ghost_mode);
if (engine.BetweenStepPairs())
{
engine.EndStep();
Expand Down
9 changes: 7 additions & 2 deletions cpp/dolfinx/io/checkpointing.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <adios2.h>
#include <basix/finite-element.h>
#include <dolfinx/mesh/Mesh.h>
#include <dolfinx/mesh/utils.h>
#include <mpi.h>

/// @file checkpointing.h
Expand All @@ -37,7 +38,9 @@ void write_mesh(adios2::IO& io, adios2::Engine& engine,
/// @return mesh reconstructed from the data
template <std::floating_point T>
dolfinx::mesh::Mesh<T> 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

Expand Down Expand Up @@ -87,7 +90,9 @@ std::vector<int64_t> read_topology_data(adios2::IO& io, adios2::Engine& engine,
/// @return mesh reconstructed from the data
std::variant<dolfinx::mesh::Mesh<float>, dolfinx::mesh::Mesh<double>>
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

Expand Down

0 comments on commit 31ac5b0

Please sign in to comment.