Skip to content

Commit

Permalink
wip testing
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Dec 19, 2024
1 parent a61cade commit 91378e8
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 0 deletions.
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -787,6 +787,10 @@ if(openPMD_BUILD_TESTING)
test/Files_SerialIO/close_and_reopen_test.cpp
test/Files_SerialIO/filebased_write_test.cpp
)
elseif(${test_name} STREQUAL "ParallelIO")
list(APPEND ${out_list}
test/Files_ParallelIO/read_variablebased_randomaccess.cpp
)
endif()
endmacro()

Expand Down
6 changes: 6 additions & 0 deletions test/Files_ParallelIO/ParallelIOTests.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#include <openPMD/openPMD.hpp>

namespace read_variablebased_randomaccess
{
auto read_variablebased_randomaccess() -> void;
}
134 changes: 134 additions & 0 deletions test/Files_ParallelIO/read_variablebased_randomaccess.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
#include "ParallelIOTests.hpp"

#include "openPMD/openPMD.hpp"

#include <numeric>

#include <catch2/catch.hpp>

#if openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI
#include <adios2.h>
#include <mpi.h>

namespace read_variablebased_randomaccess
{
static void create_file_in_serial()
{
{
adios2::ADIOS adios;
auto IO = adios.DeclareIO("IO");
IO.SetEngine("bp5");
auto engine =
IO.Open("../samples/bp5_no_steps.bp", adios2::Mode::Write);

auto variable =
IO.DefineVariable<int>("/data/meshes/theta", {10}, {0}, {10});

for (size_t step = 0; step < 5; ++step)
{
engine.BeginStep();

// write default openPMD attributes
IO.DefineAttribute("/basePath", std::string("/data/%T/"));
IO.DefineAttribute(
"/date", std::string("2021-02-22 11:14:00 +0000"));
IO.DefineAttribute(
"/iterationEncoding", std::string("variableBased"));
IO.DefineAttribute("/iterationFormat", std::string("/data/%T/"));
IO.DefineAttribute("/meshesPath", std::string("meshes/"));
IO.DefineAttribute("/openPMD", std::string("1.1.0"));
IO.DefineAttribute("/openPMDextension", uint32_t(0));
IO.DefineAttribute("/software", std::string("openPMD-api"));
IO.DefineAttribute("/softwareVersion", std::string("0.17.0-dev"));

std::vector<size_t> current_snapshots(10);
std::iota(
current_snapshots.begin(),
current_snapshots.end(),
current_snapshots.size() * step);
IO.DefineAttribute(
"/data/snapshot",
current_snapshots.data(),
current_snapshots.size(),
"",
"/",
/* allowModification = */ true);

IO.DefineAttribute("/data/dt", double(1));
IO.DefineAttribute(
"/data/meshes/theta/axisLabels",
std::vector<std::string>{"x"}.data(),
1);
IO.DefineAttribute(
"/data/meshes/theta/dataOrder", std::string("C"));
IO.DefineAttribute(
"/data/meshes/theta/geometry", std::string("cartesian"));
IO.DefineAttribute(
"/data/meshes/theta/gridGlobalOffset", double(0));
IO.DefineAttribute("/data/meshes/theta/gridSpacing", double(1));
IO.DefineAttribute("/data/meshes/theta/gridUnitSI", double(1));
IO.DefineAttribute("/data/meshes/theta/position", double(0));
IO.DefineAttribute("/data/meshes/theta/timeOffset", double(0));
IO.DefineAttribute(
"/data/meshes/theta/unitDimension",
std::vector<double>(7, 0).data(),
7);
IO.DefineAttribute("/data/meshes/theta/unitSI", double(1));
IO.DefineAttribute("/data/time", double(0));
IO.DefineAttribute("/data/timeUnitSI", double(1));

IO.DefineAttribute<uint64_t>(
"__openPMD_internal/openPMD2_adios2_schema", 0);
IO.DefineAttribute<unsigned char>("__openPMD_internal/useSteps", 0);

std::vector<int> data{0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
engine.Put(variable, data.data());

engine.EndStep();
}

engine.Close();
}
}

auto read_variablebased_randomaccess() -> void
{
int rank;
MPI_Comm_rank(MPI_COMM_WORLD, &rank);
if (rank == 0)
{
create_file_in_serial();
}
MPI_Barrier(MPI_COMM_WORLD);

std::string const config = R"END(
{
"adios2":
{
"use_group_table": true
}
})END";

{
openPMD::Series read(
"../samples/bp5_no_steps.bp",
openPMD::Access::READ_ONLY,
MPI_COMM_WORLD,
"adios2.engine.type = \"bp5\"");
auto data =
read.iterations[0].meshes["theta"].loadChunk<int>({0}, {10});
read.flush();
for (size_t i = 0; i < 10; ++i)
{
REQUIRE(data.get()[i] == int(i));
}
}
}
} // namespace read_variablebased_randomaccess
#else
namespace read_variablebased_randomaccess
{
void read_variablebased_randomaccess()
{}
} // namespace read_variablebased_randomaccess
#endif
7 changes: 7 additions & 0 deletions test/ParallelIOTest.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
/* Running this test in parallel with MPI requires MPI::Init.
* To guarantee a correct call to Init, launch the tests manually.
*/
#include "Files_ParallelIO/ParallelIOTests.hpp"

#include "openPMD/IO/ADIOS/macros.hpp"
#include "openPMD/IO/Access.hpp"
#include "openPMD/auxiliary/Environment.hpp"
Expand Down Expand Up @@ -2201,4 +2203,9 @@ TEST_CASE("adios2_flush_via_step")
}
#endif

TEST_CASE("read_variablebased_randomaccess")
{
read_variablebased_randomaccess::read_variablebased_randomaccess();
}

#endif // openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI

0 comments on commit 91378e8

Please sign in to comment.