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

Fix availableChunks for READ_LINEAR in ADIOS2 #1586

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions include/openPMD/backend/Attributable.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,8 @@ class Attributable

/** Reconstructs a path that can be passed to a Series constructor */
std::string filePath() const;
/** Return the path ob the object within the openPMD file */
std::string openPMDPath() const;
};

/**
Expand Down
5 changes: 3 additions & 2 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1455,8 +1455,9 @@ void ADIOS2IOHandlerImpl::availableChunks(
std::string varName = nameOfVariable(writable);
auto engine = ba.getEngine(); // make sure that data are present
auto datatype = detail::fromADIOS2Type(ba.m_IO.VariableType(varName));
bool allSteps = ba.streamStatus ==
detail::BufferedActions::StreamStatus::ReadWithoutStream;
bool allSteps = ba.m_mode != adios2::Mode::Read &&
ba.streamStatus ==
detail::BufferedActions::StreamStatus::ReadWithoutStream;
switchAdios2VariableType<detail::RetrieveBlocksInfo>(
datatype,
parameters,
Expand Down
21 changes: 21 additions & 0 deletions src/backend/Attributable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include <complex>
#include <iostream>
#include <set>
#include <sstream>

namespace openPMD
{
Expand Down Expand Up @@ -187,6 +188,26 @@ std::string Attributable::MyPath::filePath() const
return directory + seriesName + seriesExtension;
}

std::string Attributable::MyPath::openPMDPath() const
{
if (group.empty())
{
return std::string();
}
else
{
std::stringstream res;
auto it = group.begin();
auto end = group.end();
res << *it++;
for (; it != end; ++it)
{
res << '/' << *it;
}
return res.str();
}
}

auto Attributable::myPath() const -> MyPath
{
MyPath res;
Expand Down
95 changes: 95 additions & 0 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5096,6 +5096,39 @@ bool areEqual(T a, T b)
} // namespace epsilon

#if openPMD_HAVE_ADIOS2

#define openPMD_VERBOSE_CHUNKS 0

#if openPMD_VERBOSE_CHUNKS
static std::string format_chunk(ChunkInfo const &chunk_info)
{
std::stringstream result;
auto print_vector = [&result](auto const &vec) {
if (vec.empty())
{
result << "[]";
}
else
{
auto it = vec.begin();
result << '[' << *it++;
auto end = vec.end();
for (; it != end; ++it)
{
result << ',' << *it;
}
result << ']';
}
};
result << '(';
print_vector(chunk_info.offset);
result << '|';
print_vector(chunk_info.extent);
result << ')';
return result.str();
}
#endif

TEST_CASE("git_adios2_sample_test", "[serial][adios2]")
{
using namespace epsilon;
Expand All @@ -5105,11 +5138,73 @@ TEST_CASE("git_adios2_sample_test", "[serial][adios2]")

std::string const samplePath =
"../samples/git-sample/3d-bp4/example-3d-bp4.bp";
std::string const samplePathFilebased =
"../samples/git-sample/3d-bp4/example-3d-bp4_%T.bp";
if (!auxiliary::directory_exists(samplePath))
{
std::cerr << "git sample '" << samplePath << "' not accessible \n";
return;
}

/*
* This checks a regression introduced by
* https://github.com/openPMD/openPMD-api/pull/1498 and fixed by
* https://github.com/openPMD/openPMD-api/pull/1586
*/
for (auto const &[filepath, access] :
{std::make_pair(samplePath, Access::READ_ONLY),
std::make_pair(samplePathFilebased, Access::READ_ONLY),
std::make_pair(samplePath, Access::READ_LINEAR),
std::make_pair(samplePathFilebased, Access::READ_LINEAR)})
{
Series read(filepath, access);

// false positive by clang-tidy?
// NOLINTNEXTLINE(performance-for-range-copy)
for (auto iteration : read.readIterations())
{
for (auto &mesh : iteration.meshes)
{
for (auto &component : mesh.second)
{
#if openPMD_VERBOSE_CHUNKS
std::cout << "Chunks for '"
<< component.second.myPath().openPMDPath()
<< "':" << std::endl;
for (auto const &chunk : component.second.availableChunks())
{
std::cout << "\t" << format_chunk(chunk) << std::endl;
}
#else
component.second.availableChunks();
#endif
}
}
for (auto &particle_species : iteration.particles)
{
for (auto &record : particle_species.second)
{
for (auto &component : record.second)
{
#if openPMD_VERBOSE_CHUNKS
std::cout << "Chunks for '"
<< component.second.myPath().openPMDPath()
<< "':" << std::endl;
for (auto const &chunk :
component.second.availableChunks())
{
std::cout << "\t" << format_chunk(chunk)
<< std::endl;
}
#else
component.second.availableChunks();
#endif
}
}
}
}
}

Series o(samplePath, Access::READ_ONLY, R"({"backend": "adios2"})");
REQUIRE(o.openPMD() == "1.1.0");
REQUIRE(o.openPMDextension() == 0);
Expand Down
Loading