From 91378e84bf8bf927cadb27692dec893050118847 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Franz=20P=C3=B6schel?= Date: Thu, 19 Dec 2024 12:08:09 +0100 Subject: [PATCH] wip testing --- CMakeLists.txt | 4 + test/Files_ParallelIO/ParallelIOTests.hpp | 6 + .../read_variablebased_randomaccess.cpp | 134 ++++++++++++++++++ test/ParallelIOTest.cpp | 7 + 4 files changed, 151 insertions(+) create mode 100644 test/Files_ParallelIO/ParallelIOTests.hpp create mode 100644 test/Files_ParallelIO/read_variablebased_randomaccess.cpp diff --git a/CMakeLists.txt b/CMakeLists.txt index e5272ae2de..6e58a6f415 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/test/Files_ParallelIO/ParallelIOTests.hpp b/test/Files_ParallelIO/ParallelIOTests.hpp new file mode 100644 index 0000000000..c7c879fc8b --- /dev/null +++ b/test/Files_ParallelIO/ParallelIOTests.hpp @@ -0,0 +1,6 @@ +#include + +namespace read_variablebased_randomaccess +{ +auto read_variablebased_randomaccess() -> void; +} diff --git a/test/Files_ParallelIO/read_variablebased_randomaccess.cpp b/test/Files_ParallelIO/read_variablebased_randomaccess.cpp new file mode 100644 index 0000000000..ca5eb66961 --- /dev/null +++ b/test/Files_ParallelIO/read_variablebased_randomaccess.cpp @@ -0,0 +1,134 @@ +#include "ParallelIOTests.hpp" + +#include "openPMD/openPMD.hpp" + +#include + +#include + +#if openPMD_HAVE_ADIOS2 && openPMD_HAVE_MPI +#include +#include + +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("/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 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{"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(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( + "__openPMD_internal/openPMD2_adios2_schema", 0); + IO.DefineAttribute("__openPMD_internal/useSteps", 0); + + std::vector 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({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 diff --git a/test/ParallelIOTest.cpp b/test/ParallelIOTest.cpp index 519a8749b2..9552c3911e 100644 --- a/test/ParallelIOTest.cpp +++ b/test/ParallelIOTest.cpp @@ -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" @@ -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