Zoltan2
Machine.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // Zoltan2: A package of combinatorial algorithms for scientific computing
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact Karen Devine (kddevin@sandia.gov)
39 // Erik Boman (egboman@sandia.gov)
40 // Siva Rajamanickam (srajama@sandia.gov)
41 //
42 // ***********************************************************************
43 //
44 // @HEADER
45 //
46 // Testing Zoltan2::MachineRepresentation
47 
49 #include <Zoltan2_TestHelpers.hpp>
50 #include <Teuchos_DefaultComm.hpp>
51 
52 template <typename nCoord_t, typename part_t>
53 int checkAllCoords(const Teuchos::Comm<int> &comm,
55 {
56  // Verify that getAllMachineCoordinatesView returns the same values
57  // as individual calls by rank.
58  // Verify that returned coordinates lie within the extent of the coordinates.
59 
60  int fail = 0;
61  const int failval = 100000000;
62 
63  int np = comm.getSize();
64  int me = comm.getRank();
65 
66  int dim = mach.getMachineDim();
67  int *nxyz = new int[dim];
68 
69  nCoord_t *xyz = new nCoord_t[dim];
70 
71  nCoord_t **allCoords;
72 
73  bool haveExtent = mach.getMachineExtent(nxyz);
74 
75  if (mach.getAllMachineCoordinatesView(allCoords)) {
76 
77  // Check all ranks
78  for (int i = 0; i < np; i++) {
79  if (mach.getMachineCoordinate(i, xyz)) {
80  if (me == 0) std::cout << "RANK " << i << " COORD ";
81  for (int d = 0; d < dim; d++) {
82  if (me == 0) std::cout << " " << xyz[d];
83  if (xyz[d] != allCoords[d][i]) fail = failval;
84  if (haveExtent && (xyz[d] < 0 || xyz[d] >= nxyz[d])) fail = failval;
85  }
86  if (me == 0) std::cout << std::endl;
87  }
88  else {
89  std::cout << "Rank " << me
90  << " getMachineCoordinate failed " << std::endl;
91  fail = failval; // getMachineCoordinate failed
92  }
93  }
94  if (fail == failval) {
95  std::cout << "Rank " << me
96  << " Invalid coordinates from getAllMachineCoordinatesView or "
97  << "getMachineCoordinate" << std::endl;
98  }
99 
100  // Check my rank
101  if (mach.getMyMachineCoordinate(xyz)) {
102  for (int d = 0; d < dim; d++)
103  if (xyz[d] != allCoords[d][me]) fail = failval;
104  }
105  else {
106  fail = failval; // getMyMachineCoordinate failed
107  std::cout << "Rank " << me
108  << "getMyMachineCoordinates failed" << std::endl;
109  }
110  }
111  else {
112  fail = failval; // couldn't retrieve coordinates
113  std::cout << "Rank " << me
114  << "couldn't retrieve coordinates with "
115  << "getAllMachineCoordinatesView" << std::endl;
116  }
117 
118  delete [] xyz;
119  delete [] nxyz;
120 
121  return fail;
122 }
123 
125 int checkErrorCode(const Teuchos::Comm<int> &comm, int code)
126 {
127  int rank = comm.getRank();
128  if (code > 0)
129  std::cerr << "Proc " << rank << " error: " << code << std::endl;
130  comm.barrier();
131 
132  // Will return 1 if any process has a non-zero code
133  TEST_FAIL_AND_RETURN_VALUE(comm, code==0, "TEST FAILED", 1);
134 
135  return 0;
136 }
137 
139 
140 int main(int argc, char *argv[])
141 {
142  Teuchos::GlobalMPISession session(&argc, &argv);
143  Teuchos::RCP<const Comm<int> > comm = Teuchos::DefaultComm<int>::getComm();
144 
145  int me = comm->getRank();
146  int np = comm->getSize();
147  //char *name = "node0"; Causes compiler warnings. Do weirdness.
148  char node0[6] = {'n', 'o', 'd', 'e', '0', '\0'};
149  char *name = node0;
150  int fail = 0;
151 
152  typedef zlno_t ncoord_t;
153  typedef zlno_t part_t;
154 
156 
157  // Tests that all machines should pass
158  if (mach.getNumRanks() != np) fail += 1;
159 
160  if (mach.hasMachineCoordinates())
161  fail += checkAllCoords<ncoord_t,part_t>(*comm, mach);
162 
163  if (checkErrorCode(*comm, fail))
164  return 1;
165 
166 #if defined(HAVE_ZOLTAN2_LDMS)
167  { // Add tests specific to LDMS
168  if (checkErrorCode(*comm, fail))
169  return 1;
170  }
171 #elif defined(HAVE_ZOLTAN2_RCA)
172  { // Add tests specific to RCA
173  if (checkErrorCode(*comm, fail))
174  return 1;
175  }
176 #elif defined(HAVE_ZOLTAN2_TOPOMANAGER)
177  { // Add tests specific to TopoMgr
178  if (checkErrorCode(*comm, fail))
179  return 1;
180  }
181 #elif defined(HAVE_ZOLTAN2_BGQTEST)
182  { // Add tests specific to BGQ
183  if (checkErrorCode(*comm, fail))
184  return 1;
185  }
186 #else
187 
188  { // Tests specific to MachineForTesting
189 
190  if (mach.getMachineDim() != 3) fail += 10;
191 
192  int nxyz[3];
193  if (!mach.getMachineExtent(nxyz)) fail += 100;
194  if (nxyz[0] != np || nxyz[1] != 2*np || nxyz[2] != 3*np)
195  // Depends on ficticious extent in Zoltan2_MachineForTesting.hpp
196  fail += 1000;
197 
198  ncoord_t xyz[3];
199 
200  // Depends on ficticious coordinates in Zoltan2_MachineForTesting.hpp
201  ncoord_t xyz_expected[3] = {me, np, np+1};
202 
203  if (!mach.getMyMachineCoordinate(xyz)) fail += 1000;
204 
205  if ((xyz[0] != xyz_expected[0]) ||
206  (xyz[1] != xyz_expected[1]) ||
207  (xyz[2] != xyz_expected[2]))
208  fail += 10000;
209 
210  // MachineForTesting cannot retrieve coords by node name
211  if (mach.getMachineCoordinate(name, xyz)) fail += 10000000;
212 
213  if (checkErrorCode(*comm, fail))
214  return 1;
215  }
216 #endif
217 
218  if (me == 0) std::cout << "PASS" << std::endl;
219 
220  return 0;
221 }
int main(int argc, char *argv[])
Definition: Machine.cpp:140
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
getCoordinate function set the machine coordinate xyz of any rank process return true if coordinates ...
int zlno_t
common code used by tests
int checkErrorCode(const Teuchos::Comm< int > &comm, int code)
Definition: Machine.cpp:125
bool getMyMachineCoordinate(pcoord_t *xyz) const
getMyCoordinate function set the machine coordinate xyz of the current process return true if current...
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
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
static const std::string fail
#define TEST_FAIL_AND_RETURN_VALUE(comm, ok, s, rc)
bool getMachineExtent(int *nxyz) const
sets the number of unique coordinates in each machine dimension return true if coordinates are availa...
int getNumRanks() const
return the number of ranks.
int checkAllCoords(const Teuchos::Comm< int > &comm, const Zoltan2::MachineRepresentation< nCoord_t, part_t > &mach)
Definition: Machine.cpp:53
bool hasMachineCoordinates() const
indicates whether or not the machine has coordinates