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