10 #ifndef _ZOLTAN2_MACHINE_DRAGONFLY_RCALIB_HPP_
11 #define _ZOLTAN2_MACHINE_DRAGONFLY_RCALIB_HPP_
13 #include <Teuchos_Comm.hpp>
14 #include <Teuchos_CommHelpers.hpp>
17 #ifdef HAVE_ZOLTAN2_RCALIB
81 template <
typename pcoord_t,
typename part_t>
95 transformed_networkDim(3),
97 transformed_procCoords(NULL),
98 actual_procCoords(NULL),
99 transformed_machine_extent(NULL),
100 actual_machine_extent(NULL),
101 num_unique_groups(0),
103 is_transformed(false),
106 actual_machine_extent =
new int[actual_networkDim];
111 group_count =
new part_t[actual_machine_extent[0]];
113 memset(group_count, 0,
sizeof(
part_t) * actual_machine_extent[0]);
116 transformed_networkDim = 1 + actual_machine_extent[1] +
117 actual_machine_extent[2];
118 transformed_machine_extent =
new int[transformed_networkDim];
121 actual_procCoords =
new pcoord_t *[actual_networkDim];
122 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
124 for (
int i = 0; i < actual_networkDim; ++i) {
125 actual_procCoords[i] =
new pcoord_t[this->
numRanks];
126 memset(actual_procCoords[i], 0,
130 pcoord_t *xyz =
new pcoord_t[transformed_networkDim];
132 for (
int i = 0; i < actual_networkDim; ++i)
133 actual_procCoords[i][this->
myRank] = xyz[i];
138 part_t * tmp_vec =
new part_t[actual_machine_extent[0]];
139 memset(tmp_vec, 0,
sizeof(
part_t) * actual_machine_extent[0]);
141 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_SUM,
142 actual_machine_extent[0],
147 num_unique_groups = 0;
149 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
150 if (tmp_vec[i] > 0) {
156 delete[] group_count;
157 group_count =
new part_t[num_unique_groups];
160 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
161 if (tmp_vec[i] > 0) {
162 group_count[pos] = tmp_vec[i];
170 gatherMachineCoordinates(this->actual_procCoords,
171 this->actual_networkDim, comm);
191 const Teuchos::ParameterList &pl_ ):
193 transformed_networkDim(3),
194 actual_networkDim(3),
195 transformed_procCoords(NULL),
196 actual_procCoords(NULL),
197 transformed_machine_extent(NULL),
198 actual_machine_extent(NULL),
199 num_unique_groups(0),
201 is_transformed(false),
204 actual_machine_extent =
new int[actual_networkDim];
208 group_count =
new part_t[actual_machine_extent[0]];
210 memset(group_count, 0,
sizeof(
part_t) * actual_machine_extent[0]);
213 actual_procCoords =
new pcoord_t *[actual_networkDim];
214 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
216 pcoord_t *xyz =
new pcoord_t[actual_networkDim];
221 part_t * tmp_vec =
new part_t[actual_machine_extent[0]];
222 memset(tmp_vec, 0,
sizeof(
part_t) * actual_machine_extent[0]);
224 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_SUM,
225 actual_machine_extent[0],
230 num_unique_groups = 0;
232 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
233 if (tmp_vec[i] > 0) {
239 delete[] group_count;
240 group_count =
new part_t[num_unique_groups];
243 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
244 if (tmp_vec[i] > 0) {
245 group_count[pos] = tmp_vec[i];
251 const Teuchos::ParameterEntry *pe2 =
252 this->pl->getEntryPtr(
"Machine_Optimization_Level");
256 int optimization_level;
257 optimization_level = pe2->getValue<
int>(&optimization_level);
259 if (optimization_level > 0) {
260 is_transformed =
true;
263 transformed_networkDim = 1 + actual_machine_extent[1] +
264 actual_machine_extent[2];
265 transformed_machine_extent =
new int[transformed_networkDim];
267 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
270 for (
int i = 0; i < transformed_networkDim; ++i) {
271 transformed_procCoords[i] =
new pcoord_t[this->
numRanks];
272 memset(transformed_procCoords[i], 0,
277 int nx = this->actual_machine_extent[0];
278 int ny = this->actual_machine_extent[1];
279 int nz = this->actual_machine_extent[2];
281 const Teuchos::ParameterEntry *pe_x =
282 this->pl->getEntryPtr(
"Machine_X_Stretch");
283 const Teuchos::ParameterEntry *pe_y =
284 this->pl->getEntryPtr(
"Machine_Y_Stretch");
285 const Teuchos::ParameterEntry *pe_z =
286 this->pl->getEntryPtr(
"Machine_Z_Stretch");
294 x_stretch = pe_x->getValue<
int>(&x_stretch);
296 y_stretch = pe_y->getValue<
int>(&y_stretch);
298 z_stretch = pe_z->getValue<
int>(&z_stretch);
301 transformed_procCoords[0][this->
myRank] =
302 x_stretch * xyz[0] * ny * nz;
305 for (
int i = 1; i < 1 + ny; ++i) {
307 transformed_procCoords[i][this->
myRank] = 0;
310 transformed_procCoords[i][this->
myRank] = y_stretch;
313 for (
int i = 1 + ny; i < transformed_networkDim; ++i) {
315 transformed_procCoords[i][this->
myRank] = 0;
317 if (xyz[2] == i - (1 + ny))
318 transformed_procCoords[i][this->
myRank] = z_stretch;
321 this->transformed_machine_extent =
new int[transformed_networkDim];
324 this->transformed_machine_extent[0] = x_stretch * (nx - 1) * ny * nz;
325 for (
int i = 1; i < 1 + ny; ++i) {
326 this->transformed_machine_extent[i] = y_stretch;
328 for (
int i = 1 + ny; i < transformed_networkDim; ++i) {
329 this->transformed_machine_extent[i] = z_stretch;
333 gatherMachineCoordinates(this->transformed_procCoords,
334 this->transformed_networkDim, comm);
340 if (!is_transformed) {
342 for (
int i = 0; i < actual_networkDim; ++i) {
343 actual_procCoords[i] =
new pcoord_t[this->
numRanks];
344 memset(actual_procCoords[i], 0,
348 for (
int i = 0; i < actual_networkDim; ++i)
349 actual_procCoords[i][this->
myRank] = xyz[i];
352 gatherMachineCoordinates(this->actual_procCoords,
353 this->actual_networkDim, comm);
362 if (is_transformed) {
363 is_transformed =
false;
365 for (
int i = 0; i < transformed_networkDim; ++i) {
366 delete [] transformed_procCoords[i];
369 delete [] transformed_machine_extent;
373 for (
int i = 0; i < actual_networkDim; ++i) {
374 delete [] actual_procCoords[i];
379 delete [] actual_procCoords;
380 delete [] transformed_procCoords;
382 delete [] actual_machine_extent;
383 delete [] group_count;
391 return this->transformed_networkDim;
393 return this->actual_networkDim;
398 if (is_transformed) {
399 for (
int dim = 0; dim < transformed_networkDim; ++dim)
400 nxyz[dim] = this->transformed_machine_extent[dim];
410 #if defined (HAVE_ZOLTAN2_RCALIB)
412 rca_get_max_dimension(&mxyz);
415 nxyz[dim++] = mxyz.mesh_x + 1;
416 nxyz[dim++] = mxyz.mesh_y + 1;
417 nxyz[dim++] = mxyz.mesh_z + 1;
436 return this->num_unique_groups;
442 if (group_count != NULL) {
443 for (
int i = 0; i < num_unique_groups; ++i) {
444 grp_count[i] = this->group_count[i];
457 if (is_transformed) {
458 for (
int i = 0; i < this->
numRanks; ++i) {
459 std::cout <<
"Rank:" << i;
460 for (
int j = 0; j < this->transformed_networkDim; ++j) {
461 std::cout <<
" " << transformed_procCoords[j][i];
463 std::cout << std::endl;
466 std::cout << std::endl <<
"Transformed Machine Extent: ";
467 for (
int i = 0; i < this->transformed_networkDim; ++i) {
468 std::cout <<
" " << this->transformed_machine_extent[i];
470 std::cout << std::endl;
474 for (
int i = 0; i < this->
numRanks; ++i) {
475 std::cout <<
"Rank:" << i;
476 for (
int j = 0; j < this->actual_networkDim; ++j) {
477 std::cout <<
" " << actual_procCoords[j][i];
479 std::cout << std::endl;
482 std::cout << std::endl <<
"Actual Machine Extent: ";
483 for (
int i = 0; i < this->actual_networkDim; ++i) {
484 std::cout <<
" " << this->actual_machine_extent[i];
486 std::cout << std::endl;
493 if (is_transformed) {
494 for (
int i = 0; i < this->transformed_networkDim; ++i) {
495 xyz[i] = transformed_procCoords[i][this->
myRank];
506 #if defined (HAVE_ZOLTAN2_RCALIB)
509 rca_get_nodeid(&nodeInfo);
512 int NIDs = (int)nodeInfo.rs_node_s._node_id;
514 mesh_coord_t node_coord;
515 int returnval = rca_get_meshcoord((uint16_t)NIDs, &node_coord);
516 if (returnval == -1) {
520 int x = node_coord.mesh_x;
521 int y = node_coord.mesh_y;
522 int z = node_coord.mesh_z;
548 pcoord_t *xyz)
const {
549 if (is_transformed) {
550 for (
int i = 0; i < this->transformed_networkDim; ++i) {
551 xyz[i] = transformed_procCoords[i][rank];
555 for (
int i = 0; i < this->actual_networkDim; ++i) {
556 xyz[i] = actual_procCoords[i][rank];
569 if (is_transformed) {
570 allCoords = transformed_procCoords;
573 allCoords = actual_procCoords;
581 virtual bool getHopCount(
int rank1,
int rank2, pcoord_t &hops)
const override {
584 if (is_transformed) {
588 if (this->transformed_procCoords[0][rank1] !=
589 this->transformed_procCoords[0][rank2])
598 for (
int i = 1; i < this->transformed_networkDim; ++i) {
599 if (this->transformed_procCoords[i][rank1] !=
600 this->transformed_procCoords[i][rank2])
609 if (this->actual_procCoords[0][rank1] !=
610 this->actual_procCoords[0][rank2])
619 for (
int i = 1; i < actual_networkDim; ++i) {
620 if (this->actual_procCoords[i][rank1] !=
621 this->actual_procCoords[i][rank2])
632 int transformed_networkDim;
633 int actual_networkDim;
636 pcoord_t **transformed_procCoords;
637 pcoord_t **actual_procCoords;
640 part_t *transformed_machine_extent;
641 part_t *actual_machine_extent;
651 const Teuchos::ParameterList *pl;
654 void gatherMachineCoordinates(pcoord_t **&coords,
int netDim,
655 const Teuchos::Comm<int> &comm) {
657 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
659 for (
int i = 0; i < netDim; ++i) {
660 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
663 pcoord_t *tmp = tmpVect;
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 ...
virtual bool getMachineExtentWrapArounds(bool *wrap_around) const
bool getTransformedMachineExtent(int *nxyz) const
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
virtual ~MachineDragonflyRCA()
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
MachineClass Base class for representing machine coordinates, networks, etc.
bool getGroupCount(part_t *grp_count) const override
part_t getNumUniqueGroups() const override
getNumUniqueGroups function return the number of unique Dragonfly network groups in provided allocati...
SparseMatrixAdapter_t::part_t part_t
bool getMyActualMachineCoordinate(pcoord_t *xyz)
bool getMyMachineCoordinate(pcoord_t *xyz)
bool getActualMachineExtent(int *nxyz) const
bool getMyTransformedMachineCoordinate(pcoord_t *xyz)
MachineDragonflyRCA(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
Constructor: Dragonfly (e.g. Cori & Trinity) network machine description;.
int getMachineDim() const
MachineDragonflyRCA(const Teuchos::Comm< int > &comm)
Constructor: Dragonfly (e.g. Cori & Trinity) network machine description;.
bool getMachineExtent(int *nxyz) const
bool hasMachineCoordinates() const
A Dragonfly (e.g. Cori, Trinity, & Theta) Machine Class for task mapping.