1 #ifndef _ZOLTAN2_MACHINE_DRAGONFLY_RCALIB_HPP_
2 #define _ZOLTAN2_MACHINE_DRAGONFLY_RCALIB_HPP_
4 #include <Teuchos_Comm.hpp>
5 #include <Teuchos_CommHelpers.hpp>
8 #ifdef HAVE_ZOLTAN2_RCALIB
72 template <
typename pcoord_t,
typename part_t>
86 transformed_networkDim(3),
88 transformed_procCoords(NULL),
89 actual_procCoords(NULL),
90 transformed_machine_extent(NULL),
91 actual_machine_extent(NULL),
94 is_transformed(false),
97 actual_machine_extent =
new int[actual_networkDim];
102 group_count =
new part_t[actual_machine_extent[0]];
104 memset(group_count, 0,
sizeof(
part_t) * actual_machine_extent[0]);
107 transformed_networkDim = 1 + actual_machine_extent[1] +
108 actual_machine_extent[2];
109 transformed_machine_extent =
new int[transformed_networkDim];
112 actual_procCoords =
new pcoord_t *[actual_networkDim];
113 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
115 for (
int i = 0; i < actual_networkDim; ++i) {
116 actual_procCoords[i] =
new pcoord_t[this->
numRanks];
117 memset(actual_procCoords[i], 0,
121 pcoord_t *xyz =
new pcoord_t[transformed_networkDim];
123 for (
int i = 0; i < actual_networkDim; ++i)
124 actual_procCoords[i][this->
myRank] = xyz[i];
129 part_t * tmp_vec =
new part_t[actual_machine_extent[0]];
130 memset(tmp_vec, 0,
sizeof(
part_t) * actual_machine_extent[0]);
132 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_SUM,
133 actual_machine_extent[0],
138 num_unique_groups = 0;
140 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
141 if (tmp_vec[i] > 0) {
147 delete[] group_count;
148 group_count =
new part_t[num_unique_groups];
151 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
152 if (tmp_vec[i] > 0) {
153 group_count[pos] = tmp_vec[i];
161 gatherMachineCoordinates(this->actual_procCoords,
162 this->actual_networkDim, comm);
182 const Teuchos::ParameterList &pl_ ):
184 transformed_networkDim(3),
185 actual_networkDim(3),
186 transformed_procCoords(NULL),
187 actual_procCoords(NULL),
188 transformed_machine_extent(NULL),
189 actual_machine_extent(NULL),
190 num_unique_groups(0),
192 is_transformed(false),
195 actual_machine_extent =
new int[actual_networkDim];
199 group_count =
new part_t[actual_machine_extent[0]];
201 memset(group_count, 0,
sizeof(
part_t) * actual_machine_extent[0]);
204 actual_procCoords =
new pcoord_t *[actual_networkDim];
205 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
207 pcoord_t *xyz =
new pcoord_t[actual_networkDim];
212 part_t * tmp_vec =
new part_t[actual_machine_extent[0]];
213 memset(tmp_vec, 0,
sizeof(
part_t) * actual_machine_extent[0]);
215 Teuchos::reduceAll<int, part_t>(comm, Teuchos::REDUCE_SUM,
216 actual_machine_extent[0],
221 num_unique_groups = 0;
223 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
224 if (tmp_vec[i] > 0) {
230 delete[] group_count;
231 group_count =
new part_t[num_unique_groups];
234 for (
int i = 0; i < actual_machine_extent[0]; ++i) {
235 if (tmp_vec[i] > 0) {
236 group_count[pos] = tmp_vec[i];
242 const Teuchos::ParameterEntry *pe2 =
243 this->pl->getEntryPtr(
"Machine_Optimization_Level");
247 int optimization_level;
248 optimization_level = pe2->getValue<
int>(&optimization_level);
250 if (optimization_level > 0) {
251 is_transformed =
true;
254 transformed_networkDim = 1 + actual_machine_extent[1] +
255 actual_machine_extent[2];
256 transformed_machine_extent =
new int[transformed_networkDim];
258 transformed_procCoords =
new pcoord_t *[transformed_networkDim];
261 for (
int i = 0; i < transformed_networkDim; ++i) {
262 transformed_procCoords[i] =
new pcoord_t[this->
numRanks];
263 memset(transformed_procCoords[i], 0,
268 int nx = this->actual_machine_extent[0];
269 int ny = this->actual_machine_extent[1];
270 int nz = this->actual_machine_extent[2];
272 const Teuchos::ParameterEntry *pe_x =
273 this->pl->getEntryPtr(
"Machine_X_Stretch");
274 const Teuchos::ParameterEntry *pe_y =
275 this->pl->getEntryPtr(
"Machine_Y_Stretch");
276 const Teuchos::ParameterEntry *pe_z =
277 this->pl->getEntryPtr(
"Machine_Z_Stretch");
285 x_stretch = pe_x->getValue<
int>(&x_stretch);
287 y_stretch = pe_y->getValue<
int>(&y_stretch);
289 z_stretch = pe_z->getValue<
int>(&z_stretch);
292 transformed_procCoords[0][this->
myRank] =
293 x_stretch * xyz[0] * ny * nz;
296 for (
int i = 1; i < 1 + ny; ++i) {
298 transformed_procCoords[i][this->
myRank] = 0;
301 transformed_procCoords[i][this->
myRank] = y_stretch;
304 for (
int i = 1 + ny; i < transformed_networkDim; ++i) {
306 transformed_procCoords[i][this->
myRank] = 0;
308 if (xyz[2] == i - (1 + ny))
309 transformed_procCoords[i][this->
myRank] = z_stretch;
312 this->transformed_machine_extent =
new int[transformed_networkDim];
315 this->transformed_machine_extent[0] = x_stretch * (nx - 1) * ny * nz;
316 for (
int i = 1; i < 1 + ny; ++i) {
317 this->transformed_machine_extent[i] = y_stretch;
319 for (
int i = 1 + ny; i < transformed_networkDim; ++i) {
320 this->transformed_machine_extent[i] = z_stretch;
324 gatherMachineCoordinates(this->transformed_procCoords,
325 this->transformed_networkDim, comm);
331 if (!is_transformed) {
333 for (
int i = 0; i < actual_networkDim; ++i) {
334 actual_procCoords[i] =
new pcoord_t[this->
numRanks];
335 memset(actual_procCoords[i], 0,
339 for (
int i = 0; i < actual_networkDim; ++i)
340 actual_procCoords[i][this->
myRank] = xyz[i];
343 gatherMachineCoordinates(this->actual_procCoords,
344 this->actual_networkDim, comm);
353 if (is_transformed) {
354 is_transformed =
false;
356 for (
int i = 0; i < transformed_networkDim; ++i) {
357 delete [] transformed_procCoords[i];
360 delete [] transformed_machine_extent;
364 for (
int i = 0; i < actual_networkDim; ++i) {
365 delete [] actual_procCoords[i];
370 delete [] actual_procCoords;
371 delete [] transformed_procCoords;
373 delete [] actual_machine_extent;
374 delete [] group_count;
382 return this->transformed_networkDim;
384 return this->actual_networkDim;
389 if (is_transformed) {
390 for (
int dim = 0; dim < transformed_networkDim; ++dim)
391 nxyz[dim] = this->transformed_machine_extent[dim];
401 #if defined (HAVE_ZOLTAN2_RCALIB)
403 rca_get_max_dimension(&mxyz);
406 nxyz[dim++] = mxyz.mesh_x + 1;
407 nxyz[dim++] = mxyz.mesh_y + 1;
408 nxyz[dim++] = mxyz.mesh_z + 1;
427 return this->num_unique_groups;
433 if (group_count != NULL) {
434 for (
int i = 0; i < num_unique_groups; ++i) {
435 grp_count[i] = this->group_count[i];
448 if (is_transformed) {
449 for (
int i = 0; i < this->
numRanks; ++i) {
450 std::cout <<
"Rank:" << i;
451 for (
int j = 0; j < this->transformed_networkDim; ++j) {
452 std::cout <<
" " << transformed_procCoords[j][i];
454 std::cout << std::endl;
457 std::cout << std::endl <<
"Transformed Machine Extent: ";
458 for (
int i = 0; i < this->transformed_networkDim; ++i) {
459 std::cout <<
" " << this->transformed_machine_extent[i];
461 std::cout << std::endl;
465 for (
int i = 0; i < this->
numRanks; ++i) {
466 std::cout <<
"Rank:" << i;
467 for (
int j = 0; j < this->actual_networkDim; ++j) {
468 std::cout <<
" " << actual_procCoords[j][i];
470 std::cout << std::endl;
473 std::cout << std::endl <<
"Actual Machine Extent: ";
474 for (
int i = 0; i < this->actual_networkDim; ++i) {
475 std::cout <<
" " << this->actual_machine_extent[i];
477 std::cout << std::endl;
484 if (is_transformed) {
485 for (
int i = 0; i < this->transformed_networkDim; ++i) {
486 xyz[i] = transformed_procCoords[i][this->
myRank];
497 #if defined (HAVE_ZOLTAN2_RCALIB)
500 rca_get_nodeid(&nodeInfo);
503 int NIDs = (int)nodeInfo.rs_node_s._node_id;
505 mesh_coord_t node_coord;
506 int returnval = rca_get_meshcoord((uint16_t)NIDs, &node_coord);
507 if (returnval == -1) {
511 int x = node_coord.mesh_x;
512 int y = node_coord.mesh_y;
513 int z = node_coord.mesh_z;
539 pcoord_t *xyz)
const {
540 if (is_transformed) {
541 for (
int i = 0; i < this->transformed_networkDim; ++i) {
542 xyz[i] = transformed_procCoords[i][rank];
546 for (
int i = 0; i < this->actual_networkDim; ++i) {
547 xyz[i] = actual_procCoords[i][rank];
560 if (is_transformed) {
561 allCoords = transformed_procCoords;
564 allCoords = actual_procCoords;
575 if (is_transformed) {
579 if (this->transformed_procCoords[0][rank1] !=
580 this->transformed_procCoords[0][rank2])
589 for (
int i = 1; i < this->transformed_networkDim; ++i) {
590 if (this->transformed_procCoords[i][rank1] !=
591 this->transformed_procCoords[i][rank2])
600 if (this->actual_procCoords[0][rank1] !=
601 this->actual_procCoords[0][rank2])
610 for (
int i = 1; i < actual_networkDim; ++i) {
611 if (this->actual_procCoords[i][rank1] !=
612 this->actual_procCoords[i][rank2])
623 int transformed_networkDim;
624 int actual_networkDim;
627 pcoord_t **transformed_procCoords;
628 pcoord_t **actual_procCoords;
631 part_t *transformed_machine_extent;
632 part_t *actual_machine_extent;
642 const Teuchos::ParameterList *pl;
645 void gatherMachineCoordinates(pcoord_t **&coords,
int netDim,
646 const Teuchos::Comm<int> &comm) {
648 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
650 for (
int i = 0; i < netDim; ++i) {
651 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
654 pcoord_t *tmp = tmpVect;
virtual bool getMachineExtentWrapArounds(bool *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 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.