Skip to content

Commit

Permalink
Move ADIOS2 version macros to their own header
Browse files Browse the repository at this point in the history
  • Loading branch information
franzpoeschel committed Jun 19, 2023
1 parent 6c3d75b commit 07a32cd
Show file tree
Hide file tree
Showing 4 changed files with 55 additions and 43 deletions.
17 changes: 3 additions & 14 deletions include/openPMD/IO/ADIOS/ADIOS2Auxiliary.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
#pragma once

#include "openPMD/Error.hpp"
#include "openPMD/IO/ADIOS/macros.hpp"
#include "openPMD/config.hpp"

#if openPMD_HAVE_ADIOS2
Expand All @@ -35,18 +36,6 @@
#include <stdexcept>
#include <utility>
#include <vector>

/*
* ADIOS2 v2.8 brings mode::ReadRandomAccess
*/
#define HAS_ADIOS_2_8 (ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 208)
/*
* ADIOS2 v2.9 brings modifiable attributes (technically already in v2.8, but
* there are too many bugs, so we only support it beginning with v2.9).
* Group table feature requires ADIOS2 v2.9.
*/
#define HAS_ADIOS_2_9 (ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209)

#endif

namespace openPMD
Expand Down Expand Up @@ -150,7 +139,7 @@ namespace detail
case adios2::Mode::Write:
return false;
case adios2::Mode::Read:
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
case adios2::Mode::ReadRandomAccess:
#endif
return true;
Expand All @@ -169,7 +158,7 @@ namespace detail
case adios2::Mode::Write:
return true;
case adios2::Mode::Read:
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
case adios2::Mode::ReadRandomAccess:
#endif
return false;
Expand Down
27 changes: 27 additions & 0 deletions include/openPMD/IO/ADIOS/macros.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
#pragma once

#include "openPMD/config.hpp"

#if openPMD_HAVE_ADIOS2

#include <adios2.h>

/*
* ADIOS2 v2.8 brings mode::ReadRandomAccess
*/
#define openPMD_HAS_ADIOS_2_8 \
(ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 208)
/*
* ADIOS2 v2.9 brings modifiable attributes (technically already in v2.8, but
* there are too many bugs, so we only support it beginning with v2.9).
* Group table feature requires ADIOS2 v2.9.
*/
#define openPMD_HAS_ADIOS_2_9 \
(ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209)

#else

#define openPMD_HAS_ADIOS_2_8 0
#define openPMD_HAS_ADIOS_2_9 0

#endif
22 changes: 11 additions & 11 deletions src/IO/ADIOS/ADIOS2IOHandler.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ void ADIOS2IOHandlerImpl::init(json::TracingJSON cfg)
defaultOperators = std::move(operators.value());
}
}
#if !HAS_ADIOS_2_9
#if !openPMD_HAS_ADIOS_2_9
if (m_modifiableAttributes == ModifiableAttributes::Yes)
{
throw error::OperationUnsupportedInBackend(
Expand Down Expand Up @@ -879,7 +879,7 @@ void ADIOS2IOHandlerImpl::writeDataset(
void ADIOS2IOHandlerImpl::writeAttribute(
Writable *writable, const Parameter<Operation::WRITE_ATT> &parameters)
{
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
switch (useGroupTable())
{
case UseGroupTable::No:
Expand Down Expand Up @@ -1354,7 +1354,7 @@ adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode(std::string const &fullPath)
{
case Access::CREATE:
return adios2::Mode::Write;
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
case Access::READ_LINEAR:
return adios2::Mode::Read;
case Access::READ_ONLY:
Expand All @@ -1368,7 +1368,7 @@ adios2::Mode ADIOS2IOHandlerImpl::adios2AccessMode(std::string const &fullPath)
if (auxiliary::directory_exists(fullPath) ||
auxiliary::file_exists(fullPath))
{
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
return adios2::Mode::ReadRandomAccess;
#else
return adios2::Mode::Read;
Expand Down Expand Up @@ -1707,7 +1707,7 @@ namespace detail
adios2::IO IO = filedata.m_IO;
impl->m_dirty.emplace(std::move(file));

#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
if (impl->m_modifiableAttributes ==
ADIOS2IOHandlerImpl::ModifiableAttributes::No &&
parameters.changesOverSteps ==
Expand Down Expand Up @@ -1773,7 +1773,7 @@ namespace detail
}

auto &value = std::get<T>(parameters.resource);
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
bool modifiable = impl->m_modifiableAttributes ==
ADIOS2IOHandlerImpl::ModifiableAttributes::Yes ||
parameters.changesOverSteps !=
Expand All @@ -1787,7 +1787,7 @@ namespace detail

auto defineAttribute =
[&IO, &fullName, &modifiable, &impl](auto const &...args) {
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
auto attr = IO.DefineAttribute(
fullName,
args...,
Expand Down Expand Up @@ -2333,7 +2333,7 @@ namespace detail
* BP3 or HDF5, or by BP5 without group table and normal read
* mode. Need to fall back to random access parsing.
*/
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
m_mode = adios2::Mode::ReadRandomAccess;
#endif
break;
Expand Down Expand Up @@ -2411,7 +2411,7 @@ namespace detail
if (writeOnly(m_mode))
{

#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
if (!m_impl->m_useGroupTable.has_value())
{
switch (m_impl->m_iterationEncoding)
Expand Down Expand Up @@ -2726,7 +2726,7 @@ namespace detail
adios2::Engine(m_IO.Open(m_file, tempMode)));
break;
}
#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_8
case adios2::Mode::ReadRandomAccess:
#endif
case adios2::Mode::Read: {
Expand Down Expand Up @@ -3293,7 +3293,7 @@ namespace detail
case UseGroupTable::No:
break;
case UseGroupTable::Yes:
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
{
if (writeOnly(m_mode))
{
Expand Down
32 changes: 14 additions & 18 deletions test/SerialIOTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,12 @@
#define OPENPMD_protected public:
#endif

#include "openPMD/IO/ADIOS/macros.hpp"
#include "openPMD/auxiliary/Environment.hpp"
#include "openPMD/auxiliary/Filesystem.hpp"
#include "openPMD/auxiliary/StringManip.hpp"
#include "openPMD/openPMD.hpp"

#if openPMD_HAVE_ADIOS2
#include <adios2.h>
#define HAS_ADIOS_2_8 (ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209)
#define HAS_ADIOS_2_9 (ADIOS2_VERSION_MAJOR * 100 + ADIOS2_VERSION_MINOR >= 209)
#endif
#include <catch2/catch.hpp>

#include <algorithm>
Expand Down Expand Up @@ -563,9 +559,9 @@ TEST_CASE("close_iteration_interleaved_test", "[serial]")
// run this test for ADIOS2 & JSON only
if (t == "h5")
continue;
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
close_iteration_interleaved_test(t, IterationEncoding::variableBased);
#endif // HAS_ADIOS_2_9
#endif // openPMD_HAS_ADIOS_2_9
}
}

Expand Down Expand Up @@ -4903,7 +4899,7 @@ TEST_CASE("bp4_steps", "[serial][adios2]")
// dontUseSteps,
// Access::READ_LINEAR);

#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
/*
* Do this whole thing once more, but this time use the new attribute
* layout.
Expand Down Expand Up @@ -5350,7 +5346,7 @@ TEST_CASE("git_adios2_sample_test", "[serial][adios2]")
}
}

#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
void adios2_group_table(
std::string const &jsonWrite,
std::string const &jsonRead,
Expand Down Expand Up @@ -5699,7 +5695,7 @@ TEST_CASE("variableBasedParticleData", "[serial][adios2]")
{
variableBasedParticleData();
}
#endif // HAS_ADIOS_2_9
#endif // openPMD_HAS_ADIOS_2_9
#endif // openPMD_HAS_ADIOS2

#if openPMD_HAVE_ADIOS2
Expand Down Expand Up @@ -6025,7 +6021,7 @@ TEST_CASE("iterate_nonstreaming_series", "[serial][adios2]")
}
#endif
}
#if openPMD_HAVE_ADIOS2 && HAS_ADIOS_2_9
#if openPMD_HAVE_ADIOS2 && openPMD_HAS_ADIOS_2_9
iterate_nonstreaming_series(
"../samples/iterate_nonstreaming_series_variablebased.bp",
true,
Expand Down Expand Up @@ -6404,7 +6400,7 @@ TEST_CASE("deferred_parsing", "[serial]")
}
}

#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
void chaotic_stream(std::string filename, bool variableBased)
{
/*
Expand Down Expand Up @@ -6482,7 +6478,7 @@ TEST_CASE("chaotic_stream", "[serial]")
chaotic_stream("../samples/chaotic_stream_vbased." + t, true);
}
}
#endif // HAS_ADIOS_2_9
#endif // openPMD_HAS_ADIOS_2_9

#ifdef openPMD_USE_INVASIVE_TESTS
void unfinished_iteration_test(
Expand Down Expand Up @@ -6598,7 +6594,7 @@ TEST_CASE("unfinished_iteration_test", "[serial]")
#if openPMD_HAVE_ADIOS2
unfinished_iteration_test(
"bp", IterationEncoding::groupBased, R"({"backend": "adios2"})");
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
unfinished_iteration_test(
"bp5",
IterationEncoding::variableBased,
Expand All @@ -6611,7 +6607,7 @@ TEST_CASE("unfinished_iteration_test", "[serial]")
}
}
)");
#endif // HAS_ADIOS_2_9
#endif // openPMD_HAS_ADIOS_2_9
unfinished_iteration_test(
"bp", IterationEncoding::fileBased, R"({"backend": "adios2"})");
#endif
Expand Down Expand Up @@ -7098,7 +7094,7 @@ TEST_CASE("append_mode", "[serial]")
false,
ParseMode::LinearWithoutSnapshot,
jsonConfigOld);
#if HAS_ADIOS_2_9
#if openPMD_HAS_ADIOS_2_9
append_mode(
"../samples/append/append_groupbased." + t,
false,
Expand Down Expand Up @@ -7127,7 +7123,7 @@ TEST_CASE("append_mode", "[serial]")
}
}

#if HAS_ADIOS_2_8
#if openPMD_HAS_ADIOS_2_9
void append_mode_filebased(std::string const &extension)
{
std::string jsonConfig = R"END(
Expand Down Expand Up @@ -7207,7 +7203,7 @@ TEST_CASE("append_mode_filebased", "[serial]")
append_mode_filebased(t);
}
}
#endif // HAS_ADIOS_2_8
#endif // openPMD_HAS_ADIOS_2_8

void groupbased_read_write(std::string const &ext)
{
Expand Down

0 comments on commit 07a32cd

Please sign in to comment.