Skip to content

Commit d5524ec

Browse files
Fix availableChunks for READ_LINEAR in ADIOS2 (#1586)
* Fix availableChunks for READ_LINEAR in ADIOS2 * Update src/IO/ADIOS/ADIOS2IOHandler.cpp * Add testing * CI fixes
1 parent 7bb2948 commit d5524ec

4 files changed

Lines changed: 121 additions & 2 deletions

File tree

include/openPMD/backend/Attributable.hpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,8 @@ class Attributable
230230

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

235237
/**

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1455,8 +1455,9 @@ void ADIOS2IOHandlerImpl::availableChunks(
14551455
std::string varName = nameOfVariable(writable);
14561456
auto engine = ba.getEngine(); // make sure that data are present
14571457
auto datatype = detail::fromADIOS2Type(ba.m_IO.VariableType(varName));
1458-
bool allSteps = ba.streamStatus ==
1459-
detail::BufferedActions::StreamStatus::ReadWithoutStream;
1458+
bool allSteps = ba.m_mode != adios2::Mode::Read &&
1459+
ba.streamStatus ==
1460+
detail::BufferedActions::StreamStatus::ReadWithoutStream;
14601461
switchAdios2VariableType<detail::RetrieveBlocksInfo>(
14611462
datatype,
14621463
parameters,

src/backend/Attributable.cpp

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
#include <complex>
2929
#include <iostream>
3030
#include <set>
31+
#include <sstream>
3132

3233
namespace openPMD
3334
{
@@ -187,6 +188,26 @@ std::string Attributable::MyPath::filePath() const
187188
return directory + seriesName + seriesExtension;
188189
}
189190

191+
std::string Attributable::MyPath::openPMDPath() const
192+
{
193+
if (group.empty())
194+
{
195+
return std::string();
196+
}
197+
else
198+
{
199+
std::stringstream res;
200+
auto it = group.begin();
201+
auto end = group.end();
202+
res << *it++;
203+
for (; it != end; ++it)
204+
{
205+
res << '/' << *it;
206+
}
207+
return res.str();
208+
}
209+
}
210+
190211
auto Attributable::myPath() const -> MyPath
191212
{
192213
MyPath res;

test/SerialIOTest.cpp

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5096,6 +5096,39 @@ bool areEqual(T a, T b)
50965096
} // namespace epsilon
50975097

50985098
#if openPMD_HAVE_ADIOS2
5099+
5100+
#define openPMD_VERBOSE_CHUNKS 0
5101+
5102+
#if openPMD_VERBOSE_CHUNKS
5103+
static std::string format_chunk(ChunkInfo const &chunk_info)
5104+
{
5105+
std::stringstream result;
5106+
auto print_vector = [&result](auto const &vec) {
5107+
if (vec.empty())
5108+
{
5109+
result << "[]";
5110+
}
5111+
else
5112+
{
5113+
auto it = vec.begin();
5114+
result << '[' << *it++;
5115+
auto end = vec.end();
5116+
for (; it != end; ++it)
5117+
{
5118+
result << ',' << *it;
5119+
}
5120+
result << ']';
5121+
}
5122+
};
5123+
result << '(';
5124+
print_vector(chunk_info.offset);
5125+
result << '|';
5126+
print_vector(chunk_info.extent);
5127+
result << ')';
5128+
return result.str();
5129+
}
5130+
#endif
5131+
50995132
TEST_CASE("git_adios2_sample_test", "[serial][adios2]")
51005133
{
51015134
using namespace epsilon;
@@ -5105,11 +5138,73 @@ TEST_CASE("git_adios2_sample_test", "[serial][adios2]")
51055138

51065139
std::string const samplePath =
51075140
"../samples/git-sample/3d-bp4/example-3d-bp4.bp";
5141+
std::string const samplePathFilebased =
5142+
"../samples/git-sample/3d-bp4/example-3d-bp4_%T.bp";
51085143
if (!auxiliary::directory_exists(samplePath))
51095144
{
51105145
std::cerr << "git sample '" << samplePath << "' not accessible \n";
51115146
return;
51125147
}
5148+
5149+
/*
5150+
* This checks a regression introduced by
5151+
* https://github.com/openPMD/openPMD-api/pull/1498 and fixed by
5152+
* https://github.com/openPMD/openPMD-api/pull/1586
5153+
*/
5154+
for (auto const &[filepath, access] :
5155+
{std::make_pair(samplePath, Access::READ_ONLY),
5156+
std::make_pair(samplePathFilebased, Access::READ_ONLY),
5157+
std::make_pair(samplePath, Access::READ_LINEAR),
5158+
std::make_pair(samplePathFilebased, Access::READ_LINEAR)})
5159+
{
5160+
Series read(filepath, access);
5161+
5162+
// false positive by clang-tidy?
5163+
// NOLINTNEXTLINE(performance-for-range-copy)
5164+
for (auto iteration : read.readIterations())
5165+
{
5166+
for (auto &mesh : iteration.meshes)
5167+
{
5168+
for (auto &component : mesh.second)
5169+
{
5170+
#if openPMD_VERBOSE_CHUNKS
5171+
std::cout << "Chunks for '"
5172+
<< component.second.myPath().openPMDPath()
5173+
<< "':" << std::endl;
5174+
for (auto const &chunk : component.second.availableChunks())
5175+
{
5176+
std::cout << "\t" << format_chunk(chunk) << std::endl;
5177+
}
5178+
#else
5179+
component.second.availableChunks();
5180+
#endif
5181+
}
5182+
}
5183+
for (auto &particle_species : iteration.particles)
5184+
{
5185+
for (auto &record : particle_species.second)
5186+
{
5187+
for (auto &component : record.second)
5188+
{
5189+
#if openPMD_VERBOSE_CHUNKS
5190+
std::cout << "Chunks for '"
5191+
<< component.second.myPath().openPMDPath()
5192+
<< "':" << std::endl;
5193+
for (auto const &chunk :
5194+
component.second.availableChunks())
5195+
{
5196+
std::cout << "\t" << format_chunk(chunk)
5197+
<< std::endl;
5198+
}
5199+
#else
5200+
component.second.availableChunks();
5201+
#endif
5202+
}
5203+
}
5204+
}
5205+
}
5206+
}
5207+
51135208
Series o(samplePath, Access::READ_ONLY, R"({"backend": "adios2"})");
51145209
REQUIRE(o.openPMD() == "1.1.0");
51155210
REQUIRE(o.openPMDextension() == 0);

0 commit comments

Comments
 (0)