1 #ifndef _ZOLTAN2_MACHINE_TOPOMANAGERTEST_HPP_
2 #define _ZOLTAN2_MACHINE_TOPOMANAGERTEST_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
15 template <
typename pcoord_t,
typename part_t>
26 procCoords(NULL),machine_extent(NULL),
27 delete_transformed_coords(false), transformed_network_dim(0),transformed_coordinates (NULL), pl(NULL){
28 transformed_network_dim = networkDim - 1;
29 transformed_coordinates = procCoords;
31 machine_extent =
new int[networkDim];
33 machine_extent[5] = 1;
35 procCoords =
new pcoord_t *[networkDim];
36 for (
int i = 0; i < networkDim; ++i){
37 procCoords[i] =
new pcoord_t[this->
numRanks];
38 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
42 pcoord_t *xyz =
new pcoord_t[networkDim];
44 for (
int i = 0; i < networkDim; i++)
45 procCoords[i][this->
myRank] = xyz[i];
49 gatherMachineCoordinates(comm);
53 MachineBGQTest(
const Teuchos::Comm<int> &comm,
const Teuchos::ParameterList &pl_):
56 procCoords(NULL),machine_extent(NULL),
57 delete_transformed_coords(false), transformed_network_dim(0),transformed_coordinates (NULL),
60 transformed_network_dim = networkDim - 1;
61 transformed_coordinates = procCoords;
62 machine_extent =
new int[networkDim];
65 machine_extent[5] = 1;
67 procCoords =
new pcoord_t *[networkDim];
68 for (
int i = 0; i < networkDim; ++i){
69 procCoords[i] =
new pcoord_t[this->
numRanks];
70 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
74 pcoord_t *xyz =
new pcoord_t[networkDim];
76 for (
int i = 0; i < networkDim; i++)
77 procCoords[i][this->
myRank] = xyz[i];
81 gatherMachineCoordinates(comm);
83 const Teuchos::ParameterEntry *pe = this->pl->getEntryPtr(
"Machine_Optimization_Level");
87 int optimization_level = 0;
89 optimization_level = pe->getValue<
int>(&optimization_level);
91 if (optimization_level == 0){
92 transformed_network_dim = networkDim - 1;
93 transformed_coordinates = procCoords;
96 else if (optimization_level >= 1){
97 transformed_network_dim = networkDim - 2;
98 transformed_coordinates = procCoords;
105 for (
int i = 0; i < networkDim; i++){
106 delete [] procCoords[i];
108 delete [] procCoords;
110 delete [] machine_extent;
111 if (delete_transformed_coords){
112 for (
int i = 0; i < transformed_network_dim; i++){
113 delete [] transformed_coordinates[i];
115 delete [] transformed_coordinates;
125 if (dim < transformed_network_dim)
126 wrap_around[dim++] =
true;
127 if (dim < transformed_network_dim)
128 wrap_around[dim++] =
true;
129 if (dim < transformed_network_dim)
130 wrap_around[dim++] =
true;
131 if (dim < transformed_network_dim)
132 wrap_around[dim++] =
true;
133 if (dim < transformed_network_dim)
134 wrap_around[dim++] =
true;
135 if (dim < transformed_network_dim)
136 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;
159 if (dim < transformed_network_dim)
160 wrap_around[dim++] =
true;
173 const int rank_per_node = 1;
174 const int num_nodes = this->
numRanks / rank_per_node;
176 nxyz[0] = nxyz[1] = nxyz[2] = nxyz[3] = 1;
180 else if (num_nodes <= 2){
182 nxyz[0] = nxyz[1] = nxyz[2] = nxyz[3] = 1;
186 else if (num_nodes <= 4){
187 nxyz[0] = nxyz[1] = nxyz[2] = 1;
193 else if (num_nodes <= 8){
194 nxyz[0] = nxyz[1] = 1;
201 else if (num_nodes <= 16){
211 else if (num_nodes <= 32){
221 else if (num_nodes <= 64){
231 else if (num_nodes <= 128){
240 else if (num_nodes <= 256){
249 else if (num_nodes <= 512){
258 else if (num_nodes <= 1024){
267 else if (num_nodes <= 2048){
276 else if (num_nodes <= 4096){
287 std::cerr <<
"Too many ranks to test" << std::endl;
289 nxyz[5] = rank_per_node;
293 if (dim < transformed_network_dim)
294 extent[dim] = nxyz[dim];
296 if (dim < transformed_network_dim)
297 extent[dim] = nxyz[dim];
299 if (dim < transformed_network_dim)
300 extent[dim] = nxyz[dim];
302 if (dim < transformed_network_dim)
303 extent[dim] = nxyz[dim];
305 if (dim < transformed_network_dim)
306 extent[dim] = nxyz[dim];
308 if (dim < transformed_network_dim)
309 extent[dim] = nxyz[dim];
316 for (
int i = 0; i < this->transformed_network_dim; ++i){
317 xyz[i] = transformed_coordinates[i][this->
myRank];
326 t = me % machine_extent[5];
328 me = me / machine_extent[5];
329 e = me % machine_extent[4];
331 me = me / machine_extent[4];
332 d = me % machine_extent[3];
334 me = me / machine_extent[3];
335 c = me % machine_extent[2];
337 me = me / machine_extent[2];
338 b = me % machine_extent[1];
340 me = me / machine_extent[1];
341 a = me % machine_extent[0];
343 xyz[0] = a; xyz[1] = b; xyz[2] = c; xyz[3] = d; xyz[4] = e; xyz[5] = t;
351 pcoord_t *xyz)
const {
359 allCoords = procCoords;
366 for (
int i = 0; i < networkDim - 1; ++i){
367 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
368 if (distance < 0 ) distance = -distance;
369 if (machine_extent[i] - distance < distance) distance = machine_extent[i] - distance;
386 pcoord_t **procCoords;
392 bool delete_transformed_coords;
393 int transformed_network_dim;
394 pcoord_t **transformed_coordinates;
395 const Teuchos::ParameterList *pl;
397 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
399 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
401 for (
int i = 0; i < networkDim; i++) {
402 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
403 this->
numRanks, procCoords[i], tmpVect);
404 pcoord_t *tmp = tmpVect;
405 tmpVect = procCoords[i];
bool hasMachineCoordinates() const
virtual bool getHopCount(int rank1, int rank2, pcoord_t &hops)
bool getMyActualMachineCoordinate(pcoord_t *xyz)
MachineClass Base class for representing machine coordinates, networks, etc.
bool getMachineExtent(part_t *extent) const
MachineBGQTest(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
int getMachineDim() const
bool getMachineExtentWrapArounds(part_t *wrap_around) const
SparseMatrixAdapter_t::part_t part_t
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineExtentWrapArounds(bool *wrap_around) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
bool getMyMachineCoordinate(pcoord_t *xyz)
A Machine Class for testing only A more realistic machine should be used for task mapping...
virtual ~MachineBGQTest()
MachineBGQTest(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.