Skip to content

Commit

Permalink
fixing ctest error with adios2_io
Browse files Browse the repository at this point in the history
  • Loading branch information
seegyoung committed Jan 16, 2025
1 parent aae867b commit f0099e7
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 30 deletions.
1 change: 1 addition & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ if(BUILD_TESTING)
osh_add_exe(adios2_io)
test_basefunc(adios2_io 1 ./adios2_io
${CMAKE_SOURCE_DIR}/meshes/unitbox_cutTriCube_1k.osh
${CMAKE_SOURCE_DIR}/meshes/plate_6elem.osh
output.bp)
endif()
endif()
Expand Down
16 changes: 8 additions & 8 deletions src/Omega_h_adios2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ namespace Omega_h {
long unsigned int comm_size, rank;

template <typename T>
void write_value(adios2::IO &io, adios2::Engine &writer,
static void write_value(adios2::IO &io, adios2::Engine &writer,
T val, std::string &name, bool global)
{
if (global)
Expand All @@ -35,7 +35,7 @@ void write_value(adios2::IO &io, adios2::Engine &writer,
}

template <typename T>
void read_value(adios2::IO &io, adios2::Engine &reader,
static void read_value(adios2::IO &io, adios2::Engine &reader,
T *val, std::string &name, bool global)
{
adios2::Variable<T> bpData = io.InquireVariable<T>(name);
Expand All @@ -55,7 +55,7 @@ void read_value(adios2::IO &io, adios2::Engine &reader,
}

template <typename T>
void write_array(adios2::IO &io, adios2::Engine &writer, Read<T> array,
static void write_array(adios2::IO &io, adios2::Engine &writer, Read<T> array,
std::string &name)
{
// std::cout<<__func__<<" "<<name<<": value ";
Expand All @@ -81,7 +81,7 @@ void write_array(adios2::IO &io, adios2::Engine &writer, Read<T> array,
}

template <typename T>
void read_array(adios2::IO &io, adios2::Engine &reader,
static void read_array(adios2::IO &io, adios2::Engine &reader,
Read<T> &array, std::string &name)
{
// usage: Read<int32_t> array;
Expand Down Expand Up @@ -333,7 +333,7 @@ void read_tags(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, int d, std::s
}
}

void write_pbdry(adios2::IO &io, adios2::Engine &writer, Mesh* mesh, int d, std::string pref)
void write_part_boundary(adios2::IO &io, adios2::Engine &writer, Mesh* mesh, int d, std::string pref)
{
if (mesh->comm()->size() == 1) return;
auto owners = mesh->ask_owners(d);
Expand All @@ -343,7 +343,7 @@ void write_pbdry(adios2::IO &io, adios2::Engine &writer, Mesh* mesh, int d, std:
write_array(io, writer, owners.idxs, name);
}

void read_pbdry(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, int d, std::string pref)
void read_part_boundary(adios2::IO &io, adios2::Engine &reader, Mesh* mesh, int d, std::string pref)
{
if (mesh->comm()->size() == 1) return;
Remotes owners;
Expand Down Expand Up @@ -479,7 +479,7 @@ void _write_adios2(adios2::IO &io, adios2::Engine & writer,
for (Int d = 0; d <= mesh->dim(); ++d)
{
write_tags(io, writer, mesh, d, pref);
write_pbdry(io, writer, mesh, d, pref);
write_part_boundary(io, writer, mesh, d, pref);
}

write_sets(io, writer, mesh, pref);
Expand Down Expand Up @@ -548,7 +548,7 @@ Mesh read_adios2(filesystem::path const& path, Library* lib, std::string pref)
for (Int d = 0; d <= mesh.dim(); ++d)
{
read_tags(io, reader, &mesh, d, pref);
read_pbdry(io, reader, &mesh, d, pref);
read_part_boundary(io, reader, &mesh, d, pref);
}

read_sets(io, reader, &mesh, pref);
Expand Down
4 changes: 2 additions & 2 deletions src/Omega_h_adios2.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
namespace Omega_h {

template <typename T>
void write_value(adios2::IO &, adios2::Engine &writer,
static void write_value(adios2::IO &, adios2::Engine &writer,
T val, std::string &name, bool global=false);

template <typename T>
void read_value(adios2::IO &, adios2::Engine &reader,
static void read_value(adios2::IO &, adios2::Engine &reader,
T *val, std::string &name, bool global=false);

void write_adios2(filesystem::path const& path,
Expand Down
33 changes: 13 additions & 20 deletions src/adios2_io.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@
*
* .cpp : adios2 low-level API example to write and read arrays and string
*
* Created on: Aug 25, 2024
* Author: Seegyoung Seol [email protected]
*
*/
#include <Omega_h_timer.hpp>
#include <Omega_h_file.hpp>
Expand All @@ -29,9 +26,6 @@
#include <mpi.h>
#endif

using namespace Omega_h;
using namespace std;

// printTagInfo and getNumEq copied from describe.cpp
template <typename T>
void printTagInfo(Omega_h::Mesh mesh, std::ostringstream& oss, int dim, int tag, std::string type) {
Expand All @@ -57,7 +51,7 @@ int getNumEq(Omega_h::Mesh mesh, std::string tagname, int dim, int value) {
return Omega_h::get_sum(each_eq_to);
}

void print_info(Library* lib, Omega_h::Mesh mesh);
void print_info(Omega_h::Library* lib, Omega_h::Mesh mesh);

// to check the content of .bp, run /lore/seols/romulus-install/bin/bpls
// ex. ./bpls mesh.bp
Expand Down Expand Up @@ -89,47 +83,46 @@ int main(int argc, char *argv[])
Omega_h::Mesh mesh2(&lib);
Omega_h::binary::read(inpath2, world, &mesh2);

cout<<"\n--- Mesh loaded from \""<<inpath1<<"\" ---\n";
std::cout<<"\n--- Mesh loaded from \""<<inpath1<<"\" ---\n";
print_info(&lib, mesh1);
cout<<"\n--- Mesh loaded from \""<<inpath2<<"\" ---\n";
std::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);
Omega_h::binary::write("omegah1.osh", &mesh1);
Omega_h::binary::write("omegah2.osh", &mesh2);
// Omega_h::vtk::write_parallel("omegah.vtk", &mesh);

try
{
map<Mesh*, std::string> mmap;
std::map<Omega_h::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";
std::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(
&mesh1, VarCompareOpts{VarCompareOpts::RELATIVE, tol, floor});
auto opts = Omega_h::MeshCompareOpts::init(
&mesh1, Omega_h::VarCompareOpts{Omega_h::VarCompareOpts::RELATIVE, tol, floor});
auto res = compare_meshes(&mesh1, &mesh3, opts, true);
if (res == OMEGA_H_SAME || (allow_superset && res == OMEGA_H_MORE))
{
opts = MeshCompareOpts::init(
&mesh2, VarCompareOpts{VarCompareOpts::RELATIVE, tol, floor});
opts = Omega_h::MeshCompareOpts::init(
&mesh2, Omega_h::VarCompareOpts{Omega_h::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";
std::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";
std::cout << "\nFAIL! Two meshes (.osh and .bp) are NOT the same\n";
return 2;
}
catch (std::exception &e)
Expand All @@ -143,11 +136,11 @@ int main(int argc, char *argv[])
}

// serial only at the moment
void print_info(Library* lib, Omega_h::Mesh mesh)
void print_info(Omega_h::Library* lib, Omega_h::Mesh mesh)
{
auto rank = lib->world()->rank();

ostringstream oss;
std::ostringstream oss;
// always print two places to the right of the decimal
// for floating point types (i.e., imbalance)
oss.precision(2);
Expand Down

0 comments on commit f0099e7

Please sign in to comment.