Zoltan2
Zoltan2_MachineRepresentation.hpp
Go to the documentation of this file.
1 #ifndef _ZOLTAN2_MACHINEREPRESENTATION_HPP_
2 #define _ZOLTAN2_MACHINEREPRESENTATION_HPP_
3 
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
6 namespace Zoltan2{
7 
12 template <typename pcoord_t>
14 
15 private:
16  int networkDim;
17  int numProcs;
18 
19  pcoord_t **procCoords;
20  const RCP<const Comm<int> > comm;
21 
22 public:
26  MachineRepresentation(const RCP<const Comm<int> > &comm_):
27  networkDim(0), numProcs(comm_->getSize()), procCoords(0), comm(comm_){
28  // WIll need this constructor to be specific to RAAMP (MD).
29  // Will need a default constructor using, e.g., GeometricGenerator
30  // or nothing at all, for when RAAMP is not available as TPL.
31  //
32  // (AG) In addition, need to be able to run without special
33  // privileges in system (e.g., on hopper).
34  // Notes: For now, all cores connected to same NIC will get the
35  // same coordinates; later, we could add extra coordinate dimensions
36  // to represent nodes or dies (using hwloc info through RAAMP
37  // data object).
38 
39  // (MD) will modify mapping test to use machine representation
40  // #ifdef HAVE_ZOLTAN2_OVIS
41 
42  // Call initializer for RAAMP data object (AG)
43 
44  //get network dimension.
45  //TODO change.
46  // Call RAAMP Data Object to get the network dimension (AG)
47  networkDim = 3;
48 
49  //allocate memory for processor coordinates.
50  procCoords = new pcoord_t *[networkDim];
51  for (int i = 0; i < networkDim; ++i){
52  procCoords[i] = new pcoord_t [numProcs];
53  memset (procCoords[i], 0, sizeof(pcoord_t) * numProcs);
54  }
55  //obtain the coordinate of the processor.
56  this->getMyCoordinate(/*pcoord_t &xyz[networkDim]*/);
57  // copy xyz into appropriate spot in procCoords. (MD)
58 
59  //reduceAll the coordinates of each processor.
61  }
62 
63 
67  MachineRepresentation(const RCP<Comm<int> > &comm_):
68  networkDim(0), numProcs(comm_->getSize()), procCoords(0), comm(comm_){
69  // WIll need this constructor to be specific to RAAMP (MD).
70  // Will need a default constructor using, e.g., GeometricGenerator
71  // or nothing at all, for when RAAMP is not available as TPL.
72  //
73  // (AG) In addition, need to be able to run without special
74  // privileges in system (e.g., on hopper).
75  // Notes: For now, all cores connected to same NIC will get the
76  // same coordinates; later, we could add extra coordinate dimensions
77  // to represent nodes or dies (using hwloc info through RAAMP
78  // data object).
79 
80  // (MD) will modify mapping test to use machine representation
81  // #ifdef HAVE_ZOLTAN2_OVIS
82 
83  // Call initializer for RAAMP data object (AG)
84 
85  //get network dimension.
86  //TODO change.
87  // Call RAAMP Data Object to get the network dimension (AG)
88  networkDim = 3;
89 
90  //allocate memory for processor coordinates.
91  procCoords = new pcoord_t *[networkDim];
92  for (int i = 0; i < networkDim; ++i){
93  procCoords[i] = new pcoord_t [numProcs];
94  memset (procCoords[i], 0, sizeof(pcoord_t) * numProcs);
95  }
96  //obtain the coordinate of the processor.
97  this->getMyCoordinate(/*pcoord_t &xyz[networkDim]*/);
98  // copy xyz into appropriate spot in procCoords. (MD)
99 
100  //reduceAll the coordinates of each processor.
101  this->gatherMachineCoordinates();
102  }
103 
104 
108  void getMyCoordinate(/* pcoord_t &xyz[networkDim]*/){
109 
110  // Call RAAMP system to get coordinates and store in xyz (MD)
111  // What is the RAAMP call? (AG)
112  // AG will return a view (pointer) to RAAMP's data.
113  // We will copy it into xyz.
114 
115  // The code below may be good for the default constructor, perhaps,
116  // but it should copy the data into xyz instead of the procCoords.
117  int myRank = comm->getRank();
118 
119  int slice = int (pow( double(numProcs), double(1.0 / networkDim)) + 0.5 );
120 
121  int m = myRank;
122  for (int i = 0; i < networkDim; ++i){
123  procCoords[i][myRank] = m / int(pow(slice, double(networkDim - i - 1)));
124  m = m % int(pow(double(slice), double(networkDim - i - 1)));
125  }
126  }
127 
132  pcoord_t *tmpVect = new pcoord_t [numProcs];
133 
134  for (int i = 0; i < networkDim; ++i){
135  reduceAll<int, pcoord_t>(
136  *comm,
137  Teuchos::REDUCE_SUM,
138  numProcs,
139  procCoords[i],
140  tmpVect);
141  pcoord_t *tmp = tmpVect;
142  tmpVect = procCoords[i];
143  procCoords[i] = tmp;
144  }
145  delete [] tmpVect;
146  }
147 
152  for (int i = 0; i < networkDim; ++i){
153  delete [] procCoords[i];
154  }
155  delete []procCoords;
156  // Free/release THE RAAMP Data Object.
157  // Deinitialize/finalize/whatever (AG)
158  }
159 
163  int getProcDim() const{
164  return networkDim;
165  }
166 
170  pcoord_t** getProcCoords() const{
171  return procCoords;
172  }
173 
177  int getNumProcs() const{
178  return numProcs;
179  }
180 
181 };
182 }
183 #endif
pcoord_t ** getProcCoords() const
getProcDim function returns the coordinates of processors in two dimensional array.
MachineRepresentation(const RCP< Comm< int > > &comm_)
Constructor MachineRepresentation Class.
MachineRepresentation(const RCP< const Comm< int > > &comm_)
Constructor MachineRepresentation Class.
void gatherMachineCoordinates()
gatherMachineCoordinates function reduces and stores all machine coordinates.
MachineRepresentation Class Finds the coordinate of the processor. Used to find the processor coordin...
~MachineRepresentation()
destructor of the class free memory in procCoords.
int getProcDim() const
getProcDim function returns the dimension of the physical processor layout.
int getNumProcs() const
getNumProcs function returns the number of processors.
void getMyCoordinate()
getMyCoordinate function stores the coordinate of the current processor in procCoords[*][rank] ...