10 #ifndef _ZOLTAN2_MACHINE_TORUS_RCALIB_HPP_
11 #define _ZOLTAN2_MACHINE_TORUS_RCALIB_HPP_
13 #include <Teuchos_Comm.hpp>
14 #include <Teuchos_CommHelpers.hpp>
17 #ifdef HAVE_ZOLTAN2_RCALIB
29 template <
typename pcoord_t,
typename part_t>
42 actual_procCoords(NULL),
44 actual_machine_extent(NULL),
45 is_transformed(false),
48 actual_machine_extent = machine_extent =
new int[networkDim];
50 actual_machine_extent = machine_extent;
53 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
54 for (
int i = 0; i < networkDim; ++i) {
55 procCoords[i] =
new pcoord_t[this->
numRanks];
56 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
60 pcoord_t *xyz =
new pcoord_t[networkDim];
62 for (
int i = 0; i < networkDim; i++)
63 procCoords[i][this->
myRank] = xyz[i];
67 gatherMachineCoordinates(comm);
72 int transformed_network_dim = networkDim;
73 if (dim < transformed_network_dim)
74 wrap_around[dim++] =
true;
75 if (dim < transformed_network_dim)
76 wrap_around[dim++] =
true;
77 if (dim < transformed_network_dim)
78 wrap_around[dim++] =
true;
83 const Teuchos::ParameterList &pl_):
88 actual_procCoords(NULL),
90 actual_machine_extent(NULL),
91 is_transformed(false),
94 actual_machine_extent = machine_extent =
new int[networkDim];
96 actual_machine_extent = machine_extent;
99 actual_procCoords = procCoords =
new pcoord_t *[networkDim];
100 for (
int i = 0; i < networkDim; ++i) {
101 procCoords[i] =
new pcoord_t[this->
numRanks];
102 memset(procCoords[i], 0,
sizeof(pcoord_t) * this->
numRanks);
105 pcoord_t *xyz =
new pcoord_t[networkDim];
107 for (
int i = 0; i < networkDim; i++)
108 procCoords[i][this->
myRank] = xyz[i];
113 gatherMachineCoordinates(comm);
115 const Teuchos::ParameterEntry *pe2 =
116 this->pl->getEntryPtr(
"Machine_Optimization_Level");
120 int optimization_level;
121 optimization_level = pe2->getValue<
int>(&optimization_level);
123 if (optimization_level == 1) {
124 is_transformed =
true;
125 this->networkDim = 3;
126 procCoords =
new pcoord_t * [networkDim];
127 for(
int i = 0; i < networkDim; ++i) {
128 procCoords[i] =
new pcoord_t[this->
numRanks] ;
131 for (
int i = 0; i < this->
numRanks; ++i) {
132 procCoords[0][i] = this->actual_procCoords[0][i] * 8;
133 int yordinal = this->actual_procCoords[1][i];
134 procCoords[1][i] = yordinal/2 * (16 + 8) + (yordinal %2) * 8;
135 int zordinal = this->actual_procCoords[2][i];
136 procCoords[2][i] = zordinal * 5 + (zordinal / 8) * 3;
138 int mx = this->machine_extent[0];
139 int my = this->machine_extent[1];
140 int mz = this->machine_extent[2];
143 this->machine_extent =
new int[networkDim];
144 this->machine_extent[0] = mx * 8;
145 this->machine_extent[1] = my/2 * (16 + 8) + (my %2) * 8;
146 this->machine_extent[2] = mz * 5 + (mz / 8) * 3;
148 std::cout <<
"Transforming the coordinates" << std::endl;
151 else if(optimization_level >= 3) {
152 is_transformed =
true;
153 this->networkDim = 6;
154 procCoords =
new pcoord_t * [networkDim];
155 for(
int i = 0; i < networkDim; ++i) {
156 procCoords[i] =
new pcoord_t[this->
numRanks] ;
161 this->machine_extent =
new int[networkDim];
163 this->machine_extent[0] =
164 ceil (
int (this->actual_machine_extent[0]) / 2.0) * 64 ;
165 this->machine_extent[3] = 2 * 8 ;
166 this->machine_extent[1] =
167 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
168 this->machine_extent[4] = 2 * 8;
169 this->machine_extent[2] =
170 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
171 this->machine_extent[5] = 8 * 5;
173 for (
int k = 0; k < this->
numRanks ; k++) {
185 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 2) * 64;
188 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 2) * 8 ;
195 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
197 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
208 ((int (this->actual_procCoords[2][k])) / 8) * 160;
211 ((int (this->actual_procCoords[2][k])) % 8) * 5;
214 else if(optimization_level == 2) {
216 is_transformed =
true;
217 this->networkDim = 6;
218 procCoords =
new pcoord_t * [networkDim];
219 for(
int i = 0; i < networkDim; ++i) {
220 procCoords[i] =
new pcoord_t[this->
numRanks] ;
225 this->machine_extent =
new int[networkDim];
227 this->machine_extent[0] =
228 ceil(
int (this->actual_machine_extent[0]) / 3.0) * 128 ;
229 this->machine_extent[3] = 3 * 8 ;
230 this->machine_extent[1] =
231 ceil(
int (this->actual_machine_extent[1]) / 2.0) * 8 * 2400;
232 this->machine_extent[4] = 2 * 8;
233 this->machine_extent[2] =
234 ceil((
int (this->actual_machine_extent[2])) / 8.0) * 160;
235 this->machine_extent[5] = 8 * 5;
238 for (
int k = 0; k < this->
numRanks ; k++) {
249 procCoords[0][k] = (int (this->actual_procCoords[0][k]) / 3) * 128;
252 procCoords[3][k] = (int (this->actual_procCoords[0][k]) % 3) * 8 ;
259 (int (this->actual_procCoords[1][k]) / 2) * 8 * 2400;
261 procCoords[4][k] = (int (this->actual_procCoords[1][k]) % 2) * 8;
265 ((int (this->actual_procCoords[2][k])) / 8) * 160;
267 procCoords[5][k] = ((int (this->actual_procCoords[2][k])) % 8) * 5;
277 if (is_transformed) {
278 is_transformed =
false;
279 for (
int i = 0; i < actual_networkDim; i++) {
280 delete [] actual_procCoords[i];
282 delete [] actual_procCoords;
283 delete [] actual_machine_extent;
285 for (
int i = 0; i < networkDim; i++) {
286 delete [] procCoords[i];
288 delete [] procCoords;
289 delete [] machine_extent;
298 if (is_transformed) {
303 nxyz[dim++] = this->machine_extent[0];
304 nxyz[dim++] = this->machine_extent[1];
305 nxyz[dim++] = this->machine_extent[2];
311 #if defined (HAVE_ZOLTAN2_RCALIB)
313 rca_get_max_dimension(&mxyz);
315 nxyz[dim++] = mxyz.mesh_x + 1;
316 nxyz[dim++] = mxyz.mesh_y + 1;
317 nxyz[dim++] = mxyz.mesh_z + 1;
327 for (
int i = 0; i < this->
numRanks; ++i) {
328 std::cout <<
"Rank:" << i
329 <<
" " << procCoords[0][i]
330 <<
" " << procCoords[1][i]
331 <<
" " << procCoords[2][i] << std::endl;
333 std::cout <<
"Machine Extent:"
334 <<
" " << this->machine_extent[0]
335 <<
" " << this->machine_extent[1]
336 <<
" " << this->machine_extent[2] << std::endl;
341 for (
int i = 0; i < this->networkDim; ++i) {
342 xyz[i] = procCoords[i][this->
myRank];
348 #if defined (HAVE_ZOLTAN2_RCALIB)
350 rca_get_nodeid(&nodeInfo);
351 int NIDs = (int)nodeInfo.rs_node_s._node_id;
353 mesh_coord_t node_coord;
354 int returnval = rca_get_meshcoord((uint16_t)NIDs, &node_coord);
355 if (returnval == -1) {
358 xyz[0] = node_coord.mesh_x;
359 xyz[1] = node_coord.mesh_y;
360 xyz[2] = node_coord.mesh_z;
368 pcoord_t *xyz)
const {
369 for (
int i = 0; i < this->networkDim; ++i) {
370 xyz[i] = procCoords[i][rank];
381 allCoords = procCoords;
385 virtual bool getHopCount(
int rank1,
int rank2, pcoord_t &hops)
const override {
387 for (
int i = 0; i < networkDim; ++i) {
388 pcoord_t distance = procCoords[i][rank1] - procCoords[i][rank2];
390 distance = -distance;
391 if (machine_extent[i] - distance < distance)
392 distance = machine_extent[i] - distance;
402 int actual_networkDim;
404 pcoord_t **procCoords;
405 pcoord_t **actual_procCoords;
408 part_t *actual_machine_extent;
412 const Teuchos::ParameterList *pl;
420 void gatherMachineCoordinates(
const Teuchos::Comm<int> &comm) {
422 pcoord_t *tmpVect =
new pcoord_t [this->
numRanks];
424 for (
int i = 0; i < networkDim; i++) {
425 Teuchos::reduceAll<int, pcoord_t>(comm, Teuchos::REDUCE_SUM,
427 procCoords[i], tmpVect);
428 pcoord_t *tmp = tmpVect;
429 tmpVect = procCoords[i];
int getRealMachineDim() const
bool getRealMachineExtent(int *nxyz) const
MachineTorusRCA(const Teuchos::Comm< int > &comm, const Teuchos::ParameterList &pl_)
MachineClass Base class for representing machine coordinates, networks, etc.
bool getAllMachineCoordinatesView(pcoord_t **&allCoords) const
bool getMachineCoordinate(const int rank, pcoord_t *xyz) const
MachineTorusRCA(const Teuchos::Comm< int > &comm)
Constructor: A BlueGeneQ network machine description;.
bool getMachineExtent(int *nxyz) const
SparseMatrixAdapter_t::part_t part_t
bool getMyMachineCoordinate(pcoord_t *xyz)
virtual bool getMachineExtentWrapArounds(bool *wrap_around) const
bool getMachineCoordinate(const char *nodename, pcoord_t *xyz)
int getMachineDim() const
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 ~MachineTorusRCA()
An RCA Machine class on Torus Networks.
bool hasMachineCoordinates() const
bool getMyActualMachineCoordinate(pcoord_t *xyz)