Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_MachineForTesting.hpp
Go to the documentation of this file.
1 #ifndef _ZOLTAN2_MACHINEFORTESTING_HPP_
2 #define _ZOLTAN2_MACHINEFORTESTING_HPP_
3 
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
6 #include <Zoltan2_Machine.hpp>
7 
8 namespace Zoltan2{
9 
14 template <typename pcoord_t, typename part_t>
15 class MachineForTesting : public Machine<pcoord_t, part_t> {
16 
17 public:
23  MachineForTesting(const Teuchos::Comm<int> &comm):
24  Machine<pcoord_t,part_t>(comm),
25  networkDim(3),
26  procCoords(NULL)
27  {
28  //allocate memory for processor coordinates.
29  procCoords = new pcoord_t *[networkDim];
30  for (int i = 0; i < networkDim; ++i){
31  procCoords[i] = new pcoord_t[this->numRanks];
32  memset(procCoords[i], 0, sizeof(pcoord_t) * this->numRanks);
33  }
34 
35  //obtain the coordinate of the processor.
36  pcoord_t *xyz = new pcoord_t[networkDim];
38  for (int i = 0; i < networkDim; i++)
39  procCoords[i][this->myRank] = xyz[i];
40  delete [] xyz;
41 
42  //reduceAll the coordinates of each processor.
43  gatherMachineCoordinates(comm);
44  }
45 
46  MachineForTesting(const Teuchos::Comm<int> &comm, const Teuchos::ParameterList &pl):
47  Machine<pcoord_t,part_t>(comm),
48  networkDim(3),
49  procCoords(NULL)
50  {
51  //allocate memory for processor coordinates.
52  procCoords = new pcoord_t *[networkDim];
53  for (int i = 0; i < networkDim; ++i){
54  procCoords[i] = new pcoord_t[this->numRanks];
55  memset(procCoords[i], 0, sizeof(pcoord_t) * this->numRanks);
56  }
57 
58  //obtain the coordinate of the processor.
59  pcoord_t *xyz = new pcoord_t[networkDim];
61  for (int i = 0; i < networkDim; i++)
62  procCoords[i][this->myRank] = xyz[i];
63  delete [] xyz;
64 
65  //reduceAll the coordinates of each processor.
66  gatherMachineCoordinates(comm);
67  }
68 
69  virtual ~MachineForTesting() {
70  for (int i = 0; i < networkDim; i++){
71  delete [] procCoords[i];
72  }
73  delete [] procCoords;
74  }
75 
76  bool hasMachineCoordinates() const { return true; }
77 
78  int getMachineDim() const { return networkDim; }
79 
80  bool getMachineExtent(int *nxyz) const {
81  // Ficticious machine extent
82  nxyz[0] = this->numRanks;
83  nxyz[1] = 2*this->numRanks;
84  nxyz[2] = 3*this->numRanks;
85  return true;
86  }
87 
88  bool getMyMachineCoordinate(pcoord_t *xyz) {
89  return getMachineCoordinate(this->myRank, xyz);
90  }
91 
92  bool getMachineCoordinate(const int rank, pcoord_t *xyz) {
93  // Ficticious machine coordinates
94  // part_t slice = part_t(pow(double(this->numRanks), double(1.0/networkDim))
95  // + 0.5);
96  // part_t m = rank;
97  // for (int i = 0; i < networkDim; ++i){
98  // xyz[i] = m / part_t(pow(slice, double(networkDim - i - 1)));
99  // m = m % part_t(pow(double(slice), double(networkDim - i - 1)));
100  // }
101 
102  xyz[0] = rank;
103  xyz[1] = this->numRanks;
104  xyz[2] = this->numRanks+1;
105  return true;
106  }
107 
108  bool getMachineCoordinate(const char *nodename, pcoord_t *xyz) {
109  return false; // cannot yet return from nodename
110  }
111 
112  bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const {
113  allCoords = procCoords;
114  return true;
115  }
116 
117 private:
118 
119  int networkDim;
120 
121  pcoord_t **procCoords; // KDD Maybe should be RCP?
122 
123  void gatherMachineCoordinates(const Teuchos::Comm<int> &comm) {
124  // reduces and stores all machine coordinates.
125  pcoord_t *tmpVect = new pcoord_t [this->numRanks];
126 
127  for (int i = 0; i < networkDim; i++) {
128  Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
129  this->numRanks, procCoords[i], tmpVect);
130  pcoord_t *tmp = tmpVect;
131  tmpVect = procCoords[i];
132  procCoords[i] = tmp;
133  }
134  delete [] tmpVect;
135  }
136 };
137 }
138 #endif
A Machine Class for testing only A more realistic machine should be used for task mapping...
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
MachineClass Base class for representing machine coordinates, networks, etc.
MachineForTesting(const Teuchos::Comm< int > &comm)
Constructor: A default machine description used only for testing; it does not contain actual machine ...
SparseMatrixAdapter_t::part_t part_t
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz)
bool getMachineExtent(int *nxyz) const
MachineForTesting(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl)