1 #ifndef _ZOLTAN2_MACHINE_TOPOMANAGER_HPP_
2 #define _ZOLTAN2_MACHINE_TOPOMANAGER_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
8 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
9 #include <TopoManager.h>
18 template <
typename pcoord_t,
typename part_t>
28 #if defined (CMK_BLUEGENEQ)
29 networkDim(6), tmgr(comm.getSize()),
30 #elif defined (CMK_BLUEGENEP)
31 networkDim(4), tmgr(comm.getSize()),
35 procCoords(NULL), machine_extent(NULL),
36 delete_transformed_coords(false), transformed_network_dim(0),transformed_coordinates (NULL), pl(NULL)
38 transformed_network_dim = networkDim - 1;
39 transformed_coordinates = procCoords;
40 machine_extent =
new int[networkDim];
43 procCoords =
new pcoord_t *[networkDim];
44 for (
int i = 0; i < networkDim; ++i){
45 procCoords[i] =
new pcoord_t[this->
numRanks];
46 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
50 pcoord_t *xyz =
new pcoord_t[networkDim];
52 for (
int i = 0; i < networkDim; i++)
53 procCoords[i][this->
myRank] = xyz[i];
57 gatherMachineCoordinates(comm);
61 MachineTopoMgr(
const Teuchos::Comm<int> &comm,
const Teuchos::ParameterList &pl_ ):
63 #if defined (CMK_BLUEGENEQ)
64 networkDim(6), tmgr(comm.getSize()),
65 #elif defined (CMK_BLUEGENEP)
66 networkDim(4), tmgr(comm.getSize()),
70 procCoords(NULL), machine_extent(NULL),
71 delete_transformed_coords(false), transformed_network_dim(0),transformed_coordinates (NULL),
74 transformed_network_dim = networkDim - 1;
75 transformed_coordinates = procCoords;
76 machine_extent =
new int[networkDim];
79 procCoords =
new pcoord_t *[networkDim];
80 for (
int i = 0; i < networkDim; ++i){
81 procCoords[i] =
new pcoord_t[this->
numRanks];
82 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
86 pcoord_t *xyz =
new pcoord_t[networkDim];
88 for (
int i = 0; i < networkDim; i++)
89 procCoords[i][this->
myRank] = xyz[i];
93 gatherMachineCoordinates(comm);
95 const Teuchos::ParameterEntry *pe = this->pl->getEntryPtr(
"Machine_Optimization_Level");
98 int optimization_level = 0;
100 optimization_level = pe->getValue<
int>(&optimization_level);
102 if (optimization_level == 0){
103 transformed_network_dim = networkDim - 1;
104 transformed_coordinates = procCoords;
107 else if (optimization_level >= 1){
108 transformed_network_dim = networkDim - 2;
109 transformed_coordinates = procCoords;
116 for (
int i = 0; i < networkDim; i++){
117 delete [] procCoords[i];
119 delete [] procCoords;
120 delete [] machine_extent;
122 if (delete_transformed_coords){
123 for (
int i = 0; i < transformed_network_dim; i++){
124 delete [] transformed_coordinates[i];
126 delete [] transformed_coordinates;
138 #if defined (CMK_BLUEGENEQ)
140 if (dim < transformed_network_dim)
141 nxyz[dim++] = tmgr.getDimNA();
142 if (dim < transformed_network_dim)
143 nxyz[dim++] = tmgr.getDimNB();
144 if (dim < transformed_network_dim)
145 nxyz[dim++] = tmgr.getDimNC();
146 if (dim < transformed_network_dim)
147 nxyz[dim++] = tmgr.getDimND();
148 if (dim < transformed_network_dim)
149 nxyz[dim++] = tmgr.getDimNE();
150 if (dim < transformed_network_dim)
151 nxyz[dim++] = tmgr.getDimNT();
153 #elif defined (CMK_BLUEGENEP)
155 if (dim < transformed_network_dim)
156 nxyz[dim++] = tmgr.getDimNX();
157 if (dim < transformed_network_dim)
158 nxyz[dim++] = tmgr.getDimNY();
159 if (dim < transformed_network_dim)
160 nxyz[dim++] = tmgr.getDimNZ();
161 if (dim < transformed_network_dim)
162 nxyz[dim++] = tmgr.getDimNT();
171 #if defined (CMK_BLUEGENEQ)
174 if (dim < transformed_network_dim)
175 wrap_around[dim++] =
true;
176 if (dim < transformed_network_dim)
177 wrap_around[dim++] =
true;
178 if (dim < transformed_network_dim)
179 wrap_around[dim++] =
true;
180 if (dim < transformed_network_dim)
181 wrap_around[dim++] =
true;
182 if (dim < transformed_network_dim)
183 wrap_around[dim++] =
true;
184 if (dim < transformed_network_dim)
185 wrap_around[dim++] =
true;
186 #elif defined (CMK_BLUEGENEP)
188 if (dim < transformed_network_dim)
189 wrap_around[dim++] =
true;
190 if (dim < transformed_network_dim)
191 wrap_around[dim++] =
true;
192 if (dim < transformed_network_dim)
193 wrap_around[dim++] =
true;
194 if (dim < transformed_network_dim)
195 wrap_around[dim++] =
true;
202 for (
int i = 0; i < this->transformed_network_dim; ++i){
203 xyz[i] = transformed_coordinates[i][this->
myRank];
209 #if defined (CMK_BLUEGENEQ)
211 tmgr.rankToCoordinates(this->
myRank, a,b,c,d,e,t);
212 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = d; xyz[4] = e; xyz[5] = t;
215 #elif defined (CMK_BLUEGENEP)
217 tmgr.rankToCoordinates(this->
myRank, a,b,c,t);
218 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = t;
228 if (dim < transformed_network_dim)
229 wrap_around[dim++] =
true;
231 if (dim < transformed_network_dim)
232 wrap_around[dim++] =
true;
234 if (dim < transformed_network_dim)
235 wrap_around[dim++] =
true;
237 if (dim < transformed_network_dim)
238 wrap_around[dim++] =
true;
240 if (dim < transformed_network_dim)
241 wrap_around[dim++] =
true;
243 if (dim < transformed_network_dim)
244 wrap_around[dim++] =
true;
248 pcoord_t *xyz)
const {
258 allCoords = procCoords;
264 for (
int i = 0; i < networkDim - 1; ++i){
265 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
266 if (distance < 0 ) distance = -distance;
267 if (machine_extent[i] - distance < distance) distance = machine_extent[i] - distance;
278 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
281 pcoord_t **procCoords;
283 const Teuchos::ParameterList *pl;
286 bool delete_transformed_coords;
287 int transformed_network_dim;
288 pcoord_t **transformed_coordinates;
290 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
292 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
294 for (
int i = 0; i < networkDim; i++) {
295 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
296 this->
numRanks, procCoords[i], tmpVect);
297 pcoord_t *tmp = tmpVect;
298 tmpVect = procCoords[i];
int getMachineDim() const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
MachineTopoMgr(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
bool getMachineExtentWrapArounds(bool *wrap_around) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
int getRealMachineDim() const
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMachineExtent(int *nxyz) const
bool getMyActualMachineCoordinate(pcoord_t *xyz)
SparseMatrixAdapter_t::part_t part_t
bool getMyMachineCoordinate(pcoord_t *xyz)
virtual ~MachineTopoMgr()
MachineTopoMgr(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
bool getMachineExtentWrapArounds(part_t *wrap_around) const
A Machine Class for testing only A more realistic machine should be used for task mapping...
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
bool hasMachineCoordinates() const