Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
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 
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,
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 
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 }
int main(int narg, char **arg)
Definition: coloring1.cpp:164
common code used by tests
int checkErrorCode(Teuchos::RCP< const Teuchos::Comm< int > > &comm, int code)
Definition: Environment.cpp:28
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
getCoordinate function set the machine coordinate xyz of any rank process return true if coordinates ...
SparseMatrixAdapter_t::part_t part_t
int getMachineDim() const
returns the dimension (number of coords per node) in the machine
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
getProcDim function set the coordinates of all ranks allCoords[i][j], i=0,...,getMachineDim(), j=0,...,getNumRanks(), is the i-th dimensional coordinate for rank j. return true if coordinates are available for all ranks
int getNumRanks() const
return the number of ranks.
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
Tpetra::Map::local_ordinal_type zlno_t
static const std::string fail
#define TEST_FAIL_AND_RETURN_VALUE(comm, ok, s, rc)
bool hasMachineCoordinates() const
indicates whether or not the machine has coordinates
bool getMyMachineCoordinate(pcoord_t *xyz) const
getMyCoordinate function set the machine coordinate xyz of the current process return true if current...
int checkAllCoords(const Teuchos::Comm< int > &comm, const Zoltan2::MachineRepresentation< nCoord_t, part_t > &mach)
Definition: Machine.cpp:18
bool getMachineExtent(int *nxyz) const
sets the number of unique coordinates in each machine dimension