10 #ifndef _ZOLTAN2_MACHINE_TORUS_TOPOMANAGER_HPP_
11 #define _ZOLTAN2_MACHINE_TORUS_TOPOMANAGER_HPP_
13 #include <Teuchos_Comm.hpp>
14 #include <Teuchos_CommHelpers.hpp>
17 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
18 #include <TopoManager.h>
26 template <
typename pcoord_t,
typename part_t>
36 #if defined (CMK_BLUEGENEQ)
37 networkDim(6), tmgr(comm.getSize()),
38 #elif defined (CMK_BLUEGENEP)
39 networkDim(4), tmgr(comm.getSize()),
43 procCoords(NULL), machine_extent(NULL),
44 delete_transformed_coords(false),
45 transformed_network_dim(0),
46 transformed_coordinates (NULL), pl(NULL)
48 transformed_network_dim = networkDim - 1;
49 transformed_coordinates = procCoords;
50 machine_extent =
new int[networkDim];
54 procCoords =
new pcoord_t *[networkDim];
55 for (
int i = 0; i < networkDim; ++i) {
56 procCoords[i] =
new pcoord_t[this->
numRanks];
57 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
61 pcoord_t *xyz =
new pcoord_t[networkDim];
63 for (
int i = 0; i < networkDim; i++)
64 procCoords[i][this->
myRank] = xyz[i];
68 gatherMachineCoordinates(comm);
73 const Teuchos::ParameterList &pl_ ):
75 #if defined (CMK_BLUEGENEQ)
76 networkDim(6), tmgr(comm.getSize()),
77 #elif defined (CMK_BLUEGENEP)
78 networkDim(4), tmgr(comm.getSize()),
82 procCoords(NULL), machine_extent(NULL),
83 delete_transformed_coords(false),
84 transformed_network_dim(0),
85 transformed_coordinates (NULL),
88 transformed_network_dim = networkDim - 1;
89 transformed_coordinates = procCoords;
90 machine_extent =
new int[networkDim];
94 procCoords =
new pcoord_t *[networkDim];
95 for (
int i = 0; i < networkDim; ++i) {
96 procCoords[i] =
new pcoord_t[this->
numRanks];
97 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
101 pcoord_t *xyz =
new pcoord_t[networkDim];
103 for (
int i = 0; i < networkDim; i++)
104 procCoords[i][this->
myRank] = xyz[i];
108 gatherMachineCoordinates(comm);
110 const Teuchos::ParameterEntry *pe =
111 this->pl->getEntryPtr(
"Machine_Optimization_Level");
114 int optimization_level = 0;
116 optimization_level = pe->getValue<
int>(&optimization_level);
118 if (optimization_level == 0) {
119 transformed_network_dim = networkDim - 1;
120 transformed_coordinates = procCoords;
123 else if (optimization_level >= 1) {
124 transformed_network_dim = networkDim - 2;
125 transformed_coordinates = procCoords;
132 for (
int i = 0; i < networkDim; i++) {
133 delete [] procCoords[i];
135 delete [] procCoords;
136 delete [] machine_extent;
138 if (delete_transformed_coords) {
139 for (
int i = 0; i < transformed_network_dim; i++) {
140 delete [] transformed_coordinates[i];
142 delete [] transformed_coordinates;
154 #if defined (CMK_BLUEGENEQ)
156 if (dim < transformed_network_dim)
157 nxyz[dim++] = tmgr.getDimNA();
158 if (dim < transformed_network_dim)
159 nxyz[dim++] = tmgr.getDimNB();
160 if (dim < transformed_network_dim)
161 nxyz[dim++] = tmgr.getDimNC();
162 if (dim < transformed_network_dim)
163 nxyz[dim++] = tmgr.getDimND();
164 if (dim < transformed_network_dim)
165 nxyz[dim++] = tmgr.getDimNE();
166 if (dim < transformed_network_dim)
167 nxyz[dim++] = tmgr.getDimNT();
169 #elif defined (CMK_BLUEGENEP)
171 if (dim < transformed_network_dim)
172 nxyz[dim++] = tmgr.getDimNX();
173 if (dim < transformed_network_dim)
174 nxyz[dim++] = tmgr.getDimNY();
175 if (dim < transformed_network_dim)
176 nxyz[dim++] = tmgr.getDimNZ();
177 if (dim < transformed_network_dim)
178 nxyz[dim++] = tmgr.getDimNT();
187 #if defined (CMK_BLUEGENEQ)
191 if (dim < transformed_network_dim)
192 wrap_around[dim++] =
true;
193 if (dim < transformed_network_dim)
194 wrap_around[dim++] =
true;
195 if (dim < transformed_network_dim)
196 wrap_around[dim++] =
true;
197 if (dim < transformed_network_dim)
198 wrap_around[dim++] =
true;
199 if (dim < transformed_network_dim)
200 wrap_around[dim++] =
true;
201 if (dim < transformed_network_dim)
202 wrap_around[dim++] =
true;
203 #elif defined (CMK_BLUEGENEP)
205 if (dim < transformed_network_dim)
206 wrap_around[dim++] =
true;
207 if (dim < transformed_network_dim)
208 wrap_around[dim++] =
true;
209 if (dim < transformed_network_dim)
210 wrap_around[dim++] =
true;
211 if (dim < transformed_network_dim)
212 wrap_around[dim++] =
true;
219 for (
int i = 0; i < this->transformed_network_dim; ++i) {
220 xyz[i] = transformed_coordinates[i][this->
myRank];
226 #if defined (CMK_BLUEGENEQ)
228 tmgr.rankToCoordinates(this->
myRank, a,b,c,d,e,t);
229 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = d; xyz[4] = e; xyz[5] = t;
234 #elif defined (CMK_BLUEGENEP)
236 tmgr.rankToCoordinates(this->
myRank, a,b,c,t);
237 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = t;
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;
256 if (dim < transformed_network_dim)
257 wrap_around[dim++] =
true;
259 if (dim < transformed_network_dim)
260 wrap_around[dim++] =
true;
262 if (dim < transformed_network_dim)
263 wrap_around[dim++] =
true;
267 pcoord_t *xyz)
const {
277 allCoords = procCoords;
281 virtual bool getHopCount(
int rank1,
int rank2, pcoord_t &hops)
const override {
283 for (
int i = 0; i < networkDim - 1; ++i) {
284 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
286 distance = -distance;
287 if (machine_extent[i] - distance < distance)
288 distance = machine_extent[i] - distance;
299 #ifdef HAVE_ZOLTAN2_TOPOMANAGER
302 pcoord_t **procCoords;
304 const Teuchos::ParameterList *pl;
307 bool delete_transformed_coords;
308 int transformed_network_dim;
309 pcoord_t **transformed_coordinates;
311 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
313 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
315 for (
int i = 0; i < networkDim; i++) {
316 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
318 procCoords[i], tmpVect);
319 pcoord_t *tmp = tmpVect;
320 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()
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops) const override
getHopCount function set hops between rank1 and rank2 return true if coordinates are available ...
bool getMachineExtentWrapArounds(part_t *wrap_around) const
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