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

Attributes: Allow Complex Types #1909

Merged
merged 2 commits into from
Dec 20, 2019
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
22 changes: 14 additions & 8 deletions source/adios2/common/ADIOSMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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) \
Expand Down Expand Up @@ -147,7 +147,9 @@
MACRO(unsigned long long int) \
MACRO(float) \
MACRO(double) \
MACRO(long double)
MACRO(long double) \
MACRO(std::complex<float>) \
MACRO(std::complex<double>)

#define ADIOS2_FOREACH_ATTRIBUTE_PRIMITIVE_TYPE_1ARG(MACRO) \
MACRO(char) \
Expand All @@ -163,7 +165,9 @@
MACRO(unsigned long long int) \
MACRO(float) \
MACRO(double) \
MACRO(long double)
MACRO(long double) \
MACRO(std::complex<float>) \
MACRO(std::complex<double>)

#define ADIOS2_FOREACH_NUMERIC_ATTRIBUTE_TYPE_1ARG(MACRO) \
MACRO(short) \
Expand All @@ -176,7 +180,9 @@
MACRO(unsigned long long int) \
MACRO(float) \
MACRO(double) \
MACRO(long double)
MACRO(long double) \
MACRO(std::complex<float>) \
MACRO(std::complex<double>)

/**
<pre>
Expand Down Expand Up @@ -214,7 +220,9 @@
MACRO(uint64_t, uint64) \
MACRO(float, float) \
MACRO(double, double) \
MACRO(long double, ldouble)
MACRO(long double, ldouble) \
MACRO(std::complex<float>, cfloat) \
MACRO(std::complex<double>, cdouble)

#define ADIOS2_FOREACH_PRIMITVE_STDTYPE_2ARGS(MACRO) \
MACRO(int8_t, int8) \
Expand All @@ -232,9 +240,7 @@
MACRO(std::complex<double>, cdouble)

#define ADIOS2_FOREACH_STDTYPE_2ARGS(MACRO) \
ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO) \
MACRO(std::complex<float>, cfloat) \
MACRO(std::complex<double>, cdouble)
ADIOS2_FOREACH_ATTRIBUTE_STDTYPE_2ARGS(MACRO)

#define ADIOS2_FOREACH_COMPLEX_TYPE_2ARGS(MACRO) \
MACRO(std::complex<float>, CFloat) \
Expand Down
1 change: 1 addition & 0 deletions source/adios2/engine/ssc/SscReader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
#include "SscReader.tcc"
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosFunctions.h"
#include "adios2/helper/adiosJSONcomplex.h"
#include "nlohmann/json.hpp"

namespace adios2
Expand Down
1 change: 1 addition & 0 deletions source/adios2/engine/ssc/SscWriter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@

#include "SscWriter.tcc"
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosJSONcomplex.h"
#include "nlohmann/json.hpp"

namespace adios2
Expand Down
34 changes: 34 additions & 0 deletions source/adios2/helper/adiosJSONcomplex.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* Distributed under the OSI-approved Apache License, Version 2.0. See
* accompanying file Copyright.txt for details.
*
* adiosYAML.h basic YAML parsing functionality for ADIOS config file schema
*
* Created on: Dec 19, 2019
* Author: Axel Huebl <[email protected]>
*/

#ifndef ADIOS2_HELPER_ADIOSJSONCOMPLEX_H_
#define ADIOS2_HELPER_ADIOSJSONCOMPLEX_H_

#include "nlohmann/json.hpp"
#include <complex>

// JSON std::complex handling
namespace std
{
template <class T>
inline void to_json(nlohmann::json &j, const std::complex<T> &p)
{
j = nlohmann::json{p.real(), p.imag()};
}

template <class T>
inline void from_json(const nlohmann::json &j, std::complex<T> &p)
{
p.real(j.at(0));
p.imag(j.at(1));
}
} // end namespace std

#endif /* ADIOS2_HELPER_ADIOSJSONCOMPLEX_H_ */
1 change: 1 addition & 0 deletions source/adios2/toolkit/format/dataman/DataManSerializer.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
#include "adios2/common/ADIOSTypes.h"
#include "adios2/core/IO.h"
#include "adios2/helper/adiosComm.h"
#include "adios2/helper/adiosJSONcomplex.h"
#include "adios2/toolkit/profiling/taustubs/tautimer.hpp"

#include <mutex>
Expand Down
6 changes: 6 additions & 0 deletions testing/adios2/engine/SmallTestData.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ struct SmallTestData
{0.1f, 1.1f, 2.1f, 3.1f, 4.1f, 5.1f, 6.1f, 7.1f, 8.1f, 9.1f}};
std::array<double, 10> R64 = {
{10.2, 11.2, 12.2, 13.2, 14.2, 15.2, 16.2, 17.2, 18.2, 19.2}};
std::array<long double, 10> R128 = {
{410.2, 411.2, 412.2, 413.2, 414.2, 415.2, 416.2, 417.2, 418.2, 419.2}};

std::array<std::complex<float>, 10> CR32 = {
{std::complex<float>(0.1f, 1.1f), std::complex<float>(1.1f, 2.1f),
Expand Down Expand Up @@ -77,6 +79,8 @@ SmallTestData generateNewSmallTestData(SmallTestData in, int step, int rank,
std::for_each(in.U64.begin(), in.U64.end(), [&](uint64_t &v) { v += j; });
std::for_each(in.R32.begin(), in.R32.end(), [&](float &v) { v += j; });
std::for_each(in.R64.begin(), in.R64.end(), [&](double &v) { v += j; });
std::for_each(in.R128.begin(), in.R128.end(),
[&](long double &v) { v += j; });

std::for_each(in.CR32.begin(), in.CR32.end(), [&](std::complex<float> &v) {
v.real(v.real() + static_cast<float>(j));
Expand All @@ -103,6 +107,8 @@ void UpdateSmallTestData(SmallTestData &in, int step, int rank, int size)
std::for_each(in.U64.begin(), in.U64.end(), [&](uint64_t &v) { v += j; });
std::for_each(in.R32.begin(), in.R32.end(), [&](float &v) { v += j; });
std::for_each(in.R64.begin(), in.R64.end(), [&](double &v) { v += j; });
std::for_each(in.R128.begin(), in.R128.end(),
[&](long double &v) { v += j; });

std::for_each(in.CR32.begin(), in.CR32.end(), [&](std::complex<float> &v) {
v.real(v.real() + static_cast<float>(j));
Expand Down
Loading