1 #ifndef _ZOLTAN2_MACHINE_TORUS_TOPOMANAGER_HPP_
2 #define _ZOLTAN2_MACHINE_TORUS_TOPOMANAGER_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
8 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
9 #include <TopoManager.h>
17 template <
typename pcoord_t,
typename part_t>
27 #if defined (CMK_BLUEGENEQ)
28 networkDim(6), tmgr(comm.getSize()),
29 #elif defined (CMK_BLUEGENEP)
30 networkDim(4), tmgr(comm.getSize()),
34 procCoords(NULL), machine_extent(NULL),
35 delete_transformed_coords(false),
36 transformed_network_dim(0),
37 transformed_coordinates (NULL), pl(NULL)
39 transformed_network_dim = networkDim - 1;
40 transformed_coordinates = procCoords;
41 machine_extent =
new int[networkDim];
45 procCoords =
new pcoord_t *[networkDim];
46 for (
int i = 0; i < networkDim; ++i) {
47 procCoords[i] =
new pcoord_t[this->
numRanks];
48 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
52 pcoord_t *xyz =
new pcoord_t[networkDim];
54 for (
int i = 0; i < networkDim; i++)
55 procCoords[i][this->
myRank] = xyz[i];
59 gatherMachineCoordinates(comm);
64 const Teuchos::ParameterList &pl_ ):
66 #if defined (CMK_BLUEGENEQ)
67 networkDim(6), tmgr(comm.getSize()),
68 #elif defined (CMK_BLUEGENEP)
69 networkDim(4), tmgr(comm.getSize()),
73 procCoords(NULL), machine_extent(NULL),
74 delete_transformed_coords(false),
75 transformed_network_dim(0),
76 transformed_coordinates (NULL),
79 transformed_network_dim = networkDim - 1;
80 transformed_coordinates = procCoords;
81 machine_extent =
new int[networkDim];
85 procCoords =
new pcoord_t *[networkDim];
86 for (
int i = 0; i < networkDim; ++i) {
87 procCoords[i] =
new pcoord_t[this->
numRanks];
88 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
92 pcoord_t *xyz =
new pcoord_t[networkDim];
94 for (
int i = 0; i < networkDim; i++)
95 procCoords[i][this->
myRank] = xyz[i];
99 gatherMachineCoordinates(comm);
101 const Teuchos::ParameterEntry *pe =
102 this->pl->getEntryPtr(
"Machine_Optimization_Level");
105 int optimization_level = 0;
107 optimization_level = pe->getValue<
int>(&optimization_level);
109 if (optimization_level == 0) {
110 transformed_network_dim = networkDim - 1;
111 transformed_coordinates = procCoords;
114 else if (optimization_level >= 1) {
115 transformed_network_dim = networkDim - 2;
116 transformed_coordinates = procCoords;
123 for (
int i = 0; i < networkDim; i++) {
124 delete [] procCoords[i];
126 delete [] procCoords;
127 delete [] machine_extent;
129 if (delete_transformed_coords) {
130 for (
int i = 0; i < transformed_network_dim; i++) {
131 delete [] transformed_coordinates[i];
133 delete [] transformed_coordinates;
145 #if defined (CMK_BLUEGENEQ)
147 if (dim < transformed_network_dim)
148 nxyz[dim++] = tmgr.getDimNA();
149 if (dim < transformed_network_dim)
150 nxyz[dim++] = tmgr.getDimNB();
151 if (dim < transformed_network_dim)
152 nxyz[dim++] = tmgr.getDimNC();
153 if (dim < transformed_network_dim)
154 nxyz[dim++] = tmgr.getDimND();
155 if (dim < transformed_network_dim)
156 nxyz[dim++] = tmgr.getDimNE();
157 if (dim < transformed_network_dim)
158 nxyz[dim++] = tmgr.getDimNT();
160 #elif defined (CMK_BLUEGENEP)
162 if (dim < transformed_network_dim)
163 nxyz[dim++] = tmgr.getDimNX();
164 if (dim < transformed_network_dim)
165 nxyz[dim++] = tmgr.getDimNY();
166 if (dim < transformed_network_dim)
167 nxyz[dim++] = tmgr.getDimNZ();
168 if (dim < transformed_network_dim)
169 nxyz[dim++] = tmgr.getDimNT();
178 #if defined (CMK_BLUEGENEQ)
182 if (dim < transformed_network_dim)
183 wrap_around[dim++] =
true;
184 if (dim < transformed_network_dim)
185 wrap_around[dim++] =
true;
186 if (dim < transformed_network_dim)
187 wrap_around[dim++] =
true;
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 #elif defined (CMK_BLUEGENEP)
196 if (dim < transformed_network_dim)
197 wrap_around[dim++] =
true;
198 if (dim < transformed_network_dim)
199 wrap_around[dim++] =
true;
200 if (dim < transformed_network_dim)
201 wrap_around[dim++] =
true;
202 if (dim < transformed_network_dim)
203 wrap_around[dim++] =
true;
210 for (
int i = 0; i < this->transformed_network_dim; ++i) {
211 xyz[i] = transformed_coordinates[i][this->
myRank];
217 #if defined (CMK_BLUEGENEQ)
219 tmgr.rankToCoordinates(this->
myRank, a,b,c,d,e,t);
220 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = d; xyz[4] = e; xyz[5] = t;
225 #elif defined (CMK_BLUEGENEP)
227 tmgr.rankToCoordinates(this->
myRank, a,b,c,t);
228 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = t;
238 if (dim < transformed_network_dim)
239 wrap_around[dim++] =
true;
241 if (dim < transformed_network_dim)
242 wrap_around[dim++] =
true;
244 if (dim < transformed_network_dim)
245 wrap_around[dim++] =
true;
247 if (dim < transformed_network_dim)
248 wrap_around[dim++] =
true;
250 if (dim < transformed_network_dim)
251 wrap_around[dim++] =
true;
253 if (dim < transformed_network_dim)
254 wrap_around[dim++] =
true;
258 pcoord_t *xyz)
const {
268 allCoords = procCoords;
274 for (
int i = 0; i < networkDim - 1; ++i) {
275 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
277 distance = -distance;
278 if (machine_extent[i] - distance < distance)
279 distance = machine_extent[i] - distance;
290 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
293 pcoord_t **procCoords;
295 const Teuchos::ParameterList *pl;
298 bool delete_transformed_coords;
299 int transformed_network_dim;
300 pcoord_t **transformed_coordinates;
302 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
304 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
306 for (
int i = 0; i < networkDim; i++) {
307 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
309 procCoords[i], tmpVect);
310 pcoord_t *tmp = tmpVect;
311 tmpVect = procCoords[i];
bool getMachineExtentWrapArounds(bool *wrap_around) const
int getMachineDim() const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
bool hasMachineCoordinates() const
bool getMyActualMachineCoordinate(pcoord_t *xyz)
MachineClass Base class for representing machine coordinates, networks, etc.
A TopoManager Machine Class on Torus Networks.
bool getMachineExtent(int *nxyz) const
SparseMatrixAdapter_t::part_t part_t
virtual ~MachineTorusTopoMgr()
bool getMachineExtentWrapArounds(part_t *wrap_around) const
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
getHopCount function set hops between rank1 and rank2 return true if coordinates are available ...
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
MachineTorusTopoMgr(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
MachineTorusTopoMgr(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
bool getMyMachineCoordinate(pcoord_t *xyz)
int getRealMachineDim() const