-
Notifications
You must be signed in to change notification settings - Fork 1
/
verifier.hpp
47 lines (41 loc) · 1.67 KB
/
verifier.hpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#pragma once
#include "utils.hpp"
template < typename value_type >
bool compare_below_threshold(value_type expected, value_type actual, double precision) {
if (std::fabs(expected) < 1e-3 && std::fabs(actual) < 1e-3) {
if (std::fabs(expected - actual) < precision)
return true;
} else {
if (std::fabs((expected - actual) / (precision * expected)) < 1.0)
return true;
}
return false;
}
struct verifier {
IJKSize m_domain;
IJKSize m_halo;
IJKSize m_strides;
double m_precision;
verifier(IJKSize domain, IJKSize halo, double precision) : m_domain(domain), m_halo(halo), m_precision(precision) {
compute_strides(m_domain, halo, m_strides);
}
bool verify(Real* expected_field, Real* actual_field)
{
bool verified = true;
for (unsigned int k = 0; k < m_domain.m_k; ++k) {
for (unsigned int i = m_halo.m_i; i < m_domain.m_i - m_halo.m_i; ++i) {
for (unsigned int j = m_halo.m_j; j < m_domain.m_j - m_halo.m_j; ++j) {
Real expected = expected_field[index(i,j,k, m_strides)];
Real actual = actual_field[index(i,j,k,m_strides)];
if (!compare_below_threshold(expected, actual, m_precision)) {
std::cout << "Error in position " << i << " " << j << " " << k
<< " ; expected : " << expected << " ; actual : " << actual << " "
<< std::fabs((expected - actual) / (expected)) << std::endl;
verified=false;
}
}
}
}
return verified;
}
};