10 #ifndef _ZOLTAN2_MACHINE_TORUS_TOPOMANAGERTEST_HPP_
11 #define _ZOLTAN2_MACHINE_TORUS_TOPOMANAGERTEST_HPP_
13 #include <Teuchos_Comm.hpp>
14 #include <Teuchos_CommHelpers.hpp>
24 template <
typename pcoord_t,
typename part_t>
35 procCoords(NULL),machine_extent(NULL),
36 delete_transformed_coords(false),
37 transformed_network_dim(0),
38 transformed_coordinates (NULL), pl(NULL)
40 transformed_network_dim = networkDim - 1;
41 transformed_coordinates = procCoords;
43 machine_extent =
new int[networkDim];
45 machine_extent[5] = 1;
48 procCoords =
new pcoord_t *[networkDim];
49 for (
int i = 0; i < networkDim; ++i) {
50 procCoords[i] =
new pcoord_t[this->
numRanks];
51 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
55 pcoord_t *xyz =
new pcoord_t[networkDim];
57 for (
int i = 0; i < networkDim; i++)
58 procCoords[i][this->
myRank] = xyz[i];
62 gatherMachineCoordinates(comm);
67 const Teuchos::ParameterList &pl_):
70 procCoords(NULL),machine_extent(NULL),
71 delete_transformed_coords(false),
72 transformed_network_dim(0),
73 transformed_coordinates (NULL),
76 transformed_network_dim = networkDim - 1;
77 transformed_coordinates = procCoords;
78 machine_extent =
new int[networkDim];
81 machine_extent[5] = 1;
84 procCoords =
new pcoord_t *[networkDim];
85 for (
int i = 0; i < networkDim; ++i) {
86 procCoords[i] =
new pcoord_t[this->
numRanks];
87 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
91 pcoord_t *xyz =
new pcoord_t[networkDim];
93 for (
int i = 0; i < networkDim; i++)
94 procCoords[i][this->
myRank] = xyz[i];
98 gatherMachineCoordinates(comm);
100 const Teuchos::ParameterEntry *pe =
101 this->pl->getEntryPtr(
"Machine_Optimization_Level");
104 int optimization_level = 0;
106 optimization_level = pe->getValue<
int>(&optimization_level);
108 if (optimization_level == 0) {
109 transformed_network_dim = networkDim - 1;
110 transformed_coordinates = procCoords;
112 else if (optimization_level >= 1) {
113 transformed_network_dim = networkDim - 2;
114 transformed_coordinates = procCoords;
121 for (
int i = 0; i < networkDim; i++) {
122 delete [] procCoords[i];
124 delete [] procCoords;
126 delete [] machine_extent;
127 if (delete_transformed_coords) {
128 for (
int i = 0; i < transformed_network_dim; i++) {
129 delete [] transformed_coordinates[i];
131 delete [] transformed_coordinates;
141 if (dim < transformed_network_dim)
142 wrap_around[dim++] =
true;
144 if (dim < transformed_network_dim)
145 wrap_around[dim++] =
true;
147 if (dim < transformed_network_dim)
148 wrap_around[dim++] =
true;
150 if (dim < transformed_network_dim)
151 wrap_around[dim++] =
true;
153 if (dim < transformed_network_dim)
154 wrap_around[dim++] =
true;
156 if (dim < transformed_network_dim)
157 wrap_around[dim++] =
true;
164 if (dim < transformed_network_dim)
165 wrap_around[dim++] =
true;
167 if (dim < transformed_network_dim)
168 wrap_around[dim++] =
true;
170 if (dim < transformed_network_dim)
171 wrap_around[dim++] =
true;
173 if (dim < transformed_network_dim)
174 wrap_around[dim++] =
true;
176 if (dim < transformed_network_dim)
177 wrap_around[dim++] =
true;
179 if (dim < transformed_network_dim)
180 wrap_around[dim++] =
true;
193 const int rank_per_node = 1;
194 const int num_nodes = this->
numRanks / rank_per_node;
196 if (num_nodes <= 1) {
197 nxyz[0] = nxyz[1] = nxyz[2] = nxyz[3] = 1;
201 else if (num_nodes <= 2) {
202 nxyz[0] = nxyz[1] = nxyz[2] = nxyz[3] = 1;
206 else if (num_nodes <= 4) {
207 nxyz[0] = nxyz[1] = nxyz[2] = 1;
212 else if (num_nodes <= 8) {
213 nxyz[0] = nxyz[1] = 1;
219 else if (num_nodes <= 16) {
227 else if (num_nodes <= 32) {
235 else if (num_nodes <= 64) {
243 else if (num_nodes <= 128) {
251 else if (num_nodes <= 256) {
259 else if (num_nodes <= 512) {
267 else if (num_nodes <= 1024) {
275 else if (num_nodes <= 2048) {
283 else if (num_nodes <= 4096) {
292 std::cerr <<
"Too many ranks to test" << std::endl;
294 nxyz[5] = rank_per_node;
297 if (dim < transformed_network_dim)
298 extent[dim] = nxyz[dim];
300 if (dim < transformed_network_dim)
301 extent[dim] = nxyz[dim];
303 if (dim < transformed_network_dim)
304 extent[dim] = nxyz[dim];
306 if (dim < transformed_network_dim)
307 extent[dim] = nxyz[dim];
309 if (dim < transformed_network_dim)
310 extent[dim] = nxyz[dim];
312 if (dim < transformed_network_dim)
313 extent[dim] = nxyz[dim];
320 for (
int i = 0; i < this->transformed_network_dim; ++i) {
321 xyz[i] = transformed_coordinates[i][this->
myRank];
330 t = me % machine_extent[5];
332 me = me / machine_extent[5];
333 e = me % machine_extent[4];
335 me = me / machine_extent[4];
336 d = me % machine_extent[3];
338 me = me / machine_extent[3];
339 c = me % machine_extent[2];
341 me = me / machine_extent[2];
342 b = me % machine_extent[1];
344 me = me / machine_extent[1];
345 a = me % machine_extent[0];
347 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = d; xyz[4] = e; xyz[5] = t;
356 pcoord_t *xyz)
const {
364 allCoords = procCoords;
368 virtual bool getHopCount(
int rank1,
int rank2, pcoord_t &hops)
const override {
371 for (
int i = 0; i < networkDim - 1; ++i) {
372 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
374 distance = -distance;
375 if (machine_extent[i] - distance < distance)
376 distance = machine_extent[i] - distance;
394 pcoord_t **procCoords;
397 bool delete_transformed_coords;
398 int transformed_network_dim;
399 pcoord_t **transformed_coordinates;
400 const Teuchos::ParameterList *pl;
402 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
404 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
406 for (
int i = 0; i < networkDim; i++) {
407 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
409 procCoords[i], tmpVect);
410 pcoord_t *tmp = tmpVect;
411 tmpVect = procCoords[i];
bool getMachineExtent(part_t *extent) const
MachineTorusBGQTest(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
A TopoManager Machine Class (Torus Networks) for testing only A more realistic machine should be used...
int getMachineDim() const
bool getMyActualMachineCoordinate(pcoord_t *xyz)
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMachineExtentWrapArounds(bool *wrap_around) const
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
SparseMatrixAdapter_t::part_t part_t
bool getMachineExtentWrapArounds(part_t *wrap_around) const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
MachineTorusBGQTest(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
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 hasMachineCoordinates() const
bool getMyMachineCoordinate(pcoord_t *xyz)
virtual ~MachineTorusBGQTest()
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const