Zoltan2
Toggle main menu visibility
Loading...
Searching...
No Matches
Machine.cpp
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
10
//
11
// Testing Zoltan2::MachineRepresentation
12
13
#include <
Zoltan2_MachineRepresentation.hpp
>
14
#include <
Zoltan2_TestHelpers.hpp
>
15
#include <Teuchos_DefaultComm.hpp>
16
17
template
<
typename
nCoord_t,
typename
part_t>
18
int
checkAllCoords
(
const
Teuchos::Comm<int> &comm,
19
const
Zoltan2::MachineRepresentation<nCoord_t,part_t>
&mach)
20
{
21
// Verify that getAllMachineCoordinatesView returns the same values
22
// as individual calls by rank.
23
// Verify that returned coordinates lie within the extent of the coordinates.
24
25
int
fail
= 0;
26
const
int
failval = 100000000;
27
28
int
np = comm.getSize();
29
int
me = comm.getRank();
30
31
int
dim = mach.
getMachineDim
();
32
int
*nxyz =
new
int
[dim];
33
34
nCoord_t *xyz =
new
nCoord_t[dim];
35
36
nCoord_t **allCoords;
37
38
bool
haveExtent = mach.
getMachineExtent
(nxyz);
39
40
if
(mach.
getAllMachineCoordinatesView
(allCoords)) {
41
42
// Check all ranks
43
for
(
int
i = 0; i < np; i++) {
44
if
(mach.
getMachineCoordinate
(i, xyz)) {
45
if
(me == 0) std::cout <<
"RANK "
<< i <<
" COORD "
;
46
for
(
int
d = 0; d < dim; d++) {
47
if
(me == 0) std::cout <<
" "
<< xyz[d];
48
if
(xyz[d] != allCoords[d][i])
fail
= failval;
49
if
(haveExtent && (xyz[d] < 0 || xyz[d] >= nxyz[d]))
fail
= failval;
50
}
51
if
(me == 0) std::cout << std::endl;
52
}
53
else
{
54
std::cout <<
"Rank "
<< me
55
<<
" getMachineCoordinate failed "
<< std::endl;
56
fail
= failval;
// getMachineCoordinate failed
57
}
58
}
59
if
(
fail
== failval) {
60
std::cout <<
"Rank "
<< me
61
<<
" Invalid coordinates from getAllMachineCoordinatesView or "
62
<<
"getMachineCoordinate"
<< std::endl;
63
}
64
65
// Check my rank
66
if
(mach.
getMyMachineCoordinate
(xyz)) {
67
for
(
int
d = 0; d < dim; d++)
68
if
(xyz[d] != allCoords[d][me])
fail
= failval;
69
}
70
else
{
71
fail
= failval;
// getMyMachineCoordinate failed
72
std::cout <<
"Rank "
<< me
73
<<
"getMyMachineCoordinates failed"
<< std::endl;
74
}
75
}
76
else
{
77
fail
= failval;
// couldn't retrieve coordinates
78
std::cout <<
"Rank "
<< me
79
<<
"couldn't retrieve coordinates with "
80
<<
"getAllMachineCoordinatesView"
<< std::endl;
81
}
82
83
delete
[] xyz;
84
delete
[] nxyz;
85
86
return
fail
;
87
}
88
90
int
checkErrorCode
(
const
Teuchos::Comm<int> &comm,
int
code)
91
{
92
int
rank = comm.getRank();
93
if
(code > 0)
94
std::cerr <<
"Proc "
<< rank <<
" error: "
<< code << std::endl;
95
comm.barrier();
96
97
// Will return 1 if any process has a non-zero code
98
TEST_FAIL_AND_RETURN_VALUE
(comm, code==0,
"TEST FAILED"
, 1);
99
100
return
0;
101
}
102
104
105
int
main
(
int
narg,
char
*arg[])
106
{
107
Tpetra::ScopeGuard tscope(&narg, &arg);
108
Teuchos::RCP<const Teuchos::Comm<int> > comm = Tpetra::getDefaultComm();
109
110
int
me = comm->getRank();
111
int
np = comm->getSize();
112
//char *name = "node0"; Causes compiler warnings. Do weirdness.
113
char
node0[6] = {
'n'
,
'o'
,
'd'
,
'e'
,
'0'
,
'\0'
};
114
char
*name = node0;
115
int
fail
= 0;
116
117
typedef
zlno_t
ncoord_t;
118
typedef
zlno_t
part_t
;
119
120
Teuchos::ParameterList pl;
121
122
Zoltan2::MachineRepresentation<ncoord_t, part_t>
mach(*comm, pl);
123
124
// Tests that all machines should pass
125
if
(mach.
getNumRanks
() != np)
fail
+= 1;
126
127
if
(mach.
hasMachineCoordinates
())
128
fail
+=
checkAllCoords<ncoord_t,part_t>
(*comm, mach);
129
130
if
(
checkErrorCode
(*comm,
fail
))
131
return
1;
132
133
#if defined(HAVE_ZOLTAN2_LDMS)
134
{
// Add tests specific to LDMS
135
if
(me == 0 ) std::cout <<
"LDMS Topology"
<< std::endl;
136
if
(
checkErrorCode
(*comm,
fail
))
137
return
1;
138
}
139
#elif defined(HAVE_ZOLTAN2_RCALIB)
140
{
141
if
(me == 0 ) std::cout <<
"RCALIB Topology"
<< std::endl;
142
// Add tests specific to RCA
143
if
(
checkErrorCode
(*comm,
fail
))
144
return
1;
145
}
146
#elif defined(HAVE_ZOLTAN2_TOPOMANAGER)
147
{
148
if
(me == 0 ) std::cout <<
"TOPOMANAGER Topology"
<< std::endl;
149
// Add tests specific to TopoMgr
150
if
(
checkErrorCode
(*comm,
fail
))
151
return
1;
152
}
153
#elif defined(HAVE_ZOLTAN2_BGQTEST)
154
{
155
if
(me == 0 ) std::cout <<
"BGQTEST Topology"
<< std::endl;
156
// Add tests specific to BGQ
157
if
(
checkErrorCode
(*comm,
fail
))
158
return
1;
159
}
160
#else
161
{
162
if
(me == 0 ) std::cout <<
"TEST Topology"
<< std::endl;
163
// Tests specific to MachineForTesting
164
if
(mach.
getMachineDim
() != 3) {
165
std::cout <<
"Error: Dimension != 3"
<< std::endl;
166
fail
+= 10;
167
}
168
169
int
nxyz[3];
170
if
(!mach.
getMachineExtent
(nxyz)) {
171
std::cout <<
"Error: getMachineExtent failed"
<< std::endl;
172
fail
+= 100;
173
}
174
if
(nxyz[0] != np || nxyz[1] != 2*np || nxyz[2] != 3*np) {
175
// Depends on ficticious extent in Zoltan2_MachineForTesting.hpp
176
std::cout <<
"Error: incorrect MachineExtent"
<< std::endl;
177
fail
+= 1000;
178
}
179
180
ncoord_t xyz[3];
181
182
// Depends on ficticious coordinates in Zoltan2_MachineForTesting.hpp
183
ncoord_t xyz_expected[3] = {me, np, np+1};
184
185
if
(!mach.
getMyMachineCoordinate
(xyz)) {
186
std::cout <<
"Error: getMyMachineCoordinate failed"
<< std::endl;
187
fail
+= 1000;
188
}
189
190
if
((xyz[0] != xyz_expected[0]) ||
191
(xyz[1] != xyz_expected[1]) ||
192
(xyz[2] != xyz_expected[2])) {
193
std::cout <<
"Error: incorrect MyMachineCoordinate"
<< std::endl;
194
fail
+= 10000;
195
}
196
197
// MachineForTesting cannot retrieve coords by node name
198
if
(mach.
getMachineCoordinate
(name, xyz)) {
199
std::cout <<
"Error: getMachineCoordinate failed"
<< std::endl;
200
fail
+= 10000000;
201
}
202
203
if
(
checkErrorCode
(*comm,
fail
))
204
return
1;
205
}
206
#endif
207
208
if
(me == 0) std::cout <<
"PASS"
<< std::endl;
209
210
return
0;
211
}
TEST_FAIL_AND_RETURN_VALUE
#define TEST_FAIL_AND_RETURN_VALUE(comm, ok, s, rc)
Definition
ErrorHandlingForTests.hpp:60
checkAllCoords
int checkAllCoords(const Teuchos::Comm< int > &comm, const Zoltan2::MachineRepresentation< nCoord_t, part_t > &mach)
Definition
Machine.cpp:18
checkErrorCode
int checkErrorCode(const Teuchos::Comm< int > &comm, int code)
Definition
Machine.cpp:90
Zoltan2_MachineRepresentation.hpp
Zoltan2_TestHelpers.hpp
common code used by tests
zlno_t
Tpetra::Map ::local_ordinal_type zlno_t
Definition
Zoltan2_TestHelpers.hpp:69
main
int main()
Definition
absdefinitiontest.cpp:15
Zoltan2::MachineRepresentation
MachineRepresentation Class Base class for representing machine coordinates, networks,...
Definition
Zoltan2_MachineRepresentation.hpp:34
Zoltan2::MachineRepresentation::getAllMachineCoordinatesView
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
getProcDim function set the coordinates of all ranks allCoords[i][j], i=0,...,getMachineDim(),...
Definition
Zoltan2_MachineRepresentation.hpp:161
Zoltan2::MachineRepresentation::hasMachineCoordinates
bool hasMachineCoordinates() const
indicates whether or not the machine has coordinates
Definition
Zoltan2_MachineRepresentation.hpp:102
Zoltan2::MachineRepresentation::getMachineDim
int getMachineDim() const
returns the dimension (number of coords per node) in the machine
Definition
Zoltan2_MachineRepresentation.hpp:109
Zoltan2::MachineRepresentation::getMachineExtent
bool getMachineExtent(int *nxyz) const
sets the number of unique coordinates in each machine dimension
Definition
Zoltan2_MachineRepresentation.hpp:116
Zoltan2::MachineRepresentation::getNumRanks
int getNumRanks() const
return the number of ranks.
Definition
Zoltan2_MachineRepresentation.hpp:167
Zoltan2::MachineRepresentation::getMyMachineCoordinate
bool getMyMachineCoordinate(pcoord_t *xyz) const
getMyCoordinate function set the machine coordinate xyz of the current process return true if current...
Definition
Zoltan2_MachineRepresentation.hpp:133
Zoltan2::MachineRepresentation::getMachineCoordinate
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
getCoordinate function set the machine coordinate xyz of any rank process return true if coordinates ...
Definition
Zoltan2_MachineRepresentation.hpp:141
fail
static const std::string fail
Definition
findUniqueGids.cpp:45
part_t
SparseMatrixAdapter_t::part_t part_t
Definition
partitioningTree.cpp:39
test
core
unit
environment
Machine.cpp
Generated by
1.17.0