Skip to content

Commit 4e69a6e

Browse files
committed
WIP: Tie things together
1 parent efc72b0 commit 4e69a6e

File tree

3 files changed

+108
-6
lines changed

3 files changed

+108
-6
lines changed

include/openPMD/IO/ADIOS/ADIOS2File.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -415,6 +415,10 @@ class ADIOS2File
415415
{
416416
return m_attributes;
417417
}
418+
[[nodiscard]] detail::AdiosAttributes &attributes()
419+
{
420+
return m_attributes;
421+
}
418422

419423
private:
420424
ADIOS2IOHandlerImpl *m_impl;

include/openPMD/IO/ADIOS/ADIOS2PreloadAttributes.hpp

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,18 +22,14 @@
2222

2323
#include "openPMD/auxiliary/Variant.hpp"
2424
#include "openPMD/config.hpp"
25+
#include <optional>
2526
#include <variant>
2627
#if openPMD_HAVE_ADIOS2
2728

2829
#include <adios2.h>
29-
#include <functional>
3030
#include <map>
31-
#include <sstream>
32-
#include <stddef.h>
33-
#include <type_traits>
3431

3532
#include "openPMD/Datatype.hpp"
36-
#include "openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp"
3733

3834
namespace openPMD::detail
3935
{

src/IO/ADIOS/ADIOS2IOHandler.cpp

Lines changed: 103 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1291,7 +1291,7 @@ namespace
12911291

12921292
if (type == determineDatatype<rep>())
12931293
{
1294-
auto meta = IO.InquireAttribute<rep>(metaAttr);
1294+
auto meta = IO.template InquireAttribute<rep>(metaAttr);
12951295
if (meta.Data().size() == 1 && meta.Data()[0] == 1)
12961296
{
12971297
std::forward<Functor>(fun)(
@@ -1427,6 +1427,59 @@ namespace
14271427
static constexpr char const *errorMsg = "ReadAttributeAllsteps";
14281428
};
14291429

1430+
struct ReadAttributeAllstepsFullPreparsing
1431+
{
1432+
struct GetAttribute
1433+
{
1434+
detail::PreloadAdiosAttributes const &p;
1435+
template <typename AdiosType>
1436+
[[nodiscard]] auto call(std::string const &name) const
1437+
-> detail::AttributeWithShapeAndResource<AdiosType>
1438+
{
1439+
return p.getAttribute<AdiosType>(name);
1440+
}
1441+
};
1442+
1443+
template <typename T>
1444+
static void call(
1445+
std::vector<detail::PreloadAdiosAttributes> const &preload,
1446+
adios2::IO &IO,
1447+
std::string const &name,
1448+
Parameter<Operation::READ_ATT_ALLSTEPS>::result_type
1449+
&put_result_here)
1450+
{
1451+
std::vector<T> res;
1452+
res.reserve(preload.size());
1453+
for (auto const &p : preload)
1454+
{
1455+
genericReadAttribute<T>(
1456+
[&res](auto &&val) {
1457+
using type = std::remove_reference_t<decltype(val)>;
1458+
if constexpr (std::is_same_v<type, bool>)
1459+
{
1460+
throw error::ReadError(
1461+
error::AffectedObject::Attribute,
1462+
error::Reason::UnexpectedContent,
1463+
"ADIOS2",
1464+
"[ReadAttributeAllsteps] No support for "
1465+
"Boolean attributes.");
1466+
}
1467+
else
1468+
{
1469+
res.emplace_back(static_cast<decltype(val)>(val));
1470+
}
1471+
},
1472+
IO,
1473+
name,
1474+
GetAttribute{p});
1475+
}
1476+
put_result_here = std::move(res);
1477+
}
1478+
1479+
static constexpr char const *errorMsg =
1480+
"ReadAttributeAllstepsFullPreparsing";
1481+
};
1482+
14301483
#if openPMD_HAVE_MPI
14311484
struct DistributeToAllRanks
14321485
{
@@ -1561,13 +1614,61 @@ Use Access::READ_LINEAR to retrieve those values if needed.
15611614
}
15621615
} // namespace
15631616

1617+
#define OPENPMD_PREPARSE_EVERYTHING 1
1618+
15641619
void ADIOS2IOHandlerImpl::readAttributeAllsteps(
15651620
Writable *writable, Parameter<Operation::READ_ATT_ALLSTEPS> &param)
15661621
{
15671622
auto file = refreshFileFromParent(writable, /* preferParentFile = */ false);
15681623
auto pos = setAndGetFilePosition(writable);
15691624
auto name = nameOfAttribute(writable, param.name);
15701625

1626+
#if OPENPMD_PREPARSE_EVERYTHING
1627+
detail::ADIOS2File &ba = getFileData(file, IfFileNotOpen::ThrowError);
1628+
#if openPMD_HAVE_MPI
1629+
auto adios = [&]() {
1630+
if (m_communicator.has_value())
1631+
{
1632+
return adios2::ADIOS(*m_communicator);
1633+
}
1634+
else
1635+
{
1636+
return adios2::ADIOS{};
1637+
}
1638+
}();
1639+
#else
1640+
adios2::ADIOS adios;
1641+
#endif
1642+
auto IO = adios.DeclareIO("PreparseSnapshots");
1643+
// @todo check engine type
1644+
IO.SetEngine(realEngineType());
1645+
IO.SetParameter("StreamReader", "ON"); // this be for BP4
1646+
auto engine = IO.Open(fullPath(*file), adios2::Mode::Read);
1647+
std::vector<detail::PreloadAdiosAttributes> preload;
1648+
preload.reserve(engine.Steps());
1649+
adios2::StepStatus status;
1650+
while ((status = engine.BeginStep()) == adios2::StepStatus::OK)
1651+
{
1652+
auto &new_entry = preload.emplace_back();
1653+
new_entry.preloadAttributes(IO);
1654+
engine.EndStep();
1655+
}
1656+
if (status != adios2::StepStatus::EndOfStream)
1657+
{
1658+
throw std::runtime_error(
1659+
"[ADIOS2IOHandlerImpl::readAttributeAllsteps] Unexpected step "
1660+
"status while beginning a step.");
1661+
}
1662+
engine.Close();
1663+
auto &attributes = ba.attributes();
1664+
switchType<ReadAttributeAllstepsFullPreparsing>(
1665+
preload.at(0).attributeType(param.name),
1666+
preload,
1667+
IO,
1668+
param.name,
1669+
*param.resource);
1670+
attributes.m_data = std::move(preload);
1671+
#else
15711672
auto read_from_file_in_serial = [&]() {
15721673
adios2::ADIOS adios;
15731674
auto IO = adios.DeclareIO("PreparseSnapshots");
@@ -1603,6 +1704,7 @@ void ADIOS2IOHandlerImpl::readAttributeAllsteps(
16031704
#else
16041705
read_from_file_in_serial();
16051706
#endif
1707+
#endif
16061708
}
16071709

16081710
void ADIOS2IOHandlerImpl::listPaths(

0 commit comments

Comments
 (0)