Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adding Adios2 io support #113

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
4 changes: 2 additions & 2 deletions src/Omega_h_adios2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@ void read_parents(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, std::strin
}
}

void write_adios2(adios2::IO &io, adios2::Engine & writer,
void _write_adios2(adios2::IO &io, adios2::Engine & writer,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this named _write_adios2? We generally avoid having names that start with underscore or double underscore in C++ because depending on the second symbol it could be undefined behavior.

see: https://en.cppreference.com/w/cpp/language/identifiers

Mesh* mesh, std::string pref)
{
comm_size = mesh->comm()->size();
Expand Down Expand Up @@ -506,7 +506,7 @@ void write_adios2(filesystem::path const& path,
adios2::Engine writer = io.Open(filename, adios2::Mode::Write);
writer.BeginStep();
for (; it!=mesh_map.end(); ++it)
write_adios2(io, writer, it->first, it->second);
_write_adios2(io, writer, it->first, it->second);
writer.EndStep();
writer.Close();
}
Expand Down
2 changes: 2 additions & 0 deletions src/Omega_h_adios2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ template <typename T>
void read_value(adios2::IO &, adios2::Engine &reader,
T *val, std::string &name, bool global=false);

void write_adios2(filesystem::path const& path,
std::map<Mesh*, std::string>& mesh_map);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is this stored as a map? Instead of a list of pairs or struct that holds a name and a omega_h mesh pointer?

void write_adios2(filesystem::path const& path, Mesh *mesh, std::string pref="");

Mesh read_adios2(filesystem::path const& path, Library* lib, std::string pref="");
Expand Down
55 changes: 37 additions & 18 deletions src/adios2_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,39 +76,58 @@ int main(int argc, char *argv[])

Omega_h::CmdLine cmdline;

cmdline.add_arg<std::string>("input.osh");
cmdline.add_arg<std::string>("input1.osh");
cmdline.add_arg<std::string>("input2.osh");
cmdline.add_arg<std::string>("output.bp");
if (!cmdline.parse_final(world, &argc, argv)) return -1;
Omega_h::filesystem::path inpath = cmdline.get<std::string>("input.osh");
Omega_h::filesystem::path inpath1 = cmdline.get<std::string>("input1.osh");
Omega_h::filesystem::path inpath2 = cmdline.get<std::string>("input2.osh");
Omega_h::filesystem::path outpath=cmdline.get<std::string>("output.bp");

Omega_h::Mesh mesh(&lib);
Omega_h::binary::read(inpath, world, &mesh);
cout<<"\n--- Mesh loaded from \""<<inpath<<"\" ---\n";
print_info(&lib, mesh);
Omega_h::Mesh mesh1(&lib);
Omega_h::binary::read(inpath1, world, &mesh1);
Omega_h::Mesh mesh2(&lib);
Omega_h::binary::read(inpath2, world, &mesh2);

cout<<"\n--- Mesh loaded from \""<<inpath1<<"\" ---\n";
print_info(&lib, mesh1);
cout<<"\n--- Mesh loaded from \""<<inpath2<<"\" ---\n";
print_info(&lib, mesh2);

// Omega_h::Mesh mesh = build_box(world, OMEGA_H_SIMPLEX, 1., 1., 0., 2, 2, 0);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove commented code.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it.

Omega_h::binary::write("omegah.osh", &mesh);
Omega_h::vtk::write_parallel("omegah.vtk", &mesh);
Omega_h::binary::write("omegah1.osh", &mesh1);
Omega_h::binary::write("omegah2.osh", &mesh2);
// Omega_h::vtk::write_parallel("omegah.vtk", &mesh);

try
{
write_adios2(outpath, &mesh, std::string("test"));
Omega_h::Mesh mesh2 = read_adios2(outpath, &lib, std::string("test"));
Omega_h::vtk::write_parallel("adios2.vtk", &mesh2);

cout<<"\n\n--- Mesh loaded back from \""<<outpath<<"\" ---\n";
print_info(&lib, mesh2);
map<Mesh*, std::string> mmap;
mmap[&mesh1]="m1";
mmap[&mesh2]="m2";
write_adios2(outpath, mmap);
Omega_h::Mesh mesh3 = read_adios2(outpath, &lib, std::string("m1"));
Omega_h::Mesh mesh4 = read_adios2(outpath, &lib, std::string("m2"));
//Omega_h::vtk::write_parallel("adios2.vtk", &mesh2);

cout<<"\n\n--- Two meshes loaded back from \""<<outpath<<"\" ---\n";
print_info(&lib, mesh3);
print_info(&lib, mesh4);

double tol = 1e-6, floor = 0.0;
bool allow_superset = false;
auto opts = MeshCompareOpts::init(
&mesh, VarCompareOpts{VarCompareOpts::RELATIVE, tol, floor});
auto res = compare_meshes(&mesh, &mesh2, opts, true);
&mesh1, VarCompareOpts{VarCompareOpts::RELATIVE, tol, floor});
auto res = compare_meshes(&mesh1, &mesh3, opts, true);
if (res == OMEGA_H_SAME || (allow_superset && res == OMEGA_H_MORE))
{
cout << "\nSUCCESS! Two meshes (.osh and .bp) are the same\n";
return 0;
opts = MeshCompareOpts::init(
&mesh2, VarCompareOpts{VarCompareOpts::RELATIVE, tol, floor});
res = compare_meshes(&mesh2, &mesh4, opts, true);
if (res == OMEGA_H_SAME || (allow_superset && res == OMEGA_H_MORE))
{
cout << "\nSUCCESS! Meshes loaded from .osh and .bp are the same\n";
return 0;
}
}
cout << "\nFAIL! Two meshes (.osh and .bp) are NOT the same\n";
return 2;
Expand Down