Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Zoltan2_TestHelpers.hpp
Go to the documentation of this file.
1
// @HEADER
2
// *****************************************************************************
3
// Zoltan2: A package of combinatorial algorithms for scientific computing
4
//
5
// Copyright 2012 NTESS and the Zoltan2 contributors.
6
// SPDX-License-Identifier: BSD-3-Clause
7
// *****************************************************************************
8
// @HEADER
9
13
#ifndef ZOLTAN2_TESTHELPERS_HPP
14
#define ZOLTAN2_TESTHELPERS_HPP
15
16
#include <Teuchos_UnitTestHarness.hpp>
17
#include <
Zoltan2_Util.hpp
>
18
#include <iostream>
19
20
#include <Tpetra_Map.hpp>
21
typedef
Tpetra::Map<>::node_type
znode_t
;
22
23
// The path to the directory of test data
24
25
#define STR_VALUE(path) #path
26
#define PATH_NAME(path) STR_VALUE(path)
27
28
#ifdef Z2_DATA_DIR
29
std::string
testDataFilePath
(
PATH_NAME
(Z2_DATA_DIR));
30
#else
31
std::string
testDataFilePath
(
"."
);
32
#endif
33
34
// The path to the Zoltan1 test directory. We use
35
// some of their data for testing.
36
37
#ifdef Z1_TEST_DIR
38
std::string
zoltanTestDirectory
(
PATH_NAME
(Z1_TEST_DIR));
39
#else
40
std::string
zoltanTestDirectory
(
"."
);
41
#endif
42
44
//
45
// If Tpetra is compiled with explicit instantiation,
46
// we have to choose data types that are compiled into Tpetra.
47
//
48
49
// TODO: KDD 8/13/14
50
// Global definitions of types gno_t, lno_t, zgid_t and
51
// scalar_t can cause bugs in the code. If a class fails to define these
52
// types, but this file is included before the class file, the types
53
// from Zoltan2_TestHelpers.hpp will be used in the class. Compilation in
54
// user programs (without Zoltan2_TestHelpers.hpp) would then fail. An
55
// example of this bug was in the GeometricGenerator class, which used
56
// scalar_t without defining it.
57
// In this "fix," I changed gno_t, lno_t, zgid_t, scalar_t, and node_t to
58
// zgno_t, zlno_t, zzgid_t, zscalar_t and znode_t in Zoltan2_TestHelpers.hpp.
59
// This change is not the best fix; a better fix would remove the global
60
// definitions, but that would require more work. (An even better change
61
// would use the Teuchos test framework to cycle through various options,
62
// but that would require even more work and should be delayed until we
63
// revamp the testing.)
64
65
#include <TpetraCore_config.h>
66
67
typedef
int
zpart_t
;
// added this for consistency but needs further discussion
68
69
typedef
Tpetra::Map<>::local_ordinal_type
zlno_t
;
70
typedef
Tpetra::Map<>::global_ordinal_type
zgno_t
;
71
72
using
Teuchos::compareArrays;
73
74
#ifdef HAVE_TPETRA_DOUBLE
75
typedef
double
zscalar_t
;
76
#else
77
typedef
float
zscalar_t
;
78
#endif
79
81
82
#define MEMORY_CHECK(iPrint, msg) \
83
if (iPrint) { \
84
long kb = Zoltan2::getProcessKilobytes(); \
85
std::cout.width(10); \
86
std::cout.fill('*'); \
87
std::cout << kb << " KB, " << msg << std::endl; \
88
std::cout.width(0); \
89
std::cout.fill(' '); \
90
}
91
92
#define Z2_TEST(TEST) \
93
{ \
94
Teuchos::RCP<Teuchos::FancyOStream> fout = \
95
Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); \
96
auto &out = *fout; \
97
bool success = true; \
98
try { \
99
TEST; \
100
} catch (...) { \
101
out << "Test failed."; \
102
} \
103
if (!success) { \
104
throw std::runtime_error(#TEST " FAIL"); \
105
} \
106
}
107
108
#define Z2_TEST_THROW(code, ExceptType) Z2_TEST(TEST_THROW(code, ExceptType))
109
#define Z2_TEST_NOTHROW(code) Z2_TEST(TEST_NOTHROW(code))
110
#define Z2_TEST_EQUALITY(val1, val2) Z2_TEST(TEST_EQUALITY(val1, val2))
111
#define Z2_TEST_INEQUALITY(val1, val2) Z2_TEST(TEST_INEQUALITY(val1, val2))
112
#define Z2_TEST_ASSERT(expr) Z2_TEST(TEST_ASSERT(expr))
113
#define Z2_TEST_EQUALITY_CONST(val1, val2) \
114
Z2_TEST(TEST_EQUALITY_CONST(val1, val2))
115
#define Z2_TEST_INEQUALITY_CONST(val1, val2) \
116
Z2_TEST(TEST_INEQUALITY_CONST(val1, val2))
117
#define Z2_TEST_COMPARE(val1, comp, val2) \
118
Z2_TEST(TEST_COMPARE(val1, comp, val2))
119
#define Z2_TEST_COMPARE_ARRAYS(val1, val2) \
120
Z2_TEST(TEST_COMPARE_ARRAYS(val1, val2))
121
#define Z2_TEST_COMPARE_FLOATING_ARRAYS(val1, val2, tol) \
122
Z2_TEST(TEST_COMPARE_FLOATING_ARRAYS(val1, val2, tol))
123
#define Z2_TEST_FLOATING_EQUALITY(val1, val2, tol) \
124
Z2_TEST(TEST_FLOATING_EQUALITY(val1, val2, tol))
125
126
inline
void
PrintFromRoot
(
const
std::string &message) {
127
if
(Tpetra::getDefaultComm()->getRank() == 0) {
128
printf(
"%s \n"
, message.c_str());
129
}
130
}
131
132
template
<
typename
DeviceType,
typename
HostType>
133
void
TestDeviceHostView
(
const
DeviceType &deviceView,
134
const
HostType &hostView) {
135
// Should we test for more dimensions?
136
for
(
int
dim = 0; dim <= 2; ++dim) {
137
Z2_TEST_EQUALITY
(deviceView.extent(dim), hostView.extent(dim));
138
}
139
140
const
auto
mirrorDevice = Kokkos::create_mirror_view(deviceView);
141
Kokkos::deep_copy(mirrorDevice, deviceView);
142
143
// Compare the values element-wise
144
Z2_TEST_COMPARE_ARRAYS
(hostView, mirrorDevice);
145
}
146
147
#define Z2_TEST_DEVICE_HOST_VIEWS(deviceView, hostView) \
148
\
149
{ \
150
for (int dim = 0; dim <= 2; ++dim) { \
151
Z2_TEST_EQUALITY(deviceView.extent(dim), hostView.extent(dim)); \
152
} \
153
\
154
const auto mirrorDevice = Kokkos::create_mirror_view(deviceView); \
155
Kokkos::deep_copy(mirrorDevice, deviceView); \
156
\
157
Z2_TEST_COMPARE_ARRAYS(hostView, mirrorDevice); \
158
}
159
160
#include <
ErrorHandlingForTests.hpp
>
161
#include <
PrintData.hpp
>
162
#include <
UserInputForTests.hpp
>
163
164
#endif
ErrorHandlingForTests.hpp
PrintData.hpp
UserInputForTests.hpp
Generate input for testing purposes.
zscalar_t
float zscalar_t
Definition
Zoltan2_TestHelpers.hpp:77
PrintFromRoot
void PrintFromRoot(const std::string &message)
Definition
Zoltan2_TestHelpers.hpp:126
zoltanTestDirectory
std::string zoltanTestDirectory(".")
zlno_t
Tpetra::Map ::local_ordinal_type zlno_t
Definition
Zoltan2_TestHelpers.hpp:69
testDataFilePath
std::string testDataFilePath(".")
TestDeviceHostView
void TestDeviceHostView(const DeviceType &deviceView, const HostType &hostView)
Definition
Zoltan2_TestHelpers.hpp:133
Z2_TEST_COMPARE_ARRAYS
#define Z2_TEST_COMPARE_ARRAYS(val1, val2)
Definition
Zoltan2_TestHelpers.hpp:119
Z2_TEST_EQUALITY
#define Z2_TEST_EQUALITY(val1, val2)
Definition
Zoltan2_TestHelpers.hpp:110
zpart_t
int zpart_t
Definition
Zoltan2_TestHelpers.hpp:67
zgno_t
Tpetra::Map ::global_ordinal_type zgno_t
Definition
Zoltan2_TestHelpers.hpp:70
znode_t
Tpetra::Map ::node_type znode_t
Definition
Zoltan2_TestHelpers.hpp:21
PATH_NAME
#define PATH_NAME(path)
Definition
Zoltan2_TestHelpers.hpp:26
Zoltan2_Util.hpp
A gathering of useful namespace methods.
test
core
helpers
Zoltan2_TestHelpers.hpp
Generated by
1.17.0