From b62b286c81b22b2152bf3e1cfc462e387c77c79b Mon Sep 17 00:00:00 2001 From: Axel Huebl Date: Wed, 18 Dec 2019 22:00:27 -0800 Subject: [PATCH] Attributes: Allow Complex Types This is a quick hack, but it demonstrates that complex attribute types are no problem, just as in ADIOS1. --- source/adios2/common/ADIOSMacros.h | 10 +++++----- source/adios2/engine/ssc/SscReader.cpp | 18 ++++++++++++++++++ source/adios2/engine/ssc/SscWriter.cpp | 18 ++++++++++++++++++ .../toolkit/format/dataman/DataManSerializer.h | 17 +++++++++++++++++ 4 files changed, 58 insertions(+), 5 deletions(-) diff --git a/source/adios2/common/ADIOSMacros.h b/source/adios2/common/ADIOSMacros.h index ef603ca9dc..ca69fc489c 100644 --- a/source/adios2/common/ADIOSMacros.h +++ b/source/adios2/common/ADIOSMacros.h @@ -52,7 +52,7 @@ #define ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_1ARG(MACRO) \ MACRO(std::string) \ - ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_STDTYPE_1ARG(MACRO) + ADIOS2_FOREACH_PRIMITIVE_STDTYPE_1ARG(MACRO) #define ADIOS2_FOREACH_STDTYPE_1ARG(MACRO) \ MACRO(std::string) \ @@ -214,7 +214,9 @@ MACRO(uint64_t, uint64) \ MACRO(float, float) \ MACRO(double, double) \ - MACRO(long double, ldouble) + MACRO(long double, ldouble) \ + MACRO(std::complex, cfloat) \ + MACRO(std::complex, cdouble) #define ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(MACRO) \ MACRO(int8_t, int8) \ @@ -232,9 +234,7 @@ MACRO(std::complex, cdouble) #define ADIOS2_FOREACH_STDTYPE_2ARGS(MACRO) \ - ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO) \ - MACRO(std::complex, cfloat) \ - MACRO(std::complex, cdouble) + ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO) #define ADIOS2_FOREACH_COMPLEX_TYPE_2ARGS(MACRO) \ MACRO(std::complex, CFloat) \ diff --git a/source/adios2/engine/ssc/SscReader.cpp b/source/adios2/engine/ssc/SscReader.cpp index 1dd079ae7a..3e2bf6c934 100644 --- a/source/adios2/engine/ssc/SscReader.cpp +++ b/source/adios2/engine/ssc/SscReader.cpp @@ -13,6 +13,24 @@ #include "adios2/helper/adiosFunctions.h" #include "nlohmann/json.hpp" +#include + + +// JSON std::complex handling +namespace std +{ +template< class T > +void to_json(nlohmann::json &j, const std::complex< T > &p) { + j = nlohmann::json {p.real(), p.imag()}; +} + +template< class T > +void from_json(const nlohmann::json &j, std::complex< T > &p) { + p.real(j.at(0)); + p.imag(j.at(1)); +} +} // end namespace std + namespace adios2 { namespace core diff --git a/source/adios2/engine/ssc/SscWriter.cpp b/source/adios2/engine/ssc/SscWriter.cpp index 7cea28cd4e..f6c25f26c2 100644 --- a/source/adios2/engine/ssc/SscWriter.cpp +++ b/source/adios2/engine/ssc/SscWriter.cpp @@ -12,6 +12,24 @@ #include "adios2/helper/adiosComm.h" #include "nlohmann/json.hpp" +#include + + +// JSON std::complex handling +namespace std +{ +template< class T > +void to_json(nlohmann::json &j, const std::complex< T > &p) { + j = nlohmann::json {p.real(), p.imag()}; +} + +template< class T > +void from_json(const nlohmann::json &j, std::complex< T > &p) { + p.real(j.at(0)); + p.imag(j.at(1)); +} +} // end namespace std + namespace adios2 { namespace core diff --git a/source/adios2/toolkit/format/dataman/DataManSerializer.h b/source/adios2/toolkit/format/dataman/DataManSerializer.h index 47b079a561..e00c3de39b 100644 --- a/source/adios2/toolkit/format/dataman/DataManSerializer.h +++ b/source/adios2/toolkit/format/dataman/DataManSerializer.h @@ -16,11 +16,28 @@ #include "adios2/helper/adiosComm.h" #include "adios2/toolkit/profiling/taustubs/tautimer.hpp" +#include #include #include #include + +// JSON std::complex handling +namespace std +{ +template< class T > +void to_json(nlohmann::json &j, const std::complex< T > &p) { + j = nlohmann::json {p.real(), p.imag()}; +} + +template< class T > +void from_json(const nlohmann::json &j, std::complex< T > &p) { + p.real(j.at(0)); + p.imag(j.at(1)); +} +} // end namespace std + // A - Address // C - Count // D - Data Object ID or File Name