Skip to content

Commit

Permalink
Add rounding error constants for adios2::ops::mdr, beacuse GetAccurac…
Browse files Browse the repository at this point in the history
…y() is limited by rounding errors in MDR
  • Loading branch information
pnorbert committed Dec 5, 2023
1 parent 7cbc6d7 commit 55acaa7
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 18 deletions.
2 changes: 2 additions & 0 deletions source/adios2/common/ADIOSTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -427,6 +427,8 @@ constexpr char MDR[] = "mdr";

namespace mdr
{
constexpr double DOUBLE_ROUNDING_ERROR_LIMIT = 5.0e-16;
constexpr double FLOAT_ROUNDING_ERROR_LIMIT = 3.0e-7;
namespace key
{}
}
Expand Down
11 changes: 10 additions & 1 deletion source/adios2/operator/refactor/RefactorMDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,16 @@ size_t RefactorMDR::ReconstructV1(const char *bufferIn, const size_t sizeIn, cha
std::cout << ")\n";
}*/

m_AccuracyProvided.error = m_AccuracyRequested.error;
if (type == DataType::FloatComplex || type == DataType::Float)
{
m_AccuracyProvided.error =
std::max(m_AccuracyRequested.error, adios2::ops::mdr::FLOAT_ROUNDING_ERROR_LIMIT);
}
else
{
m_AccuracyProvided.error =
std::max(m_AccuracyRequested.error, adios2::ops::mdr::DOUBLE_ROUNDING_ERROR_LIMIT);
}
m_AccuracyProvided.norm = m_AccuracyRequested.norm;
m_AccuracyProvided.relative = false; // should be m_AccuracyRequested.relative

Expand Down
38 changes: 21 additions & 17 deletions testing/adios2/engine/bp/operations/TestBPWriteReadMGARDMDR.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,6 @@ class BPWriteReadMGARDMDR : public ::testing::TestWithParam<std::string>
virtual void TearDown(){};
};

constexpr double DOUBLE_ERROR_TOLERANCE = 5.0e-16;
constexpr float FLOAT_ERROR_TOLERANCE = 3.0e-7;

TEST_F(BPWriteReadMGARDMDR, BPWRMGARD1D)
{
// Refactor a dataset with MDR, then
Expand Down Expand Up @@ -141,15 +138,19 @@ TEST_F(BPWriteReadMGARDMDR, BPWRMGARD1D)
bpReader.Get(var_r32, read32s, adios2::Mode::Sync);
bpReader.Get(var_r64, read64s, adios2::Mode::Sync);

auto accuracyGot = var_r32.GetAccuracy();
assert(accuracyGot.error == accuracyRequested.error);
assert(accuracyGot.norm == accuracyRequested.norm);
assert(accuracyGot.relative == accuracyRequested.relative);
auto accuracyGot32 = var_r32.GetAccuracy();
assert(accuracyGot32.error <=
std::max(accuracyRequested.error,
adios2::ops::mdr::FLOAT_ROUNDING_ERROR_LIMIT));
assert(accuracyGot32.norm == accuracyRequested.norm);
assert(accuracyGot32.relative == accuracyRequested.relative);

accuracyGot = var_r64.GetAccuracy();
assert(accuracyGot.error == accuracyRequested.error);
assert(accuracyGot.norm == accuracyRequested.norm);
assert(accuracyGot.relative == accuracyRequested.relative);
auto accuracyGot64 = var_r64.GetAccuracy();
assert(accuracyGot64.error <=
std::max(accuracyRequested.error,
adios2::ops::mdr::DOUBLE_ROUNDING_ERROR_LIMIT));
assert(accuracyGot64.norm == accuracyRequested.norm);
assert(accuracyGot64.relative == accuracyRequested.relative);

double maxDiff = 0.0, relativeMaxDiff = 0.0;
size_t maxDiffPos = 0;
Expand All @@ -167,26 +168,29 @@ TEST_F(BPWriteReadMGARDMDR, BPWRMGARD1D)
auto r64s_Max = std::max_element(r64s.begin(), r64s.end());
relativeMaxDiff = maxDiff / *r64s_Max;
std::cout << "double array: Relative Max Diff " << relativeMaxDiff << " Max Diff "
<< maxDiff << " requested error " << error << " max diff pos "
<< maxDiffPos << " orig value " << r64s[maxDiffPos] << " read value "
<< read64s[maxDiffPos] << "\n";
ASSERT_LE(maxDiff, error + DOUBLE_ERROR_TOLERANCE);
<< maxDiff << " requested error " << error << " result error "
<< accuracyGot64.error << " max diff pos " << maxDiffPos << " orig value "
<< r64s[maxDiffPos] << " read value " << read64s[maxDiffPos] << "\n";
ASSERT_LE(maxDiff, accuracyGot64.error);

for (size_t i = 0; i < Nx; ++i)
{
double diff = std::abs(r32s[i] - read32s[i]);
if (diff > maxDiff)
{
maxDiff = diff;
maxDiffPos = i;
}
}

auto r32s_Max = std::max_element(r32s.begin(), r32s.end());
relativeMaxDiff = maxDiff / *r32s_Max;

std::cout << "float array: Relative Max Diff " << relativeMaxDiff << " Max Diff "
<< maxDiff << " requested error " << error << "\n";
ASSERT_LE(maxDiff, error + FLOAT_ERROR_TOLERANCE);
<< maxDiff << " requested error " << error << " result error "
<< accuracyGot32.error << " max diff pos " << maxDiffPos << " orig value "
<< r32s[maxDiffPos] << " read value " << read32s[maxDiffPos] << "\n";
ASSERT_LE(maxDiff, accuracyGot32.error);
}
bpReader.EndStep();
++t;
Expand Down

0 comments on commit 55acaa7

Please sign in to comment.