Zoltan2
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
Zoltan2_MachineLDMS.hpp
Go to the documentation of this file.
1 #ifndef _ZOLTAN2_MACHINEDEFAULT_HPP_
2 #define _ZOLTAN2_MACHINEDEFAULT_HPP_
3 
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
6 
7 namespace Zoltan2{
8 
13 template <typename nNo_t, typename nCoord_t>
14 class DefaultMachine : public MachineRepresentation<nNo_t, nCoord_t> {
15 
16 private:
17  int networkDim;
18  int numProcs;
19  int myRank;
20 
21  nCoord_t **procCoords; // KDD Maybe should be RCP?
22 
23 public:
28  MachineRepresentation(const Comm<int> &comm):
29  networkDim(0), numProcs(comm.getSize()), myRank(comm.getRank()),
30  procCoords(NULL)
31  {
32  // WIll need this constructor to be specific to RAAMP (MD).
33  // Will need a default constructor using, e.g., GeometricGenerator
34  // or nothing at all, for when RAAMP is not available as TPL.
35  //
36  // (AG) In addition, need to be able to run without special
37  // privileges in system (e.g., on hopper).
38  // Notes: For now, all cores connected to same NIC will get the
39  // same coordinates; later, we could add extra coordinate dimensions
40  // to represent nodes or dies (using hwloc info through RAAMP
41  // data object).
42 
43  // (MD) will modify mapping test to use machine representation
44  // #ifdef HAVE_ZOLTAN2_OVIS
45 
46  // Call initializer for RAAMP data object (AG)
47 
48  //get network dimension.
49  //TODO change.
50  // Call RAAMP Data Object to get the network dimension (AG)
51  networkDim = 3;
52 
53  //allocate memory for processor coordinates.
54  procCoords = new nCoord_t *[networkDim];
55  for (int i = 0; i < networkDim; ++i){
56  procCoords[i] = new nCoord_t [numProcs];
57  memset (procCoords[i], 0, sizeof(nCoord_t) * numProcs);
58  }
59  //obtain the coordinate of the processor.
60  this->getMyCoordinate(/*nCoord_t &xyz[networkDim]*/);
61  // copy xyz into appropriate spot in procCoords. (MD) // KDD I agree with this
62 
63  //reduceAll the coordinates of each processor.
65  }
66 
67 
71  MachineRepresentation(const RCP<Comm<int> > &comm_):
72  networkDim(0), numProcs(comm_->getSize()), procCoords(0), comm(comm_){
73  // WIll need this constructor to be specific to RAAMP (MD).
74  // Will need a default constructor using, e.g., GeometricGenerator
75  // or nothing at all, for when RAAMP is not available as TPL.
76  //
77  // (AG) In addition, need to be able to run without special
78  // privileges in system (e.g., on hopper).
79  // Notes: For now, all cores connected to same NIC will get the
80  // same coordinates; later, we could add extra coordinate dimensions
81  // to represent nodes or dies (using hwloc info through RAAMP
82  // data object).
83 
84  // (MD) will modify mapping test to use machine representation
85  // #ifdef HAVE_ZOLTAN2_OVIS
86 
87  // Call initializer for RAAMP data object (AG)
88 
89  //get network dimension.
90  //TODO change.
91  // Call RAAMP Data Object to get the network dimension (AG)
92  networkDim = 3;
93 
94  //allocate memory for processor coordinates.
95  procCoords = new nCoord_t *[networkDim];
96  for (int i = 0; i < networkDim; ++i){
97  procCoords[i] = new nCoord_t [numProcs];
98  memset (procCoords[i], 0, sizeof(nCoord_t) * numProcs);
99  }
100  //obtain the coordinate of the processor.
101  this->getMyCoordinate(/*nCoord_t &xyz[networkDim]*/);
102  // copy xyz into appropriate spot in procCoords. (MD) // KDD I Agree.
103 
104  //reduceAll the coordinates of each processor.
105  this->gatherMachineCoordinates();
106  }
107 
108 
112  void getMyCoordinate(/* nCoord_t &xyz[networkDim]*/){ // KDD Enable the argument rather
113  // KDD than writing into array here
114 
115  // Call RAAMP system to get coordinates and store in xyz (MD)
116  // What is the RAAMP call? (AG)
117  // AG will return a view (pointer) to RAAMP's data.
118  // We will copy it into xyz.
119 
120 //KDD #if defined(HAVE_ZOLTAN2_LDMS)
121 //KDD #elif defined(HAVE_ZOLTAN2_TOPOMGR)
122 //KDD #elif defined(HAVE_ZOLTAN2_RCA)
123 //KDD #else
124 
125  // The code below may be good for the default constructor, perhaps,
126  // but it should copy the data into xyz instead of the procCoords.
127  int myRank = comm->getRank();
128 
129  int slice = int (pow( double(numProcs), double(1.0 / networkDim)) + 0.5 );
130 
131  int m = myRank;
132  for (int i = 0; i < networkDim; ++i){
133  procCoords[i][myRank] = m / int(pow(slice, double(networkDim - i - 1)));
134  m = m % int(pow(double(slice), double(networkDim - i - 1)));
135  }
136 //KDD #endif
137  }
138 
139  // KDD Need to return coordinate of any rank?
140  // void getCoordinate(partId_t rank, nCoord_t &xyz[networkDim]) { }
141 
145  void gatherMachineCoordinates(){ // KDD Should be private
146  nCoord_t *tmpVect = new nCoord_t [numProcs];
147 
148  for (int i = 0; i < networkDim; ++i){
149  reduceAll<int, nCoord_t>(
150  *comm,
151  Teuchos::REDUCE_SUM,
152  numProcs,
153  procCoords[i],
154  tmpVect);
155  nCoord_t *tmp = tmpVect;
156  tmpVect = procCoords[i];
157  procCoords[i] = tmp;
158  }
159  delete [] tmpVect;
160  }
161 
166  for (int i = 0; i < networkDim; ++i){
167  delete [] procCoords[i];
168  }
169  delete [] procCoords;
170  // Free/release THE RAAMP Data Object.
171  // Deinitialize/finalize/whatever (AG)
172  }
173 
177  int getProcDim() const{ // KDD Maybe getNetworkDim or getProcCoordDim
178  return networkDim;
179  }
180 
184  nCoord_t** getProcCoords() const{ // KDD Make clear that returning a View; maybe return ArrayView
185  return procCoords;
186  }
187 
191  int getNumProcs() const{
192  return numProcs;
193  }
194 
195  // KDD TODO: Need more for full LDMS interface.
196 
197 };
198 }
199 #endif
A Default MachineRepresentation Class for testing only A more correct machine representation should b...
int getProcDim() const
getProcDim function returns the dimension of the physical processor layout.
nCoord_t ** getProcCoords() const
getProcDim function returns the coordinates of processors in two dimensional array.
void getMyCoordinate()
getMyCoordinate function stores the coordinate of the current processor in procCoords[*][rank] ...
virtual ~MachineRepresentation()
destructor of the class free memory in procCoords.
int getNumProcs() const
getNumProcs function returns the number of processors.
MachineRepresentation(const RCP< Comm< int > > &comm_)
Constructor MachineRepresentation Class.
MachineRepresentation Class Base class for representing machine coordinates, networks, etc.
MachineRepresentation(const Comm< int > &comm)
Constructor MachineRepresentation Class.
void gatherMachineCoordinates()
gatherMachineCoordinates function reduces and stores all machine coordinates.