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

Added support for std::complex types #797

Merged
merged 4 commits into from
Aug 14, 2018
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
2 changes: 2 additions & 0 deletions source/adios2/helper/adiosMath.inl
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ template <class T>
void GetMinMaxComplex(const std::complex<T> *values, const size_t size,
std::complex<T> &min, std::complex<T> &max) noexcept
{
min = values[0];
max = values[0];

T minNorm = std::norm(values[0]);
T maxNorm = minNorm;
Expand Down
9 changes: 3 additions & 6 deletions source/adios2/toolkit/format/bp3/BP3Base.tcc
Original file line number Diff line number Diff line change
Expand Up @@ -342,8 +342,7 @@ BP3Base::ParseCharacteristics(const std::vector<char> &buffer, size_t &position,
if (characteristics.Count.empty() || characteristics.Count[0] == 1)
{
characteristics.Statistics.Value =
helper::ReadValue<typename TypeInfo<T>::ValueType>(
buffer, position);
helper::ReadValue<T>(buffer, position);
characteristics.Statistics.IsValue = true;
}
else // used for attributes
Expand All @@ -360,16 +359,14 @@ BP3Base::ParseCharacteristics(const std::vector<char> &buffer, size_t &position,
case (characteristic_min):
{
characteristics.Statistics.Min =
helper::ReadValue<typename TypeInfo<T>::ValueType>(buffer,
position);
helper::ReadValue<T>(buffer, position);
break;
}

case (characteristic_max):
{
characteristics.Statistics.Max =
helper::ReadValue<typename TypeInfo<T>::ValueType>(buffer,
position);
helper::ReadValue<T>(buffer, position);
break;
}

Expand Down
31 changes: 30 additions & 1 deletion source/adios2/toolkit/format/bp3/BP3Serializer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1221,8 +1221,37 @@ void BP3Serializer::MergeSerializeIndices(
break;
}

case (type_complex):
{
auto characteristics = ReadElementIndexCharacteristics<double>(
buffer, position, type_complex, true);
count = characteristics.EntryCount;
length = characteristics.EntryLength;
timeStep = characteristics.Statistics.Step;
break;
}

case (type_double_complex):
{
auto characteristics = ReadElementIndexCharacteristics<double>(
buffer, position, type_double_complex, true);
count = characteristics.EntryCount;
length = characteristics.EntryLength;
timeStep = characteristics.Statistics.Step;
break;
}

case (type_long_double_complex):
{
auto characteristics = ReadElementIndexCharacteristics<double>(
buffer, position, type_long_double_complex, true);
count = characteristics.EntryCount;
length = characteristics.EntryLength;
timeStep = characteristics.Statistics.Step;
break;
}

default:
// TODO: complex, long double
throw std::invalid_argument(
"ERROR: type " + std::to_string(dataType) +
" not supported in BP3 Metadata Merge\n");
Expand Down
10 changes: 10 additions & 0 deletions source/utils/bpls2/bpls2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1335,6 +1335,10 @@ int getTypeInfo(enum ADIOS_DATATYPES adiosvartype, int *elemsize)
*elemsize = 16;
break;

case adios_long_double_complex:
*elemsize = 32;
break;

case adios_long_double: // do not know how to print
//*elemsize = 16;
default:
Expand Down Expand Up @@ -1971,6 +1975,7 @@ const std::map<std::string, enum ADIOS_DATATYPES> adios_types_map = {
{"double", adios_double},
{"float complex", adios_complex},
{"double complex", adios_double_complex},
{"long double complex", adios_long_double_complex},
{"signed char", adios_byte},
{"short", adios_short},
{"long int", adios_long},
Expand Down Expand Up @@ -2330,6 +2335,11 @@ int print_data(const void *data, int item, enum ADIOS_DATATYPES adiosvartype,
((double *)data)[2 * item + 1]);
break;

case adios_long_double_complex:
fprintf(outf, (f ? fmt : "(%Lg,i%Lg)"), ((long double *)data)[2 * item],
((long double *)data)[2 * item + 1]);
break;

default:
break;
} // end switch
Expand Down
3 changes: 2 additions & 1 deletion source/utils/bpls2/bpls2.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ enum ADIOS_DATATYPES
adios_string = 9,
adios_complex = 10,
adios_double_complex = 11,
adios_string_array = 12
adios_string_array = 12,
adios_long_double_complex = 13
};

struct Entry
Expand Down
53 changes: 53 additions & 0 deletions testing/adios2/engine/SmallTestData.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,32 @@ 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<std::complex<float>, 10> CR32 = {
{std::complex<float>(0.1f, 1.1f), std::complex<float>(1.1f, 2.1f),
std::complex<float>(2.1f, 3.1f), std::complex<float>(3.1f, 4.1f),
std::complex<float>(4.1f, 5.1f), std::complex<float>(5.1f, 6.1f),
std::complex<float>(6.1f, 7.1f), std::complex<float>(7.1f, 8.1f),
std::complex<float>(8.1f, 9.1f), std::complex<float>(9.1f, 10.1f)}};

std::array<std::complex<double>, 10> CR64 = {
{std::complex<double>(10.2, 11.2), std::complex<double>(11.2, 12.2),
std::complex<double>(12.2, 13.2), std::complex<double>(13.2, 14.2),
std::complex<double>(14.2, 15.2), std::complex<double>(15.2, 16.2),
std::complex<double>(16.2, 17.2), std::complex<double>(17.2, 18.2),
std::complex<double>(18.2, 19.2), std::complex<double>(19.2, 20.2)}};

std::array<std::complex<long double>, 10> CRLD = {
{std::complex<long double>(10.2, 11.2),
std::complex<long double>(11.2, 12.2),
std::complex<long double>(12.2, 13.2),
std::complex<long double>(13.2, 14.2),
std::complex<long double>(14.2, 15.2),
std::complex<long double>(15.2, 16.2),
std::complex<long double>(16.2, 17.2),
std::complex<long double>(17.2, 18.2),
std::complex<long double>(18.2, 19.2),
std::complex<long double>(19.2, 20.2)}};
};

SmallTestData generateNewSmallTestData(SmallTestData in, int step, int rank,
Expand All @@ -63,6 +89,19 @@ SmallTestData generateNewSmallTestData(SmallTestData in, int step, int rank,
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.CR32.begin(), in.CR32.end(), [&](std::complex<float> &v) {
v.real(v.real() + static_cast<float>(j));
v.imag(v.imag() + static_cast<float>(j));
});
std::for_each(in.CR64.begin(), in.CR64.end(), [&](std::complex<double> &v) {
v.real(v.real() + static_cast<double>(j));
v.imag(v.imag() + static_cast<double>(j));
});
std::for_each(in.CRLD.begin(), in.CRLD.end(),
[&](std::complex<long double> &v) {
v.real(v.real() + static_cast<long double>(j));
v.imag(v.imag() + static_cast<long double>(j));
});
return in;
}

Expand All @@ -79,6 +118,20 @@ 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.CR32.begin(), in.CR32.end(), [&](std::complex<float> &v) {
v.real(v.real() + static_cast<float>(j));
v.imag(v.imag() + static_cast<float>(j));
});
std::for_each(in.CR64.begin(), in.CR64.end(), [&](std::complex<double> &v) {
v.real(v.real() + static_cast<double>(j));
v.imag(v.imag() + static_cast<double>(j));
});
std::for_each(in.CRLD.begin(), in.CRLD.end(),
[&](std::complex<long double> &v) {
v.real(v.real() + static_cast<long double>(j));
v.imag(v.imag() + static_cast<long double>(j));
});
}

#endif // TESTING_ADIOS2_ENGINE_SMALLTESTDATA_H_
Loading